diff options
author | Johann Latocha | 2012-02-22 01:25:57 +0100 |
---|---|---|
committer | Johann Latocha | 2012-02-22 01:25:57 +0100 |
commit | b7098dd3b66269b82a2253cbd19555693cbfd3b9 (patch) | |
tree | 624b20111d7ac632acead73a1e968ab954d8ae85 /src/server/server.c | |
parent | [ALL] Send proper rid (diff) | |
download | dnbd3-b7098dd3b66269b82a2253cbd19555693cbfd3b9.tar.gz dnbd3-b7098dd3b66269b82a2253cbd19555693cbfd3b9.tar.xz dnbd3-b7098dd3b66269b82a2253cbd19555693cbfd3b9.zip |
[SERVER] Segfault on conf reload (hopefully!) fixed
Diffstat (limited to 'src/server/server.c')
-rw-r--r-- | src/server/server.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/server/server.c b/src/server/server.c index dba7cdd..48dd545 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -35,6 +35,7 @@ #include "ipc.h" int _sock; +pthread_spinlock_t _spinlock; GSList *_dnbd3_clients = NULL; char *_config_file_name = DEFAULT_SERVER_CONFIG_FILE; @@ -64,6 +65,8 @@ void dnbd3_print_version() void dnbd3_cleanup() { printf("INFO: Cleanup...\n"); + + pthread_spin_lock(&_spinlock); GSList *iterator = NULL; for (iterator = _dnbd3_clients; iterator; iterator = iterator->next) { @@ -71,8 +74,8 @@ void dnbd3_cleanup() shutdown(client->sock, SHUT_RDWR); pthread_join(*client->thread, NULL); } - g_slist_free(_dnbd3_clients); + pthread_spin_unlock(&_spinlock); close(_sock); free(_images); @@ -158,6 +161,8 @@ int main(int argc, char* argv[]) pthread_t thread_ipc; pthread_create(&(thread_ipc), NULL, dnbd3_ipc_receive, NULL); + pthread_spin_init(&_spinlock, PTHREAD_PROCESS_PRIVATE); + printf("INFO: Server is ready...\n"); // main loop @@ -182,7 +187,9 @@ int main(int argc, char* argv[]) dnbd3_client->thread = &thread; dnbd3_client->image = NULL; + pthread_spin_lock(&_spinlock); _dnbd3_clients = g_slist_append(_dnbd3_clients, dnbd3_client); + pthread_spin_unlock(&_spinlock); pthread_create(&(thread), NULL, dnbd3_handle_query, (void *) (uintptr_t) dnbd3_client); pthread_detach(thread); |