aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/mds-server')
-rw-r--r--src/mds-server/client.c17
-rw-r--r--src/mds-server/interception-condition.c5
-rw-r--r--src/mds-server/multicast.c8
3 files changed, 18 insertions, 12 deletions
diff --git a/src/mds-server/client.c b/src/mds-server/client.c
index 4f5f997..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,7 +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;
+ int saved_errno, stage = 0;
this->interception_conditions = NULL;
this->multicasts = NULL;
this->send_pending = NULL;
@@ -219,8 +221,8 @@ 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);
@@ -264,6 +266,8 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data)
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);
@@ -277,6 +281,7 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data)
mds_message_destroy(this->modify_message);
free(this->modify_message);
}
+ done_failing:
return errno = saved_errno, (size_t)0;
}
diff --git a/src/mds-server/interception-condition.c b/src/mds-server/interception-condition.c
index 31905c9..cfe5d0c 100644
--- a/src/mds-server/interception-condition.c
+++ b/src/mds-server/interception-condition.c
@@ -71,10 +71,11 @@ size_t interception_condition_unmarshal(interception_condition_t* restrict this,
buf_get_next(data, int64_t, this->priority);
buf_get_next(data, int, this->modifying);
n = (strlen(data) + 1) * sizeof(char);
- if ((this->condition = malloc(n)) == NULL)
- return 0;
+ fail_if ((this->condition = malloc(n)) == NULL);
memcpy(this->condition, data, n);
return sizeof(size_t) + sizeof(int64_t) + 2 * sizeof(int) + n;
+ fail:
+ return 0;
}
diff --git a/src/mds-server/multicast.c b/src/mds-server/multicast.c
index 7a0b309..c3d09bc 100644
--- a/src/mds-server/multicast.c
+++ b/src/mds-server/multicast.c
@@ -124,8 +124,7 @@ size_t multicast_unmarshal(multicast_t* restrict this, char* restrict data)
buf_get_next(data, size_t, this->message_ptr);
buf_get_next(data, size_t, this->message_prefix);
if (this->interceptions_count > 0)
- if (xmalloc(this->interceptions, this->interceptions_count, queued_interception_t))
- return 0;
+ fail_if (xmalloc(this->interceptions, this->interceptions_count, queued_interception_t));
for (i = 0; i < this->interceptions_count; i++)
{
n = queued_interception_unmarshal(this->interceptions + i, data);
@@ -134,12 +133,13 @@ size_t multicast_unmarshal(multicast_t* restrict this, char* restrict data)
}
if (this->message_length > 0)
{
- if (xmalloc(this->message, this->message_length, char))
- return 0;
+ fail_if (xmalloc(this->message, this->message_length, char));
memcpy(this->message, data, this->message_length * sizeof(char));
rc += this->message_length * sizeof(char);
}
return rc;
+ fail:
+ return 0;
}