diff options
Diffstat (limited to 'src/mds-registry/slave.c')
-rw-r--r-- | src/mds-registry/slave.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c index 8a4d221..ef46963 100644 --- a/src/mds-registry/slave.c +++ b/src/mds-registry/slave.c @@ -55,13 +55,14 @@ static int slave_notify_client(slave_t* slave) while (left > 0) { sent = send_message(socket_fd, buf + ptr, left); - if ((sent < left) && errno && (errno != EINTR)) - return -1; + fail_if ((sent < left) && errno && (errno != EINTR)); left -= sent; ptr += sent; } return 0; + fail: + return -1; } @@ -136,14 +137,12 @@ static void* slave_loop(void* data) */ int start_created_slave(slave_t* restrict slave) { - if ((errno = pthread_mutex_lock(&slave_mutex))) - return -1; + int locked = 0; - if ((errno = pthread_create(&(slave->thread), NULL, slave_loop, (void*)(intptr_t)slave))) - { - pthread_mutex_unlock(&slave_mutex); - return -1; - } + fail_if ((errno = pthread_mutex_lock(&slave_mutex))); + locked = 1; + + fail_if ((errno = pthread_create(&(slave->thread), NULL, slave_loop, (void*)(intptr_t)slave))); if ((errno = pthread_detach(slave->thread))) xperror(*argv); @@ -152,6 +151,10 @@ int start_created_slave(slave_t* restrict slave) pthread_mutex_unlock(&slave_mutex); return 0; + fail: + if (locked) + pthread_mutex_unlock(&slave_mutex); + return -1; } @@ -239,8 +242,7 @@ int advance_slaves(char* command) int signal_slaves = 0; ssize_t node; - if ((errno = pthread_mutex_lock(&slave_mutex))) - return -1; + fail_if ((errno = pthread_mutex_lock(&slave_mutex))); foreach_linked_list_node (slave_list, node) { @@ -257,6 +259,8 @@ int advance_slaves(char* command) pthread_mutex_unlock(&slave_mutex); return 0; + fail: + return -1; } @@ -410,7 +414,8 @@ size_t slave_marshal(const slave_t* restrict this, char* restrict data) size_t slave_unmarshal(slave_t* restrict this, char* restrict data) { size_t key, n, m, rc = 2 * sizeof(int) + sizeof(ssize_t) + sizeof(size_t) + sizeof(uint64_t); - char* protocol; + char* protocol = NULL; + int saved_errno; this->wait_set = NULL; this->client_id = NULL; @@ -427,42 +432,37 @@ size_t slave_unmarshal(slave_t* restrict this, char* restrict data) buf_get_next(data, long, this->dethklok.tv_nsec); n = (strlen((char*)data) + 1) * sizeof(char); - if ((this->client_id = malloc(n)) == NULL) - return 0; + fail_if ((this->client_id = malloc(n)) == NULL); memcpy(this->client_id, data, n); data += n, rc += n; n = (strlen((char*)data) + 1) * sizeof(char); - if ((this->message_id = malloc(n)) == NULL) - return 0; + fail_if ((this->message_id = malloc(n)) == NULL); memcpy(this->message_id, data, n); data += n, rc += n; - if ((this->wait_set = malloc(sizeof(hash_table_t))) == NULL) - return 0; - if (hash_table_create(this->wait_set)) - return 0; + fail_if ((this->wait_set = malloc(sizeof(hash_table_t))) == NULL); + fail_if (hash_table_create(this->wait_set)); buf_get_next(data, size_t, m); while (m--) { n = (strlen((char*)data) + 1) * sizeof(char); - if ((protocol = malloc(n)) == NULL) - return 0; + fail_if ((protocol = malloc(n)) == NULL); memcpy(protocol, data, n); data += n, rc += n; key = (size_t)(void*)protocol; if (hash_table_put(this->wait_set, key, 1) == 0) - if (errno) - { - free(protocol); - return 0; - } + fail_if (errno); } return rc; + fail: + saved_errno = errno; + free(protocol); + return errno = saved_errno, (size_t)0; } |