aboutgitcodebugslistschat
path: root/log.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-06-04 07:14:49 +0200
committerStefano Brivio <sbrivio@redhat.com>2023-06-23 10:15:55 +0200
commit3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a (patch)
treeb213e0c7ff78f7db6f9116c00d3a9c3cd417daf2 /log.c
parentd072ac243407df464d0e0c74268631e39c5f1251 (diff)
downloadpasst-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.gz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.bz2
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.lz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.xz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.zst
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.zip
conf, log: On -h / --help, print usage to stdout, not stderr
Erik suggests that this makes it easier to grep for options, and with --help we're anyway printing usage information as expected, not as part of an error report. While at it: on -h, we should exit with 0. Reported-by: Erik Sjölund <erik.sjolund@gmail.com> Link: https://bugs.passt.top/show_bug.cgi?id=52 Link: https://bugs.passt.top/show_bug.cgi?id=53 Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'log.c')
-rw-r--r--log.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/log.c b/log.c
index 3a3d101..63d7801 100644
--- a/log.c
+++ b/log.c
@@ -43,17 +43,19 @@ static char log_header[BUFSIZ]; /* File header, written back on cuts */
static time_t log_start; /* Start timestamp */
int log_trace; /* --trace mode enabled */
+int log_to_stdout; /* Print to stdout instead of stderr */
#define BEFORE_DAEMON (setlogmask(0) == LOG_MASK(LOG_EMERG))
#define logfn(name, level) \
void name(const char *format, ...) { \
+ FILE *out = log_to_stdout ? stdout : stderr; \
struct timespec tp; \
va_list args; \
\
if (setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) { \
clock_gettime(CLOCK_REALTIME, &tp); \
- fprintf(stderr, "%lli.%04lli: ", \
+ fprintf(out, "%lli.%04lli: ", \
(long long int)tp.tv_sec - log_start, \
(long long int)tp.tv_nsec / (100L * 1000)); \
} \
@@ -70,10 +72,10 @@ void name(const char *format, ...) { \
if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file == -1) || \
(BEFORE_DAEMON && !(log_opt & LOG_PERROR))) { \
va_start(args, format); \
- (void)vfprintf(stderr, format, args); \
+ (void)vfprintf(out, format, args); \
va_end(args); \
if (format[strlen(format)] != '\n') \
- fprintf(stderr, "\n"); \
+ fprintf(out, "\n"); \
} \
}