X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Feloginctl.c;h=dd0a89d383290e8dcab89e7c577e1c32adfc4fa4;hb=0801458c689ba85fd27666f69e42818f87353bc2;hp=9e40e87ad22ffe12ac5a9069b6ed5a21fabf86d8;hpb=687aa1e7968dcd99a38e165b5386e466491ba7b0;p=elogind.git diff --git a/src/login/eloginctl.c b/src/login/eloginctl.c index 9e40e87ad..dd0a89d38 100644 --- a/src/login/eloginctl.c +++ b/src/login/eloginctl.c @@ -176,6 +176,14 @@ int elogind_cancel_shutdown(sd_bus *bus) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; + r = elogind_set_wall_message(bus, NULL); + + if (r < 0) { + log_warning_errno(r, "Failed to set wall message, ignoring: %s", + bus_error_message(&error, r)); + sd_bus_error_free(&error); + } + r = sd_bus_call_method( bus, "org.freedesktop.login1", @@ -196,6 +204,7 @@ void elogind_cleanup(void) { } static void elogind_log_special(enum elogind_action a) { +#ifdef ENABLE_DEBUG_ELOGIND switch (a) { case ACTION_HALT: log_struct(LOG_INFO, @@ -232,11 +241,13 @@ static void elogind_log_special(enum elogind_action a) { LOG_MESSAGE("Hibernate action called."), LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_START), NULL); + break; case ACTION_HYBRID_SLEEP: log_struct(LOG_INFO, LOG_MESSAGE("Hybrid-Sleep action called."), LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_START), NULL); + break; case ACTION_CANCEL_SHUTDOWN: log_struct(LOG_INFO, LOG_MESSAGE("Cancel Shutdown called."), @@ -246,6 +257,7 @@ static void elogind_log_special(enum elogind_action a) { default: break; } +#endif // ENABLE_DEBUG_ELOGIND } static int elogind_reboot(sd_bus *bus, enum elogind_action a) { @@ -260,8 +272,6 @@ static int elogind_reboot(sd_bus *bus, enum elogind_action a) { if (!bus) return -EIO; - polkit_agent_open_if_enabled(); - switch (a) { case ACTION_POWEROFF: @@ -288,12 +298,16 @@ static int elogind_reboot(sd_bus *bus, enum elogind_action a) { return -EINVAL; } - r = elogind_set_wall_message(bus, table[a]); + polkit_agent_open_if_enabled(); - if (r < 0) { - log_warning_errno(r, "Failed to set wall message, ignoring: %s", - bus_error_message(&error, r)); - sd_bus_error_free(&error); + if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) ) { + r = elogind_set_wall_message(bus, table[a]); + + if (r < 0) { + log_warning_errno(r, "Failed to set wall message, ignoring: %s", + bus_error_message(&error, r)); + sd_bus_error_free(&error); + } } /* Now call elogind itself to request the operation */ @@ -305,8 +319,7 @@ static int elogind_reboot(sd_bus *bus, enum elogind_action a) { method, &error, NULL, - "b", - arg_ask_password); + "b", arg_ask_password); if (r < 0) log_error("Failed to execute operation: %s", bus_error_message(&error, r)); @@ -322,8 +335,6 @@ static int elogind_schedule_shutdown(sd_bus *bus, enum elogind_action a) { if (!bus) return -EIO; - polkit_agent_open_if_enabled(); - switch (a) { case ACTION_POWEROFF: @@ -468,6 +479,42 @@ int start_special(int argc, char *argv[], void *userdata) { elogind_log_special(a); + /* For poweroff and reboot, some extra checks are performed: */ + if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) ) { + + /* No power off actions in chroot environments */ + if ( running_in_chroot() > 0 ) { + log_info("Running in chroot, ignoring request."); + return 0; + } + + /* Check time argument */ + if ( (argc > 1) && (ACTION_CANCEL_SHUTDOWN != arg_action)) { + r = parse_shutdown_time_spec(argv[1], &arg_when); + if (r < 0) { + log_error("Failed to parse time specification: %s", argv[optind]); + return r; + } + } + + /* The optional user wall message must be set */ + if ( (argc > 1) + && ( (arg_action == ACTION_CANCEL_SHUTDOWN) + || (0 == arg_when) ) ) + /* No time argument for shutdown cancel, or no + * time argument given. */ + wall = argv + 1; + else if (argc > 2) + /* We skip the time argument */ + wall = argv + 2; + + if (wall) { + arg_wall = strv_copy(wall); + if (!arg_wall) + return log_oom(); + } + } + /* Switch to cancel shutdown, if a shutdown action was requested, and the option to cancel it was set: */ if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) @@ -478,40 +525,6 @@ int start_special(int argc, char *argv[], void *userdata) { if (r < 0) return r; - /* No power off actions in chroot environments */ - if ((a == ACTION_POWEROFF || - a == ACTION_REBOOT) && - (running_in_chroot() > 0) ) { - log_info("Running in chroot, ignoring request."); - return 0; - } - - /* Check time arguments */ - if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) - && (argc > 1) - && (arg_action != ACTION_CANCEL_SHUTDOWN) ) { - r = parse_shutdown_time_spec(argv[1], &arg_when); - if (r < 0) { - log_error("Failed to parse time specification: %s", argv[optind]); - return r; - } - } else - arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE; - - /* The optional user wall message must be set */ - if ((argc > 1) && (arg_action == ACTION_CANCEL_SHUTDOWN) ) - /* No time argument for shutdown cancel */ - wall = argv + 1; - else if (argc > 2) - /* We skip the time argument */ - wall = argv + 2; - - if (wall) { - arg_wall = strv_copy(wall); - if (!arg_wall) - return log_oom(); - } - /* Perform requested action */ if (IN_SET(a, ACTION_POWEROFF,