diff options
Diffstat (limited to '')
-rw-r--r-- | src/mds-server/client.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/mds-server/client.c b/src/mds-server/client.c index 99d561e..f72a2ce 100644 --- a/src/mds-server/client.c +++ b/src/mds-server/client.c @@ -82,16 +82,18 @@ int client_initialise_threading(client_t* restrict this) /* Create mutex to make sure two thread to not try to send messages concurrently, and other client local actions. */ - if ((errno = pthread_mutex_init(&(this->mutex), NULL))) return -1; + fail_if ((errno = pthread_mutex_init(&(this->mutex), NULL))); this->mutex_created = 1; /* Create mutex and codition for multicast interception replies. */ - if ((errno = pthread_mutex_init(&(this->modify_mutex), NULL))) return -1; + fail_if ((errno = pthread_mutex_init(&(this->modify_mutex), NULL))); this->modify_mutex_created = 1; - if ((errno = pthread_cond_init(&(this->modify_cond), NULL))) return -1; + fail_if ((errno = pthread_cond_init(&(this->modify_cond), NULL))); this->modify_cond_created = 1; return 0; + fail: + return -1; } @@ -203,6 +205,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, stage = 0; this->interception_conditions = NULL; this->multicasts = NULL; this->send_pending = NULL; @@ -218,40 +221,37 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) buf_get_next(data, uint64_t, this->id); buf_get_next(data, size_t, n); if (n > 0) - if (mds_message_unmarshal(&(this->message), data)) - return 0; + fail_if (mds_message_unmarshal(&(this->message), data)); + stage++; 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); @@ -265,6 +265,9 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) return rc; fail: + saved_errno = errno; + if (stage == 0) + goto done_failing; mds_message_destroy(&(this->message)); for (i = 0; i < this->interception_conditions_count; i++) free(this->interception_conditions[i].condition); @@ -278,7 +281,8 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) mds_message_destroy(this->modify_message); free(this->modify_message); } - return 0; + done_failing: + return errno = saved_errno, (size_t)0; } /** |