From 6800876608f906e862f75d926e0fb2f380b138fc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:05:16 +0100 Subject: [PATCH 1/6] logind: replace handle_action_valid() macro by inline function The old macro will double evaluation and has no protection against operator precedence issues. Let's fix that by using an inline func instead, which also gives us typesafety. --- src/login/logind-action.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/login/logind-action.h b/src/login/logind-action.h index 4dcf719488..dc073fe951 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -21,12 +21,14 @@ typedef enum HandleAction { typedef struct ActionTableItem ActionTableItem; -#define handle_action_valid(x) (x >= 0 && x < _HANDLE_ACTION_MAX) - #include "logind-inhibit.h" #include "logind.h" #include "sleep-config.h" +static inline bool handle_action_valid(HandleAction a) { + return a >= 0 && a < _HANDLE_ACTION_MAX; +} + struct ActionTableItem { HandleAction handle; const char *target; From b0a3a5e53899438def7139c0d7ae7f9f984b744b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:19:44 +0100 Subject: [PATCH 2/6] =?UTF-8?q?logind:=20rename=20ActionTableItem=20?= =?UTF-8?q?=E2=86=92=20HandleActionData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It stores meta-info about various HandleActions, hence let's name it after that. The fact that it can be seen as stored inside some form of a table is an implementation detail of logind-action.c, and should not leak into other modules, hence let's focus on what it is, not how it is stored. --- src/login/logind-action.c | 4 ++-- src/login/logind-action.h | 8 ++++---- src/login/logind-dbus.c | 20 ++++++++++---------- src/login/logind-dbus.h | 2 +- src/login/logind.h | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 50feb7e651..7d1d4bf685 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 ActionTableItem action_table[_HANDLE_ACTION_MAX] = { +static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { [HANDLE_POWEROFF] = { .handle = HANDLE_POWEROFF, .target = SPECIAL_POWEROFF_TARGET, @@ -113,7 +113,7 @@ static const ActionTableItem action_table[_HANDLE_ACTION_MAX] = { }, }; -const ActionTableItem* manager_item_for_handle(HandleAction handle) { +const HandleActionData* manager_item_for_handle(HandleAction handle) { assert(handle >= 0); assert(handle < (ssize_t) ELEMENTSOF(action_table)); diff --git a/src/login/logind-action.h b/src/login/logind-action.h index dc073fe951..21635376c8 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -19,7 +19,7 @@ typedef enum HandleAction { _HANDLE_ACTION_INVALID = -EINVAL, } HandleAction; -typedef struct ActionTableItem ActionTableItem; +typedef struct HandleActionData HandleActionData; #include "logind-inhibit.h" #include "logind.h" @@ -29,7 +29,7 @@ static inline bool handle_action_valid(HandleAction a) { return a >= 0 && a < _HANDLE_ACTION_MAX; } -struct ActionTableItem { +struct HandleActionData { HandleAction handle; const char *target; InhibitWhat inhibit_what; @@ -52,7 +52,7 @@ int manager_handle_action( const char* handle_action_to_string(HandleAction h) _const_; HandleAction handle_action_from_string(const char *s) _pure_; -const ActionTableItem* manager_item_for_handle(HandleAction handle); -HandleAction manager_handle_for_item(const ActionTableItem* a); +const HandleActionData* manager_item_for_handle(HandleAction handle); +HandleAction manager_handle_for_item(const HandleActionData* a); CONFIG_PARSER_PROTOTYPE(config_parse_handle_action); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 7f6a6cce18..e49eb8dec2 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1513,7 +1513,7 @@ static int have_multiple_sessions( static int bus_manager_log_shutdown( Manager *m, - const ActionTableItem *a) { + const HandleActionData *a) { const char *message, *log_message; @@ -1603,7 +1603,7 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { static int execute_shutdown_or_sleep( Manager *m, - const ActionTableItem *a, + const HandleActionData *a, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; @@ -1699,7 +1699,7 @@ static int manager_inhibit_timeout_handler( static int delay_shutdown_or_sleep( Manager *m, - const ActionTableItem *a) { + const HandleActionData *a) { int r; @@ -1731,7 +1731,7 @@ static int delay_shutdown_or_sleep( int bus_manager_shutdown_or_sleep_now_or_later( Manager *m, - const ActionTableItem *a, + const HandleActionData *a, sd_bus_error *error) { _cleanup_free_ char *load_state = NULL; @@ -1773,7 +1773,7 @@ int bus_manager_shutdown_or_sleep_now_or_later( static int verify_shutdown_creds( Manager *m, sd_bus_message *message, - const ActionTableItem *a, + const HandleActionData *a, uint64_t flags, sd_bus_error *error) { @@ -1882,7 +1882,7 @@ static int setup_wall_message_timer(Manager *m, sd_bus_message* message) { static int method_do_shutdown_or_sleep( Manager *m, sd_bus_message *message, - const ActionTableItem *a, + const HandleActionData *a, bool with_flags, sd_bus_error *error) { @@ -2197,7 +2197,7 @@ static int manager_scheduled_shutdown_handler( uint64_t usec, void *userdata) { - const ActionTableItem *a = NULL; + const HandleActionData *a = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; Manager *m = userdata; int r; @@ -2243,7 +2243,7 @@ error: static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; HandleAction handle; - const ActionTableItem *a; + const HandleActionData *a; uint64_t elapse; char *type; int r; @@ -2323,7 +2323,7 @@ fail: static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; - const ActionTableItem *a; + const HandleActionData *a; bool cancelled; int r; @@ -2378,7 +2378,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd static int method_can_shutdown_or_sleep( Manager *m, sd_bus_message *message, - const ActionTableItem *a, + const HandleActionData *a, sd_bus_error *error) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; diff --git a/src/login/logind-dbus.h b/src/login/logind-dbus.h index 1cdfd3eec9..11eb170d17 100644 --- a/src/login/logind-dbus.h +++ b/src/login/logind-dbus.h @@ -15,7 +15,7 @@ int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char int manager_dispatch_delayed(Manager *manager, bool timeout); -int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const ActionTableItem *a, sd_bus_error *error); +int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const HandleActionData *a, sd_bus_error *error); int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error); int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error); diff --git a/src/login/logind.h b/src/login/logind.h index af9af9e457..1613daa04e 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -71,14 +71,14 @@ struct Manager { /* If a shutdown/suspend was delayed due to an inhibitor this contains the action we are supposed to start after the delay is over */ - const ActionTableItem *delayed_action; + const HandleActionData *delayed_action; /* If a shutdown/suspend is currently executed, then this is * the job of it */ char *action_job; sd_event_source *inhibit_timeout_source; - const ActionTableItem *scheduled_shutdown_type; + const HandleActionData *scheduled_shutdown_type; usec_t scheduled_shutdown_timeout; sd_event_source *scheduled_shutdown_timeout_source; uid_t scheduled_shutdown_uid; From 510eccab5f89ca1a0a6d6030730881091b53ef70 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:23:52 +0100 Subject: [PATCH 3/6] logind: minor whitespace fix --- src/login/logind-action.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 7d1d4bf685..57f7665db6 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -43,7 +43,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .message = "System is rebooting", .log_message = "reboot", }, - [HANDLE_HALT] = { + [HANDLE_HALT] = { .handle = HANDLE_HALT, .target = SPECIAL_HALT_TARGET, .inhibit_what = INHIBIT_SHUTDOWN, @@ -55,7 +55,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .message = "System is halting", .log_message = "halt", }, - [HANDLE_KEXEC] = { + [HANDLE_KEXEC] = { .handle = HANDLE_KEXEC, .target = SPECIAL_KEXEC_TARGET, .inhibit_what = INHIBIT_SHUTDOWN, @@ -67,7 +67,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .message = "System is rebooting with kexec", .log_message = "kexec", }, - [HANDLE_SUSPEND] = { + [HANDLE_SUSPEND] = { .handle = HANDLE_SUSPEND, .target = SPECIAL_SUSPEND_TARGET, .inhibit_what = INHIBIT_SLEEP, @@ -76,7 +76,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .polkit_action_ignore_inhibit = "org.freedesktop.login1.suspend-ignore-inhibit", .sleep_operation = SLEEP_SUSPEND, }, - [HANDLE_HIBERNATE] = { + [HANDLE_HIBERNATE] = { .handle = HANDLE_HIBERNATE, .target = SPECIAL_HIBERNATE_TARGET, .inhibit_what = INHIBIT_SLEEP, @@ -85,7 +85,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .polkit_action_ignore_inhibit = "org.freedesktop.login1.hibernate-ignore-inhibit", .sleep_operation = SLEEP_HIBERNATE, }, - [HANDLE_HYBRID_SLEEP] = { + [HANDLE_HYBRID_SLEEP] = { .handle = HANDLE_HYBRID_SLEEP, .target = SPECIAL_HYBRID_SLEEP_TARGET, .inhibit_what = INHIBIT_SLEEP, @@ -94,7 +94,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .polkit_action_ignore_inhibit = "org.freedesktop.login1.hibernate-ignore-inhibit", .sleep_operation = SLEEP_HYBRID_SLEEP, }, - [HANDLE_SUSPEND_THEN_HIBERNATE] = { + [HANDLE_SUSPEND_THEN_HIBERNATE] = { .handle = HANDLE_SUSPEND_THEN_HIBERNATE, .target = SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET, .inhibit_what = INHIBIT_SLEEP, @@ -103,7 +103,7 @@ static const HandleActionData action_table[_HANDLE_ACTION_MAX] = { .polkit_action_ignore_inhibit = "org.freedesktop.login1.hibernate-ignore-inhibit", .sleep_operation = SLEEP_SUSPEND_THEN_HIBERNATE, }, - [HANDLE_FACTORY_RESET] = { + [HANDLE_FACTORY_RESET] = { .handle = HANDLE_FACTORY_RESET, .target = SPECIAL_FACTORY_RESET_TARGET, .inhibit_what = _INHIBIT_WHAT_INVALID, From 5e06260b2cf294b3776ec0c619c53f98e8650c23 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:24:40 +0100 Subject: [PATCH 4/6] logind: drop unused prototype --- src/login/logind-action.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/login/logind-action.h b/src/login/logind-action.h index 21635376c8..4365bd8d4b 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -53,6 +53,5 @@ 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); -HandleAction manager_handle_for_item(const HandleActionData* a); CONFIG_PARSER_PROTOTYPE(config_parse_handle_action); From 48bccaa92e57ec1449937c2464a93b6d2c4bbb37 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:26:31 +0100 Subject: [PATCH 5/6] =?UTF-8?q?logind:=20rename=20manager=5Fitem=5Ffor=5Fh?= =?UTF-8?q?andle()=20=E2=86=92=20handle=5Faction=5Flookup()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/login/logind-action.c | 15 ++++++++------- src/login/logind-action.h | 2 +- src/login/logind-dbus.c | 36 ++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 57f7665db6..5a691307b3 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 4365bd8d4b..03284414c5 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 e49eb8dec2..23efe1063b 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); } From a3ddcc111491380b9cfeba310ec4da7a1c87c8d0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 13:28:24 +0100 Subject: [PATCH 6/6] =?UTF-8?q?logind:=20rename=20scheduled=5Fshutdown=5Ft?= =?UTF-8?q?ype=20=E2=86=92=20scheduled=5Fshutdown=5Faction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches naming of the 'delayed_action' field we already have. It's similar in both type and concept, and hence should be named similarly. --- src/login/logind-dbus.c | 24 ++++++++++++------------ src/login/logind-utmp.c | 6 +++--- src/login/logind.h | 10 ++++------ 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 23efe1063b..2ed4eeddfe 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -365,7 +365,7 @@ static int property_get_scheduled_shutdown( return r; r = sd_bus_message_append(reply, "st", - m->scheduled_shutdown_type ? handle_action_to_string(m->scheduled_shutdown_type->handle) : NULL, + m->scheduled_shutdown_action ? handle_action_to_string(m->scheduled_shutdown_action->handle) : NULL, m->scheduled_shutdown_timeout); if (r < 0) return r; @@ -1944,7 +1944,7 @@ static int method_do_shutdown_or_sleep( reset_scheduled_shutdown(m); m->scheduled_shutdown_timeout = 0; - m->scheduled_shutdown_type = a; + m->scheduled_shutdown_action = a; (void) setup_wall_message_timer(m, message); @@ -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 = handle_action_lookup(handle); + m->scheduled_shutdown_action = handle_action_lookup(handle); if (warn_wall) { r = parse_boolean(warn_wall); @@ -2126,7 +2126,7 @@ static int update_schedule_file(Manager *m) { int r; assert(m); - assert(m->scheduled_shutdown_type); + assert(m->scheduled_shutdown_action); r = mkdir_parents_label(SHUTDOWN_SCHEDULE_FILE, 0755); if (r < 0) @@ -2140,7 +2140,7 @@ static int update_schedule_file(Manager *m) { serialize_usec(f, "USEC", m->scheduled_shutdown_timeout); serialize_item_format(f, "WARN_WALL", "%s", one_zero(m->enable_wall_messages)); - serialize_item_format(f, "MODE", "%s", handle_action_to_string(m->scheduled_shutdown_type->handle)); + serialize_item_format(f, "MODE", "%s", handle_action_to_string(m->scheduled_shutdown_action->handle)); serialize_item_format(f, "UID", UID_FMT, m->scheduled_shutdown_uid); if (m->scheduled_shutdown_tty) @@ -2177,7 +2177,7 @@ static void reset_scheduled_shutdown(Manager *m) { m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source); m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source); - m->scheduled_shutdown_type = NULL; + m->scheduled_shutdown_action = NULL; m->scheduled_shutdown_timeout = USEC_INFINITY; m->scheduled_shutdown_uid = UID_INVALID; m->scheduled_shutdown_tty = mfree(m->scheduled_shutdown_tty); @@ -2204,7 +2204,7 @@ static int manager_scheduled_shutdown_handler( assert(m); - a = m->scheduled_shutdown_type; + a = m->scheduled_shutdown_action; assert(a); /* Don't allow multiple jobs being executed at the same time */ @@ -2227,7 +2227,7 @@ static int manager_scheduled_shutdown_handler( return 0; } - r = bus_manager_shutdown_or_sleep_now_or_later(m, m->scheduled_shutdown_type, &error); + r = bus_manager_shutdown_or_sleep_now_or_later(m, m->scheduled_shutdown_action, &error); if (r < 0) { log_error_errno(r, "Scheduled shutdown to %s failed: %m", a->target); goto error; @@ -2273,7 +2273,7 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ if (r != 0) return r; - m->scheduled_shutdown_type = a; + m->scheduled_shutdown_action = a; m->shutdown_dry_run = dry_run; m->scheduled_shutdown_timeout = elapse; @@ -2330,12 +2330,12 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd assert(m); assert(message); - cancelled = m->scheduled_shutdown_type - && !IN_SET(m->scheduled_shutdown_type->handle, HANDLE_IGNORE, _HANDLE_ACTION_INVALID); + cancelled = m->scheduled_shutdown_action + && !IN_SET(m->scheduled_shutdown_action->handle, HANDLE_IGNORE, _HANDLE_ACTION_INVALID); if (!cancelled) return sd_bus_reply_method_return(message, "b", false); - a = m->scheduled_shutdown_type; + a = m->scheduled_shutdown_action; if (!a->polkit_action) return sd_bus_error_set(error, SD_BUS_ERROR_AUTH_FAILED, "Unsupported shutdown type"); diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index b21699ea26..1db5050c3b 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -65,7 +65,7 @@ static int warn_wall(Manager *m, usec_t n) { assert(m); - if (!m->enable_wall_messages || !m->scheduled_shutdown_type) + if (!m->enable_wall_messages || !m->scheduled_shutdown_action) return 0; left = m->scheduled_shutdown_timeout > n; @@ -73,7 +73,7 @@ static int warn_wall(Manager *m, usec_t 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(m->scheduled_shutdown_type->handle), + handle_action_to_string(m->scheduled_shutdown_action->handle), left ? "at " : "NOW", left ? FORMAT_TIMESTAMP(m->scheduled_shutdown_timeout) : ""); if (r < 0) { @@ -131,7 +131,7 @@ int manager_setup_wall_message_timer(Manager *m) { /* wall message handling */ - if (!m->scheduled_shutdown_type) + if (!m->scheduled_shutdown_action) return 0; if (elapse > 0 && elapse < n) diff --git a/src/login/logind.h b/src/login/logind.h index 1613daa04e..2136486c60 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -68,17 +68,15 @@ struct Manager { usec_t inhibit_delay_max; usec_t user_stop_delay; - /* If a shutdown/suspend was delayed due to an inhibitor this - contains the action we are supposed to start after the - delay is over */ + /* If a shutdown/suspend was delayed due to an inhibitor this contains the action we are supposed to + * start after the delay is over */ const HandleActionData *delayed_action; - /* If a shutdown/suspend is currently executed, then this is - * the job of it */ + /* If a shutdown/suspend is currently executed, then this is the job of it */ char *action_job; sd_event_source *inhibit_timeout_source; - const HandleActionData *scheduled_shutdown_type; + const HandleActionData *scheduled_shutdown_action; usec_t scheduled_shutdown_timeout; sd_event_source *scheduled_shutdown_timeout_source; uid_t scheduled_shutdown_uid;