1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

logind/systemctl: one follow-up for DesignatedMaintenanceWindow (#34966)

Fixes https://github.com/systemd/systemd/issues/33429
This commit is contained in:
Lennart Poettering 2024-10-31 21:47:45 +01:00 committed by GitHub
commit 02bf14d924
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 17 deletions

View File

@ -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),

View File

@ -2665,9 +2665,9 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
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");
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));

View File

@ -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)

View File

@ -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
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;
} else {
r = logind_schedule_shutdown(a);
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