generator: use kmsg in system-level generators, journal otherwise v246.7
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Sep 2020 14:19:12 +0000 (16:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Dec 2020 17:08:31 +0000 (18:08 +0100)
Fixes: #17129.
(cherry picked from commit dee29aeb5909f4f5604012ced250488286b8d468)

https://github.com/systemd/systemd-stable/issues/76

src/shared/generator.c

index 04d2f86a4a3e32dc1843b285a33bb619244a3be7..d61b367d33709187338a3e54f377b40a6fb3393a 100644 (file)
@@ -4,6 +4,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "cgroup-util.h"
 #include "dropin.h"
 #include "escape.h"
 #include "fd-util.h"
@@ -620,6 +621,11 @@ int generator_write_cryptsetup_service_section(
 }
 
 void log_setup_generator(void) {
-        log_set_prohibit_ipc(true);
-        log_setup_service();
+        /* Disable talking to syslog/journal (i.e. the two IPC-based loggers) if we run in system context. */
+        if (cg_pid_get_owner_uid(0, NULL) == -ENXIO /* not running in a per-user slice */)
+                log_set_prohibit_ipc(true);
+
+        log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); /* This effectively means: journal for per-user generators, kmsg otherwise */
+        log_parse_environment();
+        (void) log_open();
 }