]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shutdown: explicitly set a log target in shutdown.c
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 23:33:12 +0000 (00:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 23:33:12 +0000 (00:33 +0100)
We used to set this, but this was dropped when shutdown got taught to
get the target passed in from the regular PID 1. Let's readd this to
make things more explanatory, and cover all grounds, since after all the
target passed is in theory an optional part of the protocol between the
regular PID 1 and the shutdown PID 1.

src/core/shutdown.c

index 95eafccc7bb5cc546dd2916d93371cc900fb3832..0326a7808d35e9239bb8cef5d5157c08806390e1 100644 (file)
@@ -276,15 +276,18 @@ int main(int argc, char *argv[]) {
         static const char* const dirs[] = {SYSTEM_SHUTDOWN_PATH, NULL};
         char *watchdog_device;
 
+        /* The log target defaults to console, but the original systemd process will pass its log target in through a
+         * command line argument, which will override this default. Also, ensure we'll never log to the journal or
+         * syslog, as these logging daemons are either already dead or will die very soon. */
+
+        log_set_target(LOG_TARGET_CONSOLE);
+        log_set_prohibit_ipc(true);
         log_parse_environment();
+
         r = parse_argv(argc, argv);
         if (r < 0)
                 goto error;
 
-        /* journald will die if not gone yet. The log target defaults
-         * to console, but may have been changed by command line options. */
-
-        log_set_prohibit_ipc(true);
         log_open();
 
         umask(0022);
@@ -306,8 +309,8 @@ int main(int argc, char *argv[]) {
         else if (streq(arg_verb, "exit"))
                 cmd = 0; /* ignored, just checking that arg_verb is valid */
         else {
-                r = -EINVAL;
                 log_error("Unknown action '%s'.", arg_verb);
+                r = -EINVAL;
                 goto error;
         }
 
@@ -324,7 +327,7 @@ int main(int argc, char *argv[]) {
         }
 
         /* Lock us into memory */
-        mlockall(MCL_CURRENT|MCL_FUTURE);
+        (void) mlockall(MCL_CURRENT|MCL_FUTURE);
 
         /* Synchronize everything that is not written to disk yet at this point already. This is a good idea so that
          * slow IO is processed here already and the final process killing spree is not impacted by processes