On Wed, 8 Feb 2023 12:48:30 -0500 Laine Stump <laine(a)redhat.com> wrote:Signed-off-by: Laine Stump <laine(a)redhat.com> --- log.c | 14 +++++++++++++- log.h | 1 + passt.c | 6 ++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/log.c b/log.c index 468c730..0ab0adf 100644 --- a/log.c +++ b/log.c @@ -34,6 +34,7 @@ static int log_sock = -1; /* Optional socket to system logger */ static char log_ident[BUFSIZ]; /* Identifier string for openlog() */ static int log_mask; /* Current log priority mask */ static int log_opt; /* Options for openlog() */ +static int log_daemon_mode = false; /* true once process is daemonized */ static int log_file = -1; /* Optional log file descriptor */ static size_t log_size; /* Maximum log file size in bytes */ @@ -67,7 +68,8 @@ void name(const char *format, ...) { \ } \ \ if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) || \ - setlogmask(0) == LOG_MASK(LOG_EMERG)) && log_file == -1) { \ + setlogmask(0) == LOG_MASK(LOG_EMERG)) \ + && (log_file == -1 || !log_daemon_mode)) { \This is getting a bit complicated. At the moment, LOG_EMERG is abused with the meaning "we don't know where/what to log yet", because we didn't process logging options yet. Would it be an option to extend this abuse a bit further, and use LOG_EMERG to indicate that passt didn't daemonise yet, instead? You would just need to move the __setlogmask() calls in main(), and change the comment about the first one. I haven't tested this, and we should be a bit careful with this (check what happens with and without running passt from an interactive terminal, with and without a log file, etc.). A possibly cleaner approach could be to decouple this from the log mask, and have an enum instead, to represent logging "states" or "modes" -- but I'm not sure we're really going to save much complexity with it. By the way, the man page should be updated as well. -- Stefano