From 7f56c3d46efeb15d6e1b440bbc10f0643fdbee5f Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Mon, 10 Sep 2018 19:53:59 +0100 Subject: [PATCH 1/3] Revert "systemctl: fix compilation w/o logind" This reverts commit 807690fb7f7e4998e2bb67f32026ab9f1c7b8077. --- src/systemctl/systemctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9ddd40a48e..ff204cd789 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -8509,8 +8509,8 @@ static int halt_now(enum action a) { } } -#if ENABLE_LOGIND static int logind_schedule_shutdown(void) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char date[FORMAT_TIMESTAMP_MAX]; const char *action; @@ -8563,7 +8563,6 @@ static int logind_schedule_shutdown(void) { log_info("Shutdown scheduled for %s, use 'shutdown -c' to cancel.", format_timestamp(date, sizeof(date), arg_when)); return 0; } -#endif static int halt_main(void) { int r; From cf9cda441ad406417f67e1d919a2a91ee53b4cda Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Mon, 10 Sep 2018 19:54:12 +0100 Subject: [PATCH 2/3] Revert "systemctl: if no logind, don't try to schedule shutdown" This reverts commit c68867da320de296917820e5a76e902a8a86be5a. --- src/systemctl/systemctl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index ff204cd789..c91363f9d7 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -8511,6 +8511,7 @@ static int halt_now(enum action a) { static int logind_schedule_shutdown(void) { +#if ENABLE_LOGIND _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char date[FORMAT_TIMESTAMP_MAX]; const char *action; @@ -8562,6 +8563,10 @@ static int logind_schedule_shutdown(void) { if (!arg_quiet) log_info("Shutdown scheduled for %s, use 'shutdown -c' to cancel.", format_timestamp(date, sizeof(date), arg_when)); return 0; +#else + log_error("Cannot schedule shutdown without logind support, proceeding with immediate shutdown."); + return -ENOSYS; +#endif } static int halt_main(void) { @@ -8572,11 +8577,7 @@ static int halt_main(void) { return r; if (arg_when > 0) -#if ENABLE_LOGIND return logind_schedule_shutdown(); -#else - log_error("Cannot schedule shutdown without logind support, proceeding with immediate shutdown."); -#endif if (geteuid() != 0) { if (arg_dry_run || arg_force > 0) { From 940bec70bb29b105acefd540cd4c7b0b29571de1 Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Tue, 11 Sep 2018 10:41:56 +0100 Subject: [PATCH 3/3] systemctl: correctly proceed to immediate shutdown if scheduling fails Actually check the return code from logind_schedule_shutdown() and proceed to immediate shutdown if that fails. Negative return codes can be returned if systemctl is compiled without logind support, or if logind otherwise failed (either too old, disabled/masked, or it is incomplete systemd-shim/systemd-service implementation). --- src/systemctl/systemctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index c91363f9d7..8094a6aa9f 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -8576,8 +8576,10 @@ static int halt_main(void) { if (r < 0) return r; - if (arg_when > 0) - return logind_schedule_shutdown(); + /* Delayed shutdown requested, and was successful */ + if (arg_when > 0 && logind_schedule_shutdown() == 0) + return 0; + /* no delay, or logind failed or is not at all available */ if (geteuid() != 0) { if (arg_dry_run || arg_force > 0) {