From 790f84eb9229452d8041e828abece0e61e4cdca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 10:06:00 +0100 Subject: [PATCH 1/6] shared/bootspec: look at the correct variable The result of this parsing isn't used for anything, so this didn't cause a functional difference, but a spurious warning was emitted. --- src/shared/bootspec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 7bb66f3d87..2e3611850a 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -202,11 +202,11 @@ int boot_loader_read_conf(const char *path, BootConfig *config) { r = free_and_strdup(&config->timeout, p); else if (streq(field, "editor")) r = free_and_strdup(&config->editor, p); - else if (streq(buf, "auto-entries")) + else if (streq(field, "auto-entries")) r = free_and_strdup(&config->auto_entries, p); - else if (streq(buf, "auto-firmware")) + else if (streq(field, "auto-firmware")) r = free_and_strdup(&config->auto_firmware, p); - else if (streq(buf, "console-mode")) + else if (streq(field, "console-mode")) r = free_and_strdup(&config->console_mode, p); else { log_notice("%s:%u: Unknown line \"%s\"", path, line, field); From cd086a014b0f07b1d6cb5fa3881d6a14cb10fd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 10:19:26 +0100 Subject: [PATCH 2/6] systemctl: raise level of log line about kernel loading It's pretty important after all. Also include the actual kexecuted command in the log message, that's useful to debug if something goes wrong. --- src/systemctl/systemctl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1e975a5f2f..e00cbb2b12 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3511,9 +3511,12 @@ static int load_kexec_kernel(void) { if (!options) return log_oom(); - log_debug("%s kexec kernel %s initrd %s options \"%s\".", - arg_dry_run ? "Would load" : "loading", - kernel, initrd, options); + log_full(arg_quiet ? LOG_DEBUG : LOG_INFO, + "%s "KEXEC" --load \"%s\" --append \"%s\"%s%s%s", + arg_dry_run ? "Would run" : "Running", + kernel, + options, + initrd ? " --initrd \"" : NULL, strempty(initrd), initrd ? "\"" : ""); if (arg_dry_run) return 0; From df685d5784e0cfdd89b6153bde886b071afff388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 10:57:44 +0100 Subject: [PATCH 3/6] systemctl: propagate the error from kexec --- src/systemctl/systemctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index e00cbb2b12..3be01321b6 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3524,7 +3524,6 @@ static int load_kexec_kernel(void) { if (r < 0) return r; if (r == 0) { - const char* const args[] = { KEXEC, "--load", kernel, @@ -3537,7 +3536,13 @@ static int load_kexec_kernel(void) { _exit(EXIT_FAILURE); } - return wait_for_terminate_and_check("kexec", pid, WAIT_LOG); + r = wait_for_terminate_and_check("kexec", pid, WAIT_LOG); + if (r < 0) + return r; + if (r > 0) + /* Command failed */ + return -EPROTO; + return 0; } static int set_exit_code(uint8_t code) { From c0d73214986ca006949b86b74c583878a562be53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 11:00:26 +0100 Subject: [PATCH 4/6] systemctl: if kexec is missing, do not try to kexec --- src/systemctl/systemctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 3be01321b6..dfc9630f55 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3483,6 +3483,9 @@ static int load_kexec_kernel(void) { return 0; } + if (access(KEXEC, X_OK) < 0) + return log_error_errno(errno, KEXEC" is not available: %m"); + r = find_esp_and_warn(arg_esp_path, false, &where, NULL, NULL, NULL, NULL); if (r == -ENOKEY) /* find_esp_and_warn() doesn't warn about this case */ return log_error_errno(r, "Cannot find the ESP partition mount point."); From d23b5ce2b6026eaa532feb9b669f217aee2782ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 11:27:15 +0100 Subject: [PATCH 5/6] systemctl: if kexec fails with --force, continue to reboot normally When we are in late shutdown, and for whatever reason kexec fails, we should proceed with a normal reboot. Network is down and sessions have been terminated when we attempt to do the kexec, so rebooting normally is a better solution. Logs from the case where the kexec kernel is not usable: Mar 08 11:23:10 fuefi systemd[1]: Reached target Final Step. Mar 08 11:23:10 fuefi systemd[1]: Starting Reboot via kexec... Mar 08 11:23:10 fuefi systemctl[1480]: Cannot find the ESP partition mount point. Mar 08 11:23:10 fuefi systemctl[1480]: Failed to load kexec kernel, continuing without. Mar 08 11:23:10 fuefi systemd[1]: Shutting down. ... and then we proceed to do a normal reboot Related to #7730. --- src/systemctl/systemctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index dfc9630f55..393c35c60f 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3603,7 +3603,9 @@ static int start_special(int argc, char *argv[], void *userdata) { } else if (a == ACTION_KEXEC) { r = load_kexec_kernel(); - if (r < 0) + if (r < 0 && arg_force >= 1) + log_notice("Failed to load kexec kernel, continuing without."); + else if (r < 0) return r; } else if (a == ACTION_EXIT && argc > 1) { From dbc9830cde21afb585e4e28eafc0230cc0933563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Mar 2018 11:57:59 +0100 Subject: [PATCH 6/6] systemctl: honour --dry-run also on logind calls Fixes #7670. --- src/systemctl/systemctl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 393c35c60f..6ae97cf107 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2915,8 +2915,8 @@ static int start_unit_one( return log_error_errno(r, "Failed to request match for PropertiesChanged signal: %m"); } - log_debug("%s manager for %s on %s, %s", - arg_dry_run ? "Would call" : "Calling", + log_debug("%s dbus call org.freedesktop.systemd1.Manager %s(%s, %s)", + arg_dry_run ? "Would execute" : "Executing", method, name, mode); if (arg_dry_run) return 0; @@ -3215,6 +3215,10 @@ static int logind_set_wall_message(void) { if (!m) return log_oom(); + log_debug("%s wall message \"%s\".", arg_dry_run ? "Would set" : "Setting", m); + if (arg_dry_run) + return 0; + r = sd_bus_call_method( bus, "org.freedesktop.login1", @@ -3285,6 +3289,10 @@ static int logind_reboot(enum action a) { polkit_agent_open_maybe(); (void) logind_set_wall_message(); + log_debug("%s org.freedesktop.login1.Manager %s dbus call.", arg_dry_run ? "Would execute" : "Executing", method); + if (arg_dry_run) + return 0; + r = sd_bus_call_method( bus, "org.freedesktop.login1",