diff options
Diffstat (limited to '')
-rw-r--r-- | src/mds-server/slavery.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/mds-server/slavery.c b/src/mds-server/slavery.c index df6d552..088b6af 100644 --- a/src/mds-server/slavery.c +++ b/src/mds-server/slavery.c @@ -47,11 +47,15 @@ void* slave_loop(void*); int fetch_message(client_t* client) { int r = mds_message_read(&(client->message), client->socket_fd); + if (r == 0) return 0; if (r == -2) - eprint("corrupt message received."); + { + eprint("corrupt message received."); + fail_if (1); + } else if (errno == ECONNRESET) { r = mds_message_read(&(client->message), client->socket_fd); @@ -60,11 +64,14 @@ int fetch_message(client_t* client) } else if (errno != EINTR) { - r = -2; xperror(*argv); + fail_if (1); } + fail_if (r == -2); return r; + fail: + return -2; } @@ -81,14 +88,16 @@ int create_slave(pthread_t* thread_slot, int slave_fd) { xperror(*argv); with_mutex (slave_mutex, running_slaves--;); - return -1; + fail_if (1); } if ((errno = pthread_detach(*thread_slot))) { xperror(*argv); - return -1; + fail_if (1); } return 0; + fail: + return -1; } @@ -96,14 +105,13 @@ int create_slave(pthread_t* thread_slot, int slave_fd) * Initialise a client, except for threading * * @param client_fd The file descriptor of the client's socket - * @return The client information, NULL on error + * @return The client information, `NULL` on error */ client_t* initialise_client(int client_fd) { ssize_t entry = LINKED_LIST_UNUSED; - int locked = 0; client_t* information; - int errno_; + int locked = 0, saved_errno; size_t tmp; /* Create information table. */ @@ -131,14 +139,13 @@ client_t* initialise_client(int client_fd) return information; - pfail: - errno_ = errno; + fail: + saved_errno = errno; if (locked) pthread_mutex_unlock(&slave_mutex); free(information); if (entry != LINKED_LIST_UNUSED) with_mutex (slave_mutex, linked_list_remove(&client_list, entry);); - errno = errno_; - return NULL; + return errno = saved_errno, NULL; } |