diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-12-08 19:15:24 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-12-08 19:15:24 +0100 |
commit | e9880491796516b7e2f835a3df6f20e5da06ebf7 (patch) | |
tree | dc10120bd50d39aa092bea82c1143e5df845ee04 /src/mds-server | |
parent | replace all variants of goto pfail with fail_if (diff) | |
download | mds-e9880491796516b7e2f835a3df6f20e5da06ebf7.tar.gz mds-e9880491796516b7e2f835a3df6f20e5da06ebf7.tar.bz2 mds-e9880491796516b7e2f835a3df6f20e5da06ebf7.tar.xz |
no more goto fail
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server')
-rw-r--r-- | src/mds-server/client.c | 21 | ||||
-rw-r--r-- | src/mds-server/mds-server.c | 22 | ||||
-rw-r--r-- | src/mds-server/receiving.c | 16 |
3 files changed, 30 insertions, 29 deletions
diff --git a/src/mds-server/client.c b/src/mds-server/client.c index 99d561e..37ba906 100644 --- a/src/mds-server/client.c +++ b/src/mds-server/client.c @@ -203,6 +203,7 @@ size_t client_marshal(const client_t* restrict this, char* restrict data) size_t client_unmarshal(client_t* restrict this, char* restrict data) { size_t i, n, rc = sizeof(ssize_t) + 3 * sizeof(int) + sizeof(uint64_t) + 5 * sizeof(size_t); + int saved_errno; this->interception_conditions = NULL; this->multicasts = NULL; this->send_pending = NULL; @@ -223,35 +224,32 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) data += n / sizeof(char); rc += n; buf_get_next(data, size_t, this->interception_conditions_count); - if (xmalloc(this->interception_conditions, this->interception_conditions_count, interception_condition_t)) - goto fail; + fail_if (xmalloc(this->interception_conditions, + this->interception_conditions_count, interception_condition_t)); for (i = 0; i < this->interception_conditions_count; i++) { n = interception_condition_unmarshal(this->interception_conditions + i, data); if (n == 0) { this->interception_conditions_count = i - 1; - goto fail; + fail_if (1); } data += n / sizeof(char); rc += n; } buf_get_next(data, size_t, n); - if (xmalloc(this->multicasts, n, multicast_t)) - goto fail; + fail_if (xmalloc(this->multicasts, n, multicast_t)); for (i = 0; i < n; i++, this->multicasts_count++) { size_t m = multicast_unmarshal(this->multicasts + i, data); - if (m == 0) - goto fail; + fail_if (m == 0); data += m / sizeof(char); rc += m; } buf_get_next(data, size_t, this->send_pending_size); if (this->send_pending_size > 0) { - if (xmalloc(this->send_pending, this->send_pending_size, char)) - goto fail; + fail_if (xmalloc(this->send_pending, this->send_pending_size, char)); memcpy(this->send_pending, data, this->send_pending_size * sizeof(char)); data += this->send_pending_size; rc += this->send_pending_size * sizeof(char); @@ -264,7 +262,8 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) rc += n * sizeof(char); return rc; - fail: + pfail: + saved_errno = errno; mds_message_destroy(&(this->message)); for (i = 0; i < this->interception_conditions_count; i++) free(this->interception_conditions[i].condition); @@ -278,7 +277,7 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) mds_message_destroy(this->modify_message); free(this->modify_message); } - return 0; + return errno = saved_errno, (size_t)0; } /** diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index f058396..499ba96 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -302,7 +302,7 @@ void* slave_loop(void* data) if ((r == 0) && message_received(information)) goto terminate; else if (r == -2) - goto fail; + goto done; else if (r && (errno == EINTR) && terminating) goto terminate; /* Stop the thread if we are re-exec:ing or terminating the server. */ } @@ -329,7 +329,7 @@ void* slave_loop(void* data) if (reexecing) goto reexec; - fail: /* This done on success as well. */ + done: /* Close socket and free resources. */ close(slave_fd); free(msgbuf); @@ -350,7 +350,7 @@ void* slave_loop(void* data) pfail: xperror(*argv); - goto fail; + goto done; reexec: @@ -482,22 +482,22 @@ void queue_message_multicast(char* message, size_t length, client_t* sender) multicast->message_prefix = n; message = NULL; +#define pfail fail_in_mutex /* Queue message multicasting. */ with_mutex (sender->mutex, new_buf = sender->multicasts; - if (xrealloc(new_buf, sender->multicasts_count + 1, multicast_t)) - { - xperror(*argv); - goto fail_queue; - } + fail_if (xrealloc(new_buf, sender->multicasts_count + 1, multicast_t)); sender->multicasts = new_buf; sender->multicasts[sender->multicasts_count++] = *multicast; free(multicast); multicast = NULL; - fail_queue: + errno = 0; + fail_in_mutex: + xperror(*argv); ); +#undef pfail - fail: /* This is done before this function returns even if there was no error. */ + done: /* Release resources. */ xfree(headers, header_count); xfree(header_values, header_count); @@ -510,7 +510,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender) pfail: xperror(*argv); - goto fail; + goto done; } diff --git a/src/mds-server/receiving.c b/src/mds-server/receiving.c index 15ebb4d..100d717 100644 --- a/src/mds-server/receiving.c +++ b/src/mds-server/receiving.c @@ -183,6 +183,7 @@ static int assign_and_send_id(client_t* client, const char* message_id) char* msgbuf = NULL; char* msgbuf_; size_t n; + int rc = -1; /* Construct response. */ n = 2 * 10 + strlen(message_id) + 1; @@ -204,6 +205,7 @@ static int assign_and_send_id(client_t* client, const char* message_id) /* Queue message to be sent when this function returns. This done to simplify `multicast_message` for re-exec and termination. */ +#define pfail fail_in_mutex with_mutex (client->mutex, if (client->send_pending_size == 0) { @@ -216,20 +218,20 @@ static int assign_and_send_id(client_t* client, const char* message_id) /* Concatenate message to already pending messages. */ size_t new_len = client->send_pending_size + n; char* msg_new = client->send_pending; - if (xrealloc(msg_new, new_len, char)) - goto fail; + fail_if (xrealloc(msg_new, new_len, char)); memcpy(msg_new + client->send_pending_size, msgbuf, n * sizeof(char)); client->send_pending = msg_new; client->send_pending_size = new_len; } - fail: + (msgbuf = NULL, rc = 0, errno = 0); + fail_in_mutex: ); +#undef pfail - return 0; - - pfail: + pfail: /* Also success. */ + xperror(*argv); free(msgbuf); - return -1; + return rc; } |