]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: send journald logs to kmsg again
authorFranck Bui <fbui@suse.com>
Fri, 4 Dec 2020 08:48:52 +0000 (09:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Jan 2021 19:36:02 +0000 (20:36 +0100)
This was broken by commit bc694c06e60505efeb09e5278a7b22cdfa23975e.

src/journal/journald.c

index ef7cebce34c6de38b527f439a9cd2a042e4160ee..cfbaf366a9c7d36469e266d24fb2934e7630299b 100644 (file)
@@ -15,6 +15,7 @@
 
 int main(int argc, char *argv[]) {
         const char *namespace;
+        LogTarget log_target;
         Server server;
         int r;
 
@@ -25,8 +26,13 @@ int main(int argc, char *argv[]) {
 
         namespace = argc > 1 ? empty_to_null(argv[1]) : NULL;
 
-        log_set_prohibit_ipc(true);
-        log_set_target(LOG_TARGET_AUTO);
+        /* So here's the deal: journald can't be considered as regular daemon when it comes to
+         * logging hence LOG_TARGET_AUTO won't do the right thing for it. Hence explicitly log to
+         * the console if we're started from a console or to kmsg otherwise. */
+        log_target = isatty(STDERR_FILENO) > 0 ? LOG_TARGET_CONSOLE : LOG_TARGET_KMSG;
+
+        log_set_prohibit_ipc(true); /* better safe than sorry */
+        log_set_target(log_target);
         log_set_facility(LOG_SYSLOG);
         log_parse_environment();
         log_open();