static const ActionTableItem action_table[_HANDLE_ACTION_MAX] = {
[HANDLE_POWEROFF] = {
+ HANDLE_POWEROFF,
SPECIAL_POWEROFF_TARGET,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.power-off",
"power-off",
},
[HANDLE_REBOOT] = {
+ HANDLE_REBOOT,
SPECIAL_REBOOT_TARGET,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.reboot",
"reboot",
},
[HANDLE_HALT] = {
+ HANDLE_HALT,
SPECIAL_HALT_TARGET,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.halt",
"halt",
},
[HANDLE_KEXEC] = {
+ HANDLE_KEXEC,
SPECIAL_KEXEC_TARGET,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.reboot",
"kexec",
},
[HANDLE_SUSPEND] = {
+ HANDLE_SUSPEND,
SPECIAL_SUSPEND_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.suspend",
SLEEP_SUSPEND,
},
[HANDLE_HIBERNATE] = {
+ HANDLE_HIBERNATE,
SPECIAL_HIBERNATE_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
SLEEP_HIBERNATE,
},
[HANDLE_HYBRID_SLEEP] = {
+ HANDLE_HYBRID_SLEEP,
SPECIAL_HYBRID_SLEEP_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
SLEEP_HYBRID_SLEEP,
},
[HANDLE_SUSPEND_THEN_HIBERNATE] = {
+ HANDLE_SUSPEND_THEN_HIBERNATE,
SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
SLEEP_SUSPEND_THEN_HIBERNATE,
},
[HANDLE_FACTORY_RESET] = {
+ HANDLE_FACTORY_RESET,
SPECIAL_FACTORY_RESET_TARGET,
_INHIBIT_WHAT_INVALID,
NULL,
return &action_table[handle];
}
-HandleAction manager_handle_for_item(const ActionTableItem* a) {
- if (a && a < action_table + ELEMENTSOF(action_table))
- return a - action_table;
- return _HANDLE_ACTION_INVALID;
-}
-
int manager_handle_action(
Manager *m,
InhibitWhat inhibit_key,
#include "sleep-config.h"
struct ActionTableItem {
+ HandleAction handle;
const char *target;
InhibitWhat inhibit_what;
const char *polkit_action;
return r;
r = sd_bus_message_append(reply, "st",
- handle_action_to_string(manager_handle_for_item(m->scheduled_shutdown_type)),
+ m->scheduled_shutdown_type ? handle_action_to_string(m->scheduled_shutdown_type->handle) : NULL,
m->scheduled_shutdown_timeout);
if (r < 0)
return r;
return r;
if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
- if (manager_handle_for_item(a) != HANDLE_REBOOT && (flags & SD_LOGIND_REBOOT_VIA_KEXEC))
+ if (a->handle != HANDLE_REBOOT && (flags & SD_LOGIND_REBOOT_VIA_KEXEC))
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Reboot via kexec is only applicable with reboot operations");
} else {
/* Old style method: no flags parameter, but interactive bool passed as boolean in
int r;
assert(m);
+ assert(m->scheduled_shutdown_type);
r = mkdir_safe_label("/run/systemd/shutdown", 0755, 0, 0, MKDIR_WARN_MODE);
if (r < 0)
"MODE=%s\n",
m->scheduled_shutdown_timeout,
m->enable_wall_messages,
- handle_action_to_string(manager_handle_for_item(m->scheduled_shutdown_type)));
+ handle_action_to_string(m->scheduled_shutdown_type->handle));
if (!isempty(m->wall_message)) {
_cleanup_free_ char *t = NULL;
assert(m);
assert(message);
- cancelled = !IN_SET(manager_handle_for_item(m->scheduled_shutdown_type), HANDLE_IGNORE, _HANDLE_ACTION_INVALID);
+ cancelled = m->scheduled_shutdown_type
+ && !IN_SET(m->scheduled_shutdown_type->handle, HANDLE_IGNORE, _HANDLE_ACTION_INVALID);
if (!cancelled)
goto done;
assert(m);
- if (!m->enable_wall_messages)
+ if (!m->enable_wall_messages || !m->scheduled_shutdown_type)
return 0;
left = m->scheduled_shutdown_timeout > n;
r = asprintf(&l, "%s%sThe system is going down for %s %s%s!",
strempty(m->wall_message),
isempty(m->wall_message) ? "" : "\n",
- handle_action_to_string(manager_handle_for_item(m->scheduled_shutdown_type)),
+ handle_action_to_string(m->scheduled_shutdown_type->handle),
left ? "at " : "NOW",
left ? FORMAT_TIMESTAMP(m->scheduled_shutdown_timeout) : "");
if (r < 0) {