diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/src/common.c b/src/common.c index eb69b80..73f8e5c 100644 --- a/src/common.c +++ b/src/common.c @@ -131,11 +131,19 @@ log_message (int priority, const char *quote, const char *fmt, ...) va_end (ap); } +// `fatal' is reserved for unexpected failures that would harm further operation + #define print_fatal(...) log_message (LOG_ERR, "fatal: ", __VA_ARGS__) #define print_error(...) log_message (LOG_ERR, "error: ", __VA_ARGS__) #define print_warning(...) log_message (LOG_WARNING, "warning: ", __VA_ARGS__) #define print_status(...) log_message (LOG_INFO, "-- ", __VA_ARGS__) +#define exit_fatal(...) \ + BLOCK_START \ + print_fatal (__VA_ARGS__); \ + exit (EXIT_FAILURE); \ + BLOCK_END + // --- Debugging and assertions ------------------------------------------------ // We should check everything that may possibly fail with at least a soft @@ -191,10 +199,7 @@ xmalloc (size_t n) { void *p = malloc (n); if (!p) - { - print_fatal ("malloc: %s", strerror (errno)); - exit (EXIT_FAILURE); - } + exit_fatal ("malloc: %s", strerror (errno)); return p; } @@ -203,10 +208,7 @@ xcalloc (size_t n, size_t m) { void *p = calloc (n, m); if (!p && n && m) - { - print_fatal ("calloc: %s", strerror (errno)); - exit (EXIT_FAILURE); - } + exit_fatal ("calloc: %s", strerror (errno)); return p; } @@ -215,10 +217,7 @@ xrealloc (void *o, size_t n) { void *p = realloc (o, n); if (!p && n) - { - print_fatal ("realloc: %s", strerror (errno)); - exit (EXIT_FAILURE); - } + exit_fatal ("realloc: %s", strerror (errno)); return p; } @@ -228,8 +227,7 @@ xreallocarray (void *o, size_t n, size_t m) if (m && n > SIZE_MAX / m) { errno = ENOMEM; - print_fatal ("reallocarray: %s", strerror (errno)); - exit (EXIT_FAILURE); + exit_fatal ("reallocarray: %s", strerror (errno)); } return xrealloc (o, n * m); } @@ -1170,10 +1168,7 @@ poller_run (struct poller *self) while (n_fds == -1 && errno == EINTR); if (n_fds == -1) - { - print_fatal ("%s: %s", "epoll", strerror (errno)); - exit (EXIT_FAILURE); - } + exit_fatal ("%s: %s", "epoll", strerror (errno)); poller_timers_dispatch (&self->timers); @@ -1312,10 +1307,7 @@ poller_run (struct poller *self) while (result == -1 && errno == EINTR); if (result == -1) - { - print_fatal ("%s: %s", "poll", strerror (errno)); - exit (EXIT_FAILURE); - } + exit_fatal ("%s: %s", "poll", strerror (errno)); poller_timers_dispatch (&self->timers); @@ -1931,7 +1923,7 @@ call_write_default_config (const char *hint, const struct config_item *table) char *filename = write_default_config (hint, prolog, table, &e); if (!filename) { - print_fatal ("%s", e->message); + print_error ("%s", e->message); error_free (e); exit (EXIT_FAILURE); } |