On 2/9/23 12:45 PM, Stefano Brivio wrote:On Wed, 8 Feb 2023 12:48:30 -0500 Laine Stump <laine(a)redhat.com> wrote:Well, the fact that I didn't understand this was what was being done with the log mask kind of indicates this abuse will be misunderstood in the long run :-P But the abuse is already there, so it's not like I'm really making it any (much?) worse. It's just increasing the window when the logmask is set to LOG_EMERG, while modifying the log macro to not care if log_file is opened or not. I'll try that and see how it works out.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.If I'm understanding you, that's kind of what I was doing, it's just that there are two modes - false == "logging before being daemonized" and true == "logging after being daemonized".By the way, the man page should be updated as well.Good point.