aboutgitcodebugslistschat
path: root/log.c
diff options
context:
space:
mode:
authorLaine Stump <laine@redhat.com>2023-02-15 03:24:30 -0500
committerStefano Brivio <sbrivio@redhat.com>2023-02-16 17:32:03 +0100
commitdac4af81e3cb0a3307d737812ec6a9d830eaf31d (patch)
tree2d0b2ced4f3ff7e210383905aef7d990e006b541 /log.c
parent193385bd2f004a35abe4ef0870b3b482cd1f7919 (diff)
downloadpasst-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar.gz
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar.bz2
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar.lz
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar.xz
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.tar.zst
passt-dac4af81e3cb0a3307d737812ec6a9d830eaf31d.zip
add die() to log an error message and exit with a single call
Almost all occurences of err() are either immediately followed by exit(EXIT_FAILURE), usage(argv[0]) (which itself then calls exit(EXIT_FAILURE), or that is what's done immediately after returning from the function that calls err(). Modify the errfn macro so that its instantiations can include exit(EXIT_FAILURE) at the end, and use that to create a new function die() that will log an error and then exit. Signed-off-by: Laine Stump <laine@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'log.c')
-rw-r--r--log.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/log.c b/log.c
index 6dc6673..2920aba 100644
--- a/log.c
+++ b/log.c
@@ -44,7 +44,7 @@ static char log_header[BUFSIZ]; /* File header, written back on cuts */
static time_t log_start; /* Start timestamp */
int log_trace; /* --trace mode enabled */
-#define logfn(name, level) \
+#define logfn(name, level, doexit) \
void name(const char *format, ...) { \
struct timespec tp; \
va_list args; \
@@ -74,6 +74,9 @@ void name(const char *format, ...) { \
if (format[strlen(format)] != '\n') \
fprintf(stderr, "\n"); \
} \
+ \
+ if (doexit) \
+ exit(EXIT_FAILURE); \
}
/* Prefixes for log file messages, indexed by priority */
@@ -86,10 +89,11 @@ const char *logfile_prefix[] = {
" ", /* LOG_DEBUG */
};
-logfn(err, LOG_ERR)
-logfn(warn, LOG_WARNING)
-logfn(info, LOG_INFO)
-logfn(debug, LOG_DEBUG)
+logfn(die, LOG_ERR, 1)
+logfn(err, LOG_ERR, 0)
+logfn(warn, LOG_WARNING, 0)
+logfn(info, LOG_INFO, 0)
+logfn(debug,LOG_DEBUG, 0)
/**
* trace_init() - Set log_trace depending on trace (debug) mode