From 4dd379ab6952ccaaa027d5c150da1fbf0fecff16 Mon Sep 17 00:00:00 2001 From: Massimiliano Torromeo Date: Fri, 2 Apr 2021 17:40:05 +0200 Subject: [PATCH] Added new --log-stdout flag that enabled stdout logging even when daemonizing the process (#2591) --- janus.1 | 3 +++ janus.c | 8 ++------ janus.ggo | 1 + log.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/janus.1 b/janus.1 index 5eae19edd7..ad3b36f652 100644 --- a/janus.1 +++ b/janus.1 @@ -26,6 +26,9 @@ Open the specified PID file when starting Janus (default=none) .BR \-N ", " \-\-disable-stdout Disable stdout based logging (default=off) .TP +.BR \-L ", " \-\-log-stdout +Log to stdout, even when the process is daemonized (default=off) +.TP .BR \-L ", " \-\-log-file=\fIpath\fR Log to the specified file (default=stdout only) .TP diff --git a/janus.c b/janus.c index 77965af98c..149585fb5c 100644 --- a/janus.c +++ b/janus.c @@ -4119,7 +4119,7 @@ gint main(int argc, char *argv[]) if(args_info.disable_stdout_given) { use_stdout = FALSE; janus_config_add(config, config_general, janus_config_item_create("log_to_stdout", "no")); - } else { + } else if(!args_info.log_stdout_given) { /* Check if the configuration file is saying anything about this */ janus_config_item *item = janus_config_get(config, config_general, janus_config_type_item, "log_to_stdout"); if(item && item->value && !janus_is_true(item->value)) @@ -4147,13 +4147,9 @@ gint main(int argc, char *argv[]) daemonize = TRUE; } /* If we're going to daemonize, make sure logging to stdout is disabled and a log file has been specified */ - if(daemonize && use_stdout) { + if(daemonize && use_stdout && !args_info.log_stdout_given) { use_stdout = FALSE; } - if(daemonize && logfile == NULL) { - g_print("Running Janus as a daemon but no log file provided, giving up...\n"); - exit(1); - } /* Daemonize now, if we need to */ if(daemonize) { g_print("Running Janus as a daemon\n"); diff --git a/janus.ggo b/janus.ggo index fa8b157b6c..cc5b1318bb 100644 --- a/janus.ggo +++ b/janus.ggo @@ -2,6 +2,7 @@ option "daemon" b "Launch Janus in background as a daemon" flag off option "pid-file" p "Open the specified PID file when starting Janus (default=none)" string typestr="path" optional option "disable-stdout" N "Disable stdout based logging" flag off +option "log-stdout" - "Log to stdout, even when the process is daemonized" flag off option "log-file" L "Log to the specified file (default=stdout only)" string typestr="path" optional option "cwd-path" H "Working directory for Janus daemon process (default=/)" string typestr="path" optional option "interface" i "Interface to use (will be the public IP)" string typestr="ipaddress" optional diff --git a/log.c b/log.c index e1934bb781..f9003cb90b 100644 --- a/log.c +++ b/log.c @@ -239,7 +239,7 @@ int janus_log_init(gboolean daemon, gboolean console, const char *logfile) { g_print("WARNING: logging completely disabled!\n"); g_print(" (no stdout and no logfile, this may not be what you want...)\n"); } - if(daemon) { + if(daemon && !console) { /* Replace the standard file descriptors */ if (freopen("/dev/null", "r", stdin) == NULL) { g_print("Error replacing stdin with /dev/null\n");