diff options
Diffstat (limited to 'src/mds-server/receiving.c')
-rw-r--r-- | src/mds-server/receiving.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/mds-server/receiving.c b/src/mds-server/receiving.c index 15ebb4d..8571944 100644 --- a/src/mds-server/receiving.c +++ b/src/mds-server/receiving.c @@ -93,7 +93,7 @@ static int modifying_notify(client_t* client, mds_message_t message, uint64_t mo return 0; - pfail: + fail: xperror(*argv); if (multicast != NULL) { @@ -116,14 +116,13 @@ static int modifying_notify(client_t* client, mds_message_t message, uint64_t mo */ static int add_intercept_conditions_from_message(client_t* client, int modifying, int64_t priority, int stop) { - int errno_ = 0; + int saved_errno; char* payload = client->message.payload; size_t payload_size = client->message.payload_size; size_t size = 64; char* buf; - if (xmalloc(buf, size + 1, char)) - return -1; + fail_if (xmalloc(buf, size + 1, char)); /* All messages */ if (client->message.payload_size == 0) @@ -149,10 +148,10 @@ static int add_intercept_conditions_from_message(client_t* client, int modifying char* old_buf = buf; if (xrealloc(buf, (size <<= 1) + 1, char)) { - errno_ = errno; + saved_errno = errno; free(old_buf); pthread_mutex_unlock(&(client->mutex)); - break; + fail_if (errno = saved_errno, 1); } } memcpy(buf, payload, len); @@ -166,8 +165,9 @@ static int add_intercept_conditions_from_message(client_t* client, int modifying done: free(buf); - errno = errno_; - return errno_ ? -1 : 0; + return 0; + fail: + return -1; } @@ -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 fail 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 fail - return 0; - - pfail: + fail: /* Also success. */ + xperror(*argv); free(msgbuf); - return -1; + return rc; } @@ -327,7 +329,7 @@ int message_received(client_t* client) return 0; - pfail: + fail: xperror(*argv); free(msgbuf); return 0; |