]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: make log_set_upgrade_syslog_to_journal() take effect immediately
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Jan 2018 16:33:07 +0000 (17:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Jan 2018 17:22:56 +0000 (18:22 +0100)
This doesn't matter much, and we don't rely on it, but I think it's much
nicer if we log_set_target() and log_set_upgrade_syslog_to_journal() can
be called in either order and have the same effect.

src/basic/log.c
src/basic/log.h
src/core/main.c

index 9169474289b41764b26725d8be9dadcf539e7fc5..8a65aa349e4725bcc724fdb0b8fdb08f0bd6759b 100644 (file)
@@ -1314,6 +1314,14 @@ int log_syntax_invalid_utf8_internal(
 
 void log_set_upgrade_syslog_to_journal(bool b) {
         upgrade_syslog_to_journal = b;
+
+        /* Make the change effective immediately */
+        if (b) {
+                if (log_target == LOG_TARGET_SYSLOG)
+                        log_target = LOG_TARGET_JOURNAL;
+                else if (log_target == LOG_TARGET_SYSLOG_OR_KMSG)
+                        log_target = LOG_TARGET_JOURNAL_OR_KMSG;
+        }
 }
 
 void log_set_always_reopen_console(bool b) {
index b97cdcd703de8cb5c0826a4ee85aab51ebc96a56..910a89a25596be51ea60c8441714175c7834afab 100644 (file)
@@ -302,6 +302,7 @@ LogTarget log_target_from_string(const char *s) _pure_;
 
 void log_received_signal(int level, const struct signalfd_siginfo *si);
 
+/* If turned on, any requests for a log target involving "syslog" will be implicitly upgraded to the equivalent journal target */
 void log_set_upgrade_syslog_to_journal(bool b);
 void log_set_always_reopen_console(bool b);
 void log_set_open_when_needed(bool b);
index 7d20f4e67b60d3bb86d1f10a3ca3c0375990aac4..9ecb8e983559019b8fe2c99a34a34292fa601f78 100644 (file)
@@ -2328,6 +2328,7 @@ int main(int argc, char *argv[]) {
         saved_argv = argv;
         saved_argc = argc;
 
+        /* Make sure that if the user says "syslog" we actually log to the journal. */
         log_set_upgrade_syslog_to_journal(true);
 
         if (getpid_cached() == 1) {