aboutgitcodebugslistschat
path: root/log.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-03-12 23:22:45 +0100
committerStefano Brivio <sbrivio@redhat.com>2024-03-14 08:19:36 +0100
commitf67238aa864d92e0c73af660c7f166f53ab688bc (patch)
treed86b9838d2602611a33b7787dbb18462c70101a8 /log.c
parent3fe9878db7aeda3441c9528965835316e5df4af9 (diff)
downloadpasst-f67238aa864d92e0c73af660c7f166f53ab688bc.tar
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.tar.gz
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.tar.bz2
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.tar.lz
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.tar.xz
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.tar.zst
passt-f67238aa864d92e0c73af660c7f166f53ab688bc.zip
passt, log: Call __openlog() earlier, log to stderr until we detach
Paul reports that, with commit 15001b39ef1d ("conf: set the log level much earlier"), early messages aren't reported to standard error anymore. The reason is that, once the log mask is changed from LOG_EARLY, we don't force logging to stderr, and this mechanism was abused to have early errors on stderr. Now that we drop LOG_EARLY earlier on, this doesn't work anymore. Call __openlog() as soon as we know the mode we're running as, using LOG_PERROR. Then, once we detach, if we're not running from an interactive terminal and logging to standard error is not forced, drop LOG_PERROR from the options. While at it, check if the standard error descriptor refers to a terminal, instead of checking standard output: if the user redirects standard output to /dev/null, they might still want to see messages from standard error. Further, make sure we don't print messages to standard error reporting that we couldn't log to the system logger, if we didn't open a connection yet. That's expected. Reported-by: Paul Holzinger <pholzing@redhat.com> Fixes: 15001b39ef1d ("conf: set the log level much earlier") 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.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/log.c b/log.c
index eafaca2..bdd31b4 100644
--- a/log.c
+++ b/log.c
@@ -174,7 +174,7 @@ void passt_vsyslog(int pri, const char *format, va_list ap)
if (log_opt & LOG_PERROR)
fprintf(stderr, "%s", buf + prefix_len);
- if (send(log_sock, buf, n, 0) != n)
+ if (log_sock >= 0 && send(log_sock, buf, n, 0) != n)
fprintf(stderr, "Failed to send %i bytes to syslog\n", n);
}