diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-11 03:57:21 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-11 03:57:21 +0200 |
commit | e64b8f2fedba36d5ba64cd5f77c4fb166f9ea3c6 (patch) | |
tree | 2549d7f18077d293b7b0311f749e73a21715d46b /src/mds-server | |
parent | whitespace (diff) | |
download | mds-e64b8f2fedba36d5ba64cd5f77c4fb166f9ea3c6.tar.gz mds-e64b8f2fedba36d5ba64cd5f77c4fb166f9ea3c6.tar.bz2 mds-e64b8f2fedba36d5ba64cd5f77c4fb166f9ea3c6.tar.xz |
move mutex_created into client_t + error handling for pthread_*_init
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server')
-rw-r--r-- | src/mds-server/client.c | 1 | ||||
-rw-r--r-- | src/mds-server/client.h | 5 | ||||
-rw-r--r-- | src/mds-server/mds-server.c | 31 |
3 files changed, 30 insertions, 7 deletions
diff --git a/src/mds-server/client.c b/src/mds-server/client.c index f48a1b0..08205b2 100644 --- a/src/mds-server/client.c +++ b/src/mds-server/client.c @@ -84,6 +84,7 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) size_t i, n, rc = sizeof(ssize_t) + 2 * sizeof(int) + sizeof(uint64_t) + 3 * sizeof(size_t); this->interception_conditions = NULL; this->send_pending = NULL; + this->mutex_created = 0; buf_get_next(data, ssize_t, this->list_entry); buf_get_next(data, int, this->socket_fd); buf_get_next(data, int, this->open); diff --git a/src/mds-server/client.h b/src/mds-server/client.h index a795c84..fee5eba 100644 --- a/src/mds-server/client.h +++ b/src/mds-server/client.h @@ -71,6 +71,11 @@ typedef struct client pthread_mutex_t mutex; /** + * Whether `mutex` has been initialised + */ + int mutex_created; + + /** * The messages interception conditions conditions * for the client */ diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index 17128e1..24ec7ac 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -256,8 +256,21 @@ int main(int argc_, char** argv_) /* Create mutex and condition for slave counter. */ - pthread_mutex_init(&slave_mutex, NULL); - pthread_cond_init(&slave_cond, NULL); + if ((errno = pthread_mutex_init(&slave_mutex, NULL)) != 0) + { + perror(*argv); + fd_table_destroy(&client_map, NULL, NULL); + linked_list_destroy(&client_list); + return 1; + } + if ((errno = pthread_cond_init(&slave_cond, NULL)) != 0) + { + perror(*argv); + fd_table_destroy(&client_map, NULL, NULL); + linked_list_destroy(&client_list); + pthread_mutex_destroy(&slave_mutex); + return 1; + } /* Unmarshal the state of the server. */ @@ -402,7 +415,6 @@ void* slave_loop(void* data) ssize_t entry = LINKED_LIST_UNUSED; size_t information_address = fd_table_get(&client_map, (size_t)socket_fd); client_t* information = (client_t*)(void*)information_address; - int mutex_created = 0; char* msgbuf = NULL; size_t n; size_t tmp; @@ -418,9 +430,10 @@ void* slave_loop(void* data) goto fail; } - /* NULL-out pointers. */ + /* NULL-out pointers and initialisation markers. */ information->interception_conditions = NULL; information->send_pending = NULL; + information->mutex_created = 0; /* Add to list of clients. */ pthread_mutex_lock(&slave_mutex); @@ -460,8 +473,12 @@ void* slave_loop(void* data) information->thread = pthread_self(); /* Create mutex to make sure two thread to not try to send messages concurrently, and other slave local actions. */ - pthread_mutex_init(&(information->mutex), NULL); - mutex_created = 1; + if ((errno = pthread_mutex_init(&(information->mutex), NULL)) != 0) + { + perror(*argv); + goto fail; + } + information->mutex_created = 1; /* Make the server update without all slaves dying on SIGUSR1. */ @@ -561,7 +578,7 @@ void* slave_loop(void* data) free(information->interception_conditions[i].condition); free(information->interception_conditions); } - if (mutex_created) + if (information->mutex_created) pthread_mutex_destroy(&(information->mutex)); mds_message_destroy(&(information->message)); free(information->send_pending); |