From e18805fbd0b42b0c689af985bfb7d5cc8148e49e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Feb 2018 00:33:12 +0100 Subject: [PATCH] shutdown: explicitly set a log target in shutdown.c 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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 95eafccc7bb..0326a7808d3 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -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 -- 2.47.3