#include "terminal-util.h"
#include "user-util.h"
-static const HandleActionData action_table[_HANDLE_ACTION_MAX] = {
+static const HandleActionData handle_action_data_table[_HANDLE_ACTION_MAX] = {
[HANDLE_POWEROFF] = {
.handle = HANDLE_POWEROFF,
.target = SPECIAL_POWEROFF_TARGET,
},
};
-const HandleActionData* manager_item_for_handle(HandleAction handle) {
- assert(handle >= 0);
- assert(handle < (ssize_t) ELEMENTSOF(action_table));
+const HandleActionData* handle_action_lookup(HandleAction action) {
- return &action_table[handle];
+ if (action < 0 || (size_t) action >= ELEMENTSOF(handle_action_data_table))
+ return NULL;
+
+ return &handle_action_data_table[action];
}
int manager_handle_action(
inhibit_what_to_string(m->delayed_action->inhibit_what),
handle_action_to_string(handle));
- inhibit_operation = manager_item_for_handle(handle)->inhibit_what;
+ inhibit_operation = handle_action_lookup(handle)->inhibit_what;
/* If the actual operation is inhibited, warn and fail */
if (!ignore_inhibited &&
log_info("%s", message_table[handle]);
- r = bus_manager_shutdown_or_sleep_now_or_later(m, manager_item_for_handle(handle), &error);
+ r = bus_manager_shutdown_or_sleep_now_or_later(m, handle_action_lookup(handle), &error);
if (r < 0)
return log_error_errno(r, "Failed to execute %s operation: %s",
handle_action_to_string(handle),
}
if ((flags & SD_LOGIND_REBOOT_VIA_KEXEC) && kexec_loaded())
- a = manager_item_for_handle(HANDLE_KEXEC);
+ a = handle_action_lookup(HANDLE_KEXEC);
/* Don't allow multiple jobs being executed at the same time */
if (m->delayed_action)
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_POWEROFF),
+ handle_action_lookup(HANDLE_POWEROFF),
sd_bus_message_is_method_call(message, NULL, "PowerOffWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_REBOOT),
+ handle_action_lookup(HANDLE_REBOOT),
sd_bus_message_is_method_call(message, NULL, "RebootWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_HALT),
+ handle_action_lookup(HANDLE_HALT),
sd_bus_message_is_method_call(message, NULL, "HaltWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_SUSPEND),
+ handle_action_lookup(HANDLE_SUSPEND),
sd_bus_message_is_method_call(message, NULL, "SuspendWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_HIBERNATE),
+ handle_action_lookup(HANDLE_HIBERNATE),
sd_bus_message_is_method_call(message, NULL, "HibernateWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_HYBRID_SLEEP),
+ handle_action_lookup(HANDLE_HYBRID_SLEEP),
sd_bus_message_is_method_call(message, NULL, "HybridSleepWithFlags"),
error);
}
return method_do_shutdown_or_sleep(
m, message,
- manager_item_for_handle(HANDLE_SUSPEND_THEN_HIBERNATE),
+ handle_action_lookup(HANDLE_SUSPEND_THEN_HIBERNATE),
sd_bus_message_is_method_call(message, NULL, "SuspendThenHibernateWithFlags"),
error);
}
return;
/* assign parsed type only after we know usec is also valid */
- m->scheduled_shutdown_type = manager_item_for_handle(handle);
+ m->scheduled_shutdown_type = handle_action_lookup(handle);
if (warn_wall) {
r = parse_boolean(warn_wall);
if (!IN_SET(handle, HANDLE_POWEROFF, HANDLE_REBOOT, HANDLE_HALT, HANDLE_KEXEC))
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unsupported shutdown type");
- a = manager_item_for_handle(handle);
+ a = handle_action_lookup(handle);
assert(a);
assert(a->polkit_action);
if (handle >= 0) {
const char *target;
- target = manager_item_for_handle(handle)->target;
+ target = handle_action_lookup(handle)->target;
if (target) {
_cleanup_free_ char *load_state = NULL;
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_POWEROFF),
+ m, message, handle_action_lookup(HANDLE_POWEROFF),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_REBOOT),
+ m, message, handle_action_lookup(HANDLE_REBOOT),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_HALT),
+ m, message, handle_action_lookup(HANDLE_HALT),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_SUSPEND),
+ m, message, handle_action_lookup(HANDLE_SUSPEND),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_HIBERNATE),
+ m, message, handle_action_lookup(HANDLE_HIBERNATE),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_HYBRID_SLEEP),
+ m, message, handle_action_lookup(HANDLE_HYBRID_SLEEP),
error);
}
Manager *m = userdata;
return method_can_shutdown_or_sleep(
- m, message, manager_item_for_handle(HANDLE_SUSPEND_THEN_HIBERNATE),
+ m, message, handle_action_lookup(HANDLE_SUSPEND_THEN_HIBERNATE),
error);
}