Skip to content

Commit

Permalink
Allow daemon to log to stdout as journald can still log the output
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorromeo committed Mar 19, 2021
1 parent 20dd2db commit 4003b67
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 31 deletions.
2 changes: 1 addition & 1 deletion janus-cfgconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int lock_debug = 0;
/* Main Code */
int main(int argc, char *argv[])
{
janus_log_init(FALSE, TRUE, NULL);
janus_log_init(TRUE, NULL);
atexit(janus_log_destroy);

JANUS_LOG(LOG_INFO, "Janus version: %d (%s)\n", janus_version, janus_version_string);
Expand Down
10 changes: 1 addition & 9 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4101,14 +4101,6 @@ gint main(int argc, char *argv[])
if(item && item->value && janus_is_true(item->value))
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) {
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");
Expand Down Expand Up @@ -4185,7 +4177,7 @@ gint main(int argc, char *argv[])
}

/* Initialize logger */
if(janus_log_init(daemonize, use_stdout, logfile) < 0)
if(janus_log_init(use_stdout, logfile) < 0)
exit(1);
/* Check if there are external loggers we need to load as well */
const char *path = NULL;
Expand Down
17 changes: 1 addition & 16 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void janus_vprintf(const char *format, ...) {
g_mutex_unlock(&lock);
}

int janus_log_init(gboolean daemon, gboolean console, const char *logfile) {
int janus_log_init(gboolean console, const char *logfile) {
if (!g_atomic_int_compare_and_exchange(&initialized, 0, 1)) {
return 0;
}
Expand All @@ -239,21 +239,6 @@ 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) {
/* Replace the standard file descriptors */
if (freopen("/dev/null", "r", stdin) == NULL) {
g_print("Error replacing stdin with /dev/null\n");
return -1;
}
if (freopen("/dev/null", "w", stdout) == NULL) {
g_print("Error replacing stdout with /dev/null\n");
return -1;
}
if (freopen("/dev/null", "w", stderr) == NULL) {
g_print("Error replacing stderr with /dev/null\n");
return -1;
}
}
printthread = g_thread_new(THREAD_NAME, &janus_log_thread, NULL);
return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ void janus_vprintf(const char *format, ...) G_GNUC_PRINTF(1, 2);
/*! \brief Log initialization
* \note This should be called before attempting to use the logger. A buffer
* pool and processing thread are created.
* @param daemon Whether the Janus is running as a daemon or not
* @param console Whether the output should be printed on stdout or not
* @param logfile Log file to save the output to, if any
* @returns 0 in case of success, a negative integer otherwise */
int janus_log_init(gboolean daemon, gboolean console, const char *logfile);
int janus_log_init(gboolean console, const char *logfile);
/*! \brief Method to add a list of external loggers to the log management
* @param loggers Hash table of external loggers registered in the core */
void janus_log_set_loggers(GHashTable *loggers);
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int main(int argc, char *argv[])
if(cmdline_parser(argc, argv, &args_info) != 0)
exit(1);

janus_log_init(FALSE, TRUE, NULL);
janus_log_init(TRUE, NULL);
atexit(janus_log_destroy);

/* If we're asked to print the JSON header as it is, we must not print anything else */
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/mjr2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void janus_pp_handle_signal(int signum) {
/* Main Code */
int main(int argc, char *argv[])
{
janus_log_init(FALSE, TRUE, NULL);
janus_log_init(TRUE, NULL);
atexit(janus_log_destroy);

/* Evaluate arguments */
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pcap2mjr.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(int argc, char *argv[])
if(cmdline_parser(argc, argv, &args_info) != 0)
exit(1);

janus_log_init(FALSE, TRUE, NULL);
janus_log_init(TRUE, NULL);
atexit(janus_log_destroy);

/* Evaluate arguments to find source and target */
Expand Down

0 comments on commit 4003b67

Please sign in to comment.