From ece181226cd2d13585e09d708bfa679874ceee1a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 8 Dec 2014 18:18:33 +0100 Subject: replace all variants of goto pfail with fail_if MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-registry/registry.c | 7 +++---- src/mds-registry/slave.c | 20 ++++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c index 89f1d80..8b1c126 100644 --- a/src/mds-registry/registry.c +++ b/src/mds-registry/registry.c @@ -225,19 +225,18 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_ else if ((action == 0) && !has_key) { /* Add protocl to wait set of not present in the protocol table. */ - if ((command = strdup(command)) == NULL) - goto pfail_wait; + fail_if ((command = strdup(command)) == NULL); command_key = (size_t)(void*)command; if (hash_table_put(wait_set, command_key, 1) == 0) if (errno) { free(command); - goto pfail_wait; + fail_if (1); } } return 0; - pfail_wait: + pfail: xperror(*argv); hash_table_destroy(wait_set, (free_func*)reg_table_free_key, NULL); free(wait_set); diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c index 3825472..9999aa0 100644 --- a/src/mds-registry/slave.c +++ b/src/mds-registry/slave.c @@ -168,29 +168,28 @@ int start_slave(hash_table_t* restrict wait_set, const char* restrict recv_clien slave_t* slave = slave_create(wait_set, recv_client_id, recv_message_id); size_t slave_address, i; ssize_t node = LINKED_LIST_UNUSED; + int locked = 0; fail_if (slave == NULL); fail_if ((errno = pthread_mutex_lock(&slave_mutex))); + locked = 1; slave_address = (size_t)(void*)slave; slave->node = node = linked_list_insert_end(&slave_list, slave_address); - if (slave->node == LINKED_LIST_UNUSED) - goto pfail_in_mutex; + fail_if (slave->node == LINKED_LIST_UNUSED); for (i = 0; i < received.header_count; i++) if (startswith(received.headers[i], "Time to live: ")) { const char* ttl = received.headers[i] + strlen("Time to live: "); slave->timed = 1; - if (monotone(&(slave->dethklok))) - goto pfail_in_mutex; + fail_if (monotone(&(slave->dethklok))); slave->dethklok.tv_sec += (time_t)atoll(ttl); - /* It should really be `atol`, but we want to be future proof. */ + /* It should really be `atol`, but we want to be future-proof. */ break; } - if ((errno = pthread_create(&(slave->thread), NULL, slave_loop, (void*)(intptr_t)slave))) - goto pfail_in_mutex; + fail_if ((errno = pthread_create(&(slave->thread), NULL, slave_loop, (void*)(intptr_t)slave))); if ((errno = pthread_detach(slave->thread))) xperror(*argv); @@ -201,11 +200,8 @@ int start_slave(hash_table_t* restrict wait_set, const char* restrict recv_clien return 0; pfail: xperror(*argv); - goto more_fail; - pfail_in_mutex: - xperror(*argv); - pthread_mutex_unlock(&slave_mutex); - more_fail: + if (locked) + pthread_mutex_unlock(&slave_mutex); if (node != LINKED_LIST_UNUSED) linked_list_remove(&slave_list, node); return -1; -- cgit v1.2.3-70-g09d2