aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/macros.h13
-rw-r--r--src/mds-base.c16
-rw-r--r--src/mds-echo.c8
-rw-r--r--src/mds-registry/mds-registry.c6
-rw-r--r--src/mds-registry/reexec.c2
-rw-r--r--src/mds-registry/registry.c6
-rw-r--r--src/mds-registry/slave.c8
-rw-r--r--src/mds-registry/util.c2
-rw-r--r--src/mds-respawn.c16
-rw-r--r--src/mds-server/interceptors.c6
-rw-r--r--src/mds-server/mds-server.c12
-rw-r--r--src/mds-server/receiving.c4
-rw-r--r--src/mds-server/reexec.c6
-rw-r--r--src/mds-server/sending.c6
-rw-r--r--src/mds-server/slavery.c6
15 files changed, 63 insertions, 54 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index cbef69c..b7eb1d8 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -21,9 +21,10 @@
#include "config.h"
+#include <stdio.h>
+#include <errno.h>
/*
-#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
@@ -333,7 +334,15 @@
*/
#define growalloc(old, var, elements, type) \
(old = var, xrealloc(var, (elements) <<= 1, type) ? (var = old, (elements) >>= 1, perror(*argv), 1) : 0)
-
+
+
+/**
+ * Call `perror` if `errno` is non-zero and set `errno` to zero
+ *
+ * @param str:const char* The argument passed to `perror`
+ */
+#define xperror(str) \
+ (errno ? perror(str), errno = 0 : 0)
/**
diff --git a/src/mds-base.c b/src/mds-base.c
index 04ae25b..77b8835 100644
--- a/src/mds-base.c
+++ b/src/mds-base.c
@@ -176,7 +176,7 @@ int __attribute__((weak)) connect_to_display(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
if (socket_fd >= 0)
close(socket_fd);
return 1;
@@ -194,7 +194,7 @@ void __attribute__((weak)) server_initialised(void)
{
if (r == (pid_t)-1)
{
- perror(*argv);
+ xperror(*argv);
eprint("while forking at completed initialisation.");
exit(1);
}
@@ -302,7 +302,7 @@ static int base_unmarshal(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
@@ -345,7 +345,7 @@ static int base_marshal(int reexec_fd)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
free(state_buf);
return 1;
}
@@ -368,7 +368,7 @@ static void perform_reexec(void)
reexec_fd = shm_open(shm_path, O_RDWR | O_CREAT | O_EXCL, S_IRWXU);
if (reexec_fd < 0)
{
- perror(*argv);
+ xperror(*argv);
return;
}
if (base_marshal(reexec_fd) < 0)
@@ -378,7 +378,7 @@ static void perform_reexec(void)
/* Re-exec the server. */
reexec_server(argc, argv, is_reexec);
- perror(*argv);
+ xperror(*argv);
fail:
if (reexec_fd >= 0)
@@ -460,7 +460,7 @@ int main(int argc_, char** argv_)
pfail:
- perror(*argv);
+ xperror(*argv);
r = 1;
fail:
if (socket_fd >= 0)
@@ -490,7 +490,7 @@ int trap_signals(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
diff --git a/src/mds-echo.c b/src/mds-echo.c
index 4867e90..25f1fa5 100644
--- a/src/mds-echo.c
+++ b/src/mds-echo.c
@@ -185,7 +185,7 @@ int unmarshal_server(char* state_buf)
r = mds_message_unmarshal(&received, state_buf);
if (r)
{
- perror(*argv);
+ xperror(*argv);
mds_message_destroy(&received);
}
return r;
@@ -245,7 +245,7 @@ int master_loop(void)
rc = 0;
goto fail;
pfail:
- perror(*argv);
+ xperror(*argv);
fail:
if (rc || !reexecing)
mds_message_destroy(&received);
@@ -323,7 +323,7 @@ int echo_message(void)
recv_length == NULL ? "" : recv_length,
recv_length == NULL ? "" : "\n");
- /* Increase message ID */
+ /* Increase message ID. */
message_id = message_id == INT32_MAX ? 0 : (message_id + 1);
/* Send echo. */
@@ -354,7 +354,7 @@ int full_send(const char* message, size_t length)
}
else if ((sent < length) && (errno != EINTR))
{
- perror(*argv);
+ xperror(*argv);
return -1;
}
message += sent;
diff --git a/src/mds-registry/mds-registry.c b/src/mds-registry/mds-registry.c
index aa759c8..58463af 100644
--- a/src/mds-registry/mds-registry.c
+++ b/src/mds-registry/mds-registry.c
@@ -65,7 +65,7 @@ int preinitialise_server(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
if (stage >= 1) pthread_mutex_destroy(&slave_mutex);
if (stage >= 2) pthread_cond_destroy(&slave_cond);
return 1;
@@ -105,7 +105,7 @@ int initialise_server(void)
return 1;
if (hash_table_create_tuned(&reg_table, 32))
{
- perror(*argv);
+ xperror(*argv);
hash_table_destroy(&reg_table, NULL, NULL);
return 1;
}
@@ -176,7 +176,7 @@ int master_loop(void)
rc = 0;
goto fail;
pfail:
- perror(*argv);
+ xperror(*argv);
fail:
/* Join with all slaves threads. */
with_mutex (slave_mutex,
diff --git a/src/mds-registry/reexec.c b/src/mds-registry/reexec.c
index dafbff1..9bee27b 100644
--- a/src/mds-registry/reexec.c
+++ b/src/mds-registry/reexec.c
@@ -151,7 +151,7 @@ int unmarshal_server(char* state_buf)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
mds_message_destroy(&received);
if (stage >= 1)
hash_table_destroy(&reg_table, (free_func*)reg_table_free_key, (free_func*)reg_table_free_value);
diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c
index 8c0132e..b05d1a1 100644
--- a/src/mds-registry/registry.c
+++ b/src/mds-registry/registry.c
@@ -108,7 +108,7 @@ static int handle_close_message(void)
free(keys);
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
fail:
free(keys);
return -1;
@@ -167,7 +167,7 @@ static int registry_action_add(int has_key, char* command, size_t command_key, u
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return -1;
}
@@ -239,7 +239,7 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_
return 0;
pfail_wait:
- perror(*argv);
+ xperror(*argv);
hash_table_destroy(wait_set, (free_func*)reg_table_free_key, NULL);
free(wait_set);
return -1;
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c
index 9bc2fd1..6afc69f 100644
--- a/src/mds-registry/slave.c
+++ b/src/mds-registry/slave.c
@@ -63,7 +63,7 @@ static void* slave_loop(void* data)
goto done;
pfail:
- perror(*argv);
+ xperror(*argv);
done:
with_mutex (slave_mutex,
if (!reexecing)
@@ -102,17 +102,17 @@ int start_slave(hash_table_t* restrict wait_set, const char* restrict recv_clien
goto pfail_in_mutex;
if ((errno = pthread_detach(slave->thread)))
- perror(*argv);
+ xperror(*argv);
running_slaves++;
pthread_mutex_unlock(&slave_mutex);
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
goto more_fail;
pfail_in_mutex:
- perror(*argv);
+ xperror(*argv);
pthread_mutex_unlock(&slave_mutex);
more_fail:
if (node != LINKED_LIST_UNUSED)
diff --git a/src/mds-registry/util.c b/src/mds-registry/util.c
index 31df0e1..733aa07 100644
--- a/src/mds-registry/util.c
+++ b/src/mds-registry/util.c
@@ -102,7 +102,7 @@ int full_send(const char* message, size_t length)
}
else if ((sent < length) && (errno != EINTR))
{
- perror(*argv);
+ xperror(*argv);
return -1;
}
message += sent;
diff --git a/src/mds-respawn.c b/src/mds-respawn.c
index 6da3500..24084f0 100644
--- a/src/mds-respawn.c
+++ b/src/mds-respawn.c
@@ -156,7 +156,7 @@ int parse_cmdline(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
@@ -175,7 +175,7 @@ static void spawn_server(size_t index)
if (monotone(&started) < 0)
{
- perror(*argv);
+ xperror(*argv);
eprintf("cannot read clock when starting %s, burying.", commands[index][0]);
states[index].state = DEAD_AND_BURIED;
return;
@@ -188,7 +188,7 @@ static void spawn_server(size_t index)
pid = fork();
if (pid == (pid_t)-1)
{
- perror(*argv);
+ xperror(*argv);
eprintf("cannot fork in order to start %s, burying.", commands[index][0]);
states[index].state = DEAD_AND_BURIED;
return;
@@ -208,7 +208,7 @@ static void spawn_server(size_t index)
/* In the child process (server): change execution image to the server.. */
execvp(commands[index][0], commands[index]);
- perror(commands[index][0]);
+ xperror(commands[index][0]);
_exit(1);
}
@@ -241,7 +241,7 @@ int preinitialise_server(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
@@ -301,7 +301,7 @@ int postinitialise_server(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
@@ -476,7 +476,7 @@ static void joined_with_server(pid_t pid, int status)
/* When did the server exit. */
if (monotone(&ended) < 0)
{
- perror(*argv);
+ xperror(*argv);
eprintf("`%s' died abnormally, burying because we could not read the time.", commands[i][0]);
states[i].state = DEAD_AND_BURIED;
return;
@@ -519,7 +519,7 @@ int master_loop(void)
{
if (errno == EINTR)
continue;
- perror(*argv);
+ xperror(*argv);
rc = 1;
break;
}
diff --git a/src/mds-server/interceptors.c b/src/mds-server/interceptors.c
index 552d7a1..6d798d9 100644
--- a/src/mds-server/interceptors.c
+++ b/src/mds-server/interceptors.c
@@ -56,7 +56,7 @@ static void remove_intercept_condition(client_t* client, size_t index)
}
else
if (xrealloc(conds, n, interception_condition_t))
- perror(*argv);
+ xperror(*argv);
else
client->interception_conditions = conds;
}
@@ -142,14 +142,14 @@ void add_intercept_condition(client_t* client, char* condition, int64_t priority
/* Duplicate condition string. */
if ((condition = strdup(condition)) == NULL)
{
- perror(*argv);
+ xperror(*argv);
return;
}
/* Grow the interception condition list. */
if (xrealloc(conds, n + 1, interception_condition_t))
{
- perror(*argv);
+ xperror(*argv);
free(condition);
return;
}
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c
index d0b6b87..46451a0 100644
--- a/src/mds-server/mds-server.c
+++ b/src/mds-server/mds-server.c
@@ -71,7 +71,7 @@ server_characteristics_t server_characteristics =
if (I >= 6) linked_list_destroy(&client_list)
#define error_if(I, CONDITION) \
- if (CONDITION) { perror(*argv); __free(I); return 1; }
+ if (CONDITION) { xperror(*argv); __free(I); return 1; }
/**
@@ -147,7 +147,7 @@ int preinitialise_server(void)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
return 1;
}
@@ -239,7 +239,7 @@ int accept_connection(void)
else if ((errno == ECONNABORTED) || (errno == EINVAL)) /* Closing. */
running = 0;
else if (errno != EINTR) /* Error. */
- perror(*argv);
+ xperror(*argv);
return 0;
}
@@ -339,7 +339,7 @@ void* slave_loop(void* data)
pfail:
- perror(*argv);
+ xperror(*argv);
goto fail;
@@ -477,7 +477,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
new_buf = sender->multicasts;
if (xrealloc(new_buf, sender->multicasts_count + 1, multicast_t))
{
- perror(*argv);
+ xperror(*argv);
goto fail_queue;
}
sender->multicasts = new_buf;
@@ -499,7 +499,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
return;
pfail:
- perror(*argv);
+ xperror(*argv);
goto fail;
}
diff --git a/src/mds-server/receiving.c b/src/mds-server/receiving.c
index e4dbfe3..016c04e 100644
--- a/src/mds-server/receiving.c
+++ b/src/mds-server/receiving.c
@@ -94,7 +94,7 @@ static int modifying_notify(client_t* client, mds_message_t message, uint64_t mo
pfail:
- perror(*argv);
+ xperror(*argv);
if (multicast != NULL)
{
mds_message_destroy(multicast);
@@ -328,7 +328,7 @@ int message_received(client_t* client)
return 0;
pfail:
- perror(*argv);
+ xperror(*argv);
free(msgbuf);
return 0;
}
diff --git a/src/mds-server/reexec.c b/src/mds-server/reexec.c
index eeedf99..981569e 100644
--- a/src/mds-server/reexec.c
+++ b/src/mds-server/reexec.c
@@ -183,7 +183,7 @@ int unmarshal_server(char* state_buf)
/* Create memory address remapping table. */
if (hash_table_create(&unmarshal_remap_map))
{
- perror(*argv);
+ xperror(*argv);
hash_table_destroy(&unmarshal_remap_map, NULL, NULL);
return -1;
}
@@ -232,7 +232,7 @@ int unmarshal_server(char* state_buf)
/* On error, seek past all clients. */
continue;
clients_fail:
- perror(*argv);
+ xperror(*argv);
with_error = 1;
if (value != NULL)
{
@@ -294,7 +294,7 @@ int unmarshal_server(char* state_buf)
critical_fail:
- perror(*argv);
+ xperror(*argv);
abort();
}
diff --git a/src/mds-server/sending.c b/src/mds-server/sending.c
index 338ce68..98bb26f 100644
--- a/src/mds-server/sending.c
+++ b/src/mds-server/sending.c
@@ -79,7 +79,7 @@ static int send_multicast_to_recipient(multicast_t* multicast, client_t* recipie
n -= sent;
multicast->message_ptr += sent / sizeof(char);
if ((n > 0) && (errno != EINTR))
- perror(*argv);
+ xperror(*argv);
}
);
@@ -188,7 +188,7 @@ void multicast_message(multicast_t* multicast)
old_buf = multicast->message;
if (xrealloc(multicast->message, multicast->message_prefix + n, char))
{
- perror(*argv);
+ xperror(*argv);
multicast->message = old_buf;
}
else
@@ -256,7 +256,7 @@ void send_reply_queue(client_t* client)
sendbuf_ += sent / sizeof(char);
if ((n > 0) && (errno != EINTR)) /* Ignore EINTR */
{
- perror(*argv);
+ xperror(*argv);
break;
}
}
diff --git a/src/mds-server/slavery.c b/src/mds-server/slavery.c
index 4b92154..283251a 100644
--- a/src/mds-server/slavery.c
+++ b/src/mds-server/slavery.c
@@ -61,7 +61,7 @@ int fetch_message(client_t* client)
else if (errno != EINTR)
{
r = -2;
- perror(*argv);
+ xperror(*argv);
}
return r;
@@ -79,13 +79,13 @@ int create_slave(pthread_t* thread_slot, int slave_fd)
{
if ((errno = pthread_create(thread_slot, NULL, slave_loop, (void*)(intptr_t)slave_fd)))
{
- perror(*argv);
+ xperror(*argv);
with_mutex (slave_mutex, running_slaves--;);
return -1;
}
if ((errno = pthread_detach(*thread_slot)))
{
- perror(*argv);
+ xperror(*argv);
return -1;
}
return 0;