diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c index f765238ba7..03423bdcd3 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.c +++ b/src/libsystemd/sd-bus/bus-common-errors.c @@ -60,8 +60,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = { SD_BUS_ERROR_MAP(BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, EOPNOTSUPP), SD_BUS_ERROR_MAP(BUS_ERROR_SESSION_BUSY, EBUSY), SD_BUS_ERROR_MAP(BUS_ERROR_NOT_YOUR_DEVICE, EPERM), - /* needs to be EOPNOTSUPP for proper handling in callers of logind_schedule_shutdown() */ - SD_BUS_ERROR_MAP(BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, EOPNOTSUPP), + SD_BUS_ERROR_MAP(BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, EBADSLT), SD_BUS_ERROR_MAP(BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED, EALREADY), SD_BUS_ERROR_MAP(BUS_ERROR_NO_NTP_SUPPORT, EOPNOTSUPP), diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 094f9a64bd..7557ab2d93 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2663,11 +2663,11 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ if (r < 0) { if (r == -ENOENT) return sd_bus_error_set(error, - BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, - "No upcoming maintenance window scheduled"); - return sd_bus_error_setf(error, - BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, - "Failed to determine next maintenance window"); + BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, + "No upcoming maintenance window scheduled"); + + return sd_bus_error_set_errnof(error, r, + "Failed to determine next maintenance window: %m"); } log_info("Scheduled %s at maintenance window %s", type, FORMAT_TIMESTAMP(elapse)); diff --git a/src/systemctl/systemctl-compat-halt.c b/src/systemctl/systemctl-compat-halt.c index 4f6e304816..9d69230097 100644 --- a/src/systemctl/systemctl-compat-halt.c +++ b/src/systemctl/systemctl-compat-halt.c @@ -180,10 +180,9 @@ int halt_main(void) { return start_with_fallback(); } - if (geteuid() != 0) { - (void) must_be_root(); - return -EPERM; - } + r = must_be_root(); + if (r < 0) + return r; if (!arg_no_wtmp) { if (sd_booted() > 0) diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c index 00dd05bff7..5fff5d4f18 100644 --- a/src/systemctl/systemctl-start-special.c +++ b/src/systemctl/systemctl-start-special.c @@ -201,14 +201,17 @@ int verb_start_special(int argc, char *argv[], void *userdata) { case ACTION_KEXEC: case ACTION_HALT: case ACTION_SOFT_REBOOT: - if (arg_when == 0) + if (arg_when == 0) { r = logind_reboot(a); - else + if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) + /* The latter indicates that the requested operation requires auth, + * is not supported or already in progress, in which cases we ignore the error. */ + return r; + } else { r = logind_schedule_shutdown(a); - if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) - /* The latter indicates that the requested operation requires auth, - * is not supported or already in progress, in which cases we ignore the error. */ - return r; + if (r != -ENOSYS) + return r; + } /* On all other errors, try low-level operation. In order to minimize the difference * between operation with and without logind, we explicitly enable non-blocking mode