From: Lennart Poettering Date: Tue, 22 Feb 2022 12:26:31 +0000 (+0100) Subject: logind: rename manager_item_for_handle() → handle_action_lookup() X-Git-Tag: v251-rc1~179^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48bccaa92e57ec1449937c2464a93b6d2c4bbb37;p=thirdparty%2Fsystemd.git logind: rename manager_item_for_handle() → handle_action_lookup() The function has nothing to do with any Manager object, hence drop that from the name. And it actually looks something up by handle *action* not by *handle*, hence the old name was a bit misnomer. Let's call it handle_action_lookup(), as it queries handle action metainfo for a handle action. Also, let's make sure it behaves more like our usual functions that lookup some fixed data from some enum value/int: let's return NULL if we don't find it. --- diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 57f7665db69..5a691307b3a 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -18,7 +18,7 @@ #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, @@ -113,11 +113,12 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { }, }; -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( @@ -218,7 +219,7 @@ 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 && @@ -241,7 +242,7 @@ int manager_handle_action( 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), diff --git a/src/login/logind-action.h b/src/login/logind-action.h index 4365bd8d4b4..03284414c57 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -52,6 +52,6 @@ int manager_handle_action( const char* handle_action_to_string(HandleAction h) _const_; HandleAction handle_action_from_string(const char *s) _pure_; -const HandleActionData* manager_item_for_handle(HandleAction handle); +const HandleActionData* handle_action_lookup(HandleAction handle); CONFIG_PARSER_PROTOTYPE(config_parse_handle_action); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index e49eb8dec21..23efe1063b1 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1916,7 +1916,7 @@ static int method_do_shutdown_or_sleep( } 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) @@ -1960,7 +1960,7 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error 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); } @@ -1970,7 +1970,7 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_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); } @@ -1980,7 +1980,7 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er 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); } @@ -1990,7 +1990,7 @@ static int method_suspend(sd_bus_message *message, void *userdata, sd_bus_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); } @@ -2000,7 +2000,7 @@ static int method_hibernate(sd_bus_message *message, void *userdata, sd_bus_erro 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); } @@ -2010,7 +2010,7 @@ static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_e 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); } @@ -2020,7 +2020,7 @@ static int method_suspend_then_hibernate(sd_bus_message *message, void *userdata 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); } @@ -2083,7 +2083,7 @@ void manager_load_scheduled_shutdown(Manager *m) { 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); @@ -2265,7 +2265,7 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ 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); @@ -2418,7 +2418,7 @@ static int method_can_shutdown_or_sleep( 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; @@ -2485,7 +2485,7 @@ static int method_can_poweroff(sd_bus_message *message, void *userdata, sd_bus_e 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); } @@ -2493,7 +2493,7 @@ static int method_can_reboot(sd_bus_message *message, void *userdata, sd_bus_err 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); } @@ -2501,7 +2501,7 @@ static int method_can_halt(sd_bus_message *message, void *userdata, sd_bus_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); } @@ -2509,7 +2509,7 @@ static int method_can_suspend(sd_bus_message *message, void *userdata, sd_bus_er 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); } @@ -2517,7 +2517,7 @@ static int method_can_hibernate(sd_bus_message *message, void *userdata, sd_bus_ 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); } @@ -2525,7 +2525,7 @@ static int method_can_hybrid_sleep(sd_bus_message *message, void *userdata, sd_b 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); } @@ -2533,7 +2533,7 @@ static int method_can_suspend_then_hibernate(sd_bus_message *message, void *user 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); }