chiark / gitweb /
main: when transitioning from initrd to the main system log to kmsg
authorLennart Poettering <lennart@poettering.net>
Mon, 17 Sep 2012 15:42:13 +0000 (17:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 17 Sep 2012 15:47:47 +0000 (17:47 +0200)
When the new PID is invoked the journal socket from the initrd might
still be around. Due to the default log target being journal we'd log to
that initially when the new main systemd initializes even if the kernel
command line included a directive to redirect systemd's logging
elsewhere.

With this fix we initially always log to kmsg now, if we are PID1, and
only after parsing the kernel cmdline try to open the journal if that's
desired.

(The effective benefit of this is that SELinux performance data is now
logged again to kmsg like it used to be.)

TODO
src/core/main.c
src/shared/hwclock.c

diff --git a/TODO b/TODO
index 10f43d7d2522ee8942706252f7d1eed5f1191322..ec31f1d466e946a289e6a970e85856b8b5cc5a57 100644 (file)
--- a/TODO
+++ b/TODO
@@ -28,8 +28,6 @@ F18:
 
 * refuse automount triggers when automount is queued for stop, much like we refuse socket triggers when sockets are queued for stop
 
-* perfomance messages for selinux are gone from debug log?
-
 * There's something wrong with escaping unit names: http://lists.freedesktop.org/archives/systemd-devel/2012-August/006292.html
 
 * logind: different policy actions for idle, suspend, shutdown blockers: allow idle blockers by default, don't allow suspend blockers by default
index 199383e6368e39b3f34355ab26f5087cb6ef72b3..9d2d55154c46c7cf425063f2d8bbeb07a65caa23 100644 (file)
@@ -1285,10 +1285,15 @@ int main(int argc, char *argv[]) {
         saved_argc = argc;
 
         log_show_color(isatty(STDERR_FILENO) > 0);
-        log_show_location(false);
-        log_set_max_level(LOG_INFO);
 
-        if (getpid() == 1) {
+        if (getpid() == 1 && detect_container(NULL) <= 0) {
+
+                /* Running outside of a container as PID 1 */
+                arg_running_as = MANAGER_SYSTEM;
+                make_null_stdio();
+                log_set_target(LOG_TARGET_KMSG);
+                log_open();
+
                 if (in_initrd()) {
                         char *rd_timestamp = NULL;
 
@@ -1302,11 +1307,6 @@ int main(int argc, char *argv[]) {
                         }
                 }
 
-                arg_running_as = MANAGER_SYSTEM;
-
-                make_null_stdio();
-                log_set_target(detect_container(NULL) > 0 ? LOG_TARGET_JOURNAL : LOG_TARGET_JOURNAL_OR_KMSG);
-
                 if (!skip_setup) {
                         if (selinux_setup(&loaded_policy) < 0)
                                 goto finish;
@@ -1314,8 +1314,6 @@ int main(int argc, char *argv[]) {
                                 goto finish;
                 }
 
-                log_open();
-
                 if (label_init(NULL) < 0)
                         goto finish;
 
@@ -1339,7 +1337,28 @@ int main(int argc, char *argv[]) {
                                         log_error("Failed to set the kernel's time zone, ignoring: %s", strerror(-r));
                         }
                 }
+
+                /* Set the default for later on, but don't actually
+                 * open the logs like this for now. Note that if we
+                 * are transitioning from the initrd there might still
+                 * be journal fd open, and we shouldn't attempt
+                 * opening that before we parsed /proc/cmdline which
+                 * might redirect output elsewhere. */
+                log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
+
+        } else if (getpid() == 1) {
+
+                /* Running inside a container, as PID 1 */
+                arg_running_as = MANAGER_SYSTEM;
+                log_set_target(LOG_TARGET_CONSOLE);
+                log_open();
+
+                /* For the later on, see above... */
+                log_set_target(LOG_TARGET_JOURNAL);
+
         } else {
+
+                /* Running as user instance */
                 arg_running_as = MANAGER_USER;
                 log_set_target(LOG_TARGET_AUTO);
                 log_open();
index d9d5600ff34052db0bc03b5075a6e1ddcf24e71e..67eb2eff8b0782c0a650f6418dc08527949d836f 100644 (file)
@@ -154,6 +154,7 @@ int hwclock_set_time(const struct tm *tm) {
 
         return err;
 }
+
 int hwclock_is_localtime(void) {
         FILE *f;
         bool local = false;