From: Zbigniew Jędrzejewski-Szmek Date: Wed, 20 Nov 2024 12:15:06 +0000 (+0100) Subject: logind: define flags enum for manager_is_inhibited() X-Git-Tag: v258-rc1~1916^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c1622aa5afc1d44ca9569000fb57240518031ce;p=thirdparty%2Fsystemd.git logind: define flags enum for manager_is_inhibited() The most common case of block=true, ignore_inactive=false is mapped to flags=0. For https://github.com/systemd/systemd/issues/34091. --- diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 8b3c345e7ab..712438f4b1e 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -234,7 +234,7 @@ static int handle_action_execute( /* If the actual operation is inhibited, warn and fail */ if (inhibit_what_is_valid(inhibit_operation) && !ignore_inhibited && - manager_is_inhibited(m, inhibit_operation, /* block= */ true, NULL, false, UID_INVALID, &offending)) { + manager_is_inhibited(m, inhibit_operation, NULL, /* flags= */ 0, UID_INVALID, &offending)) { _cleanup_free_ char *comm = NULL, *u = NULL; (void) pidref_get_comm(&offending->pid, &comm); @@ -372,7 +372,7 @@ int manager_handle_action( /* If the key handling is inhibited, don't do anything */ if (inhibit_key > 0) { - if (manager_is_inhibited(m, inhibit_key, /* block= */ true, NULL, true, UID_INVALID, NULL)) { + if (manager_is_inhibited(m, inhibit_key, NULL, MANAGER_IS_INHIBITED_IGNORE_INACTIVE, UID_INVALID, NULL)) { log_debug("Refusing %s operation, %s is inhibited.", handle_action_to_string(handle), inhibit_what_to_string(inhibit_key)); diff --git a/src/login/logind-core.c b/src/login/logind-core.c index e86f1142446..bcb82582e64 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -411,7 +411,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) { assert(m); - idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, /* block= */ true, t, false, UID_INVALID, NULL); + idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t, /* flags= */ 0, UID_INVALID, NULL); HASHMAP_FOREACH(s, m->sessions) { dual_timestamp k; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index e14b681e9b4..78b4783faa9 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1931,7 +1931,12 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) { if (!manager->delayed_action || manager->action_job) return 0; - if (manager_is_inhibited(manager, manager->delayed_action->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, &offending)) { + if (manager_is_inhibited(manager, + manager->delayed_action->inhibit_what, + NULL, + MANAGER_IS_INHIBITED_CHECK_DELAY, + UID_INVALID, + &offending)) { _cleanup_free_ char *comm = NULL, *u = NULL; if (!timeout) @@ -2033,7 +2038,7 @@ int bus_manager_shutdown_or_sleep_now_or_later( delayed = m->inhibit_delay_max > 0 && - manager_is_inhibited(m, a->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, NULL); + manager_is_inhibited(m, a->inhibit_what, NULL, MANAGER_IS_INHIBITED_CHECK_DELAY, UID_INVALID, NULL); if (delayed) /* Shutdown is delayed, keep in mind what we @@ -2077,7 +2082,7 @@ static int verify_shutdown_creds( return r; multiple_sessions = r > 0; - blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, &offending); + blocked = manager_is_inhibited(m, a->inhibit_what, NULL, /* flags= */ 0, uid, &offending); interactive = flags & SD_LOGIND_INTERACTIVE; if (multiple_sessions) { @@ -2820,7 +2825,7 @@ static int method_can_shutdown_or_sleep( return r; multiple_sessions = r > 0; - blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, NULL); + blocked = manager_is_inhibited(m, a->inhibit_what, NULL, /* flags= */ 0, uid, NULL); if (check_unit_state && a->target) { _cleanup_free_ char *load_state = NULL; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index e4d2e7a73f8..ec870d10016 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -399,9 +399,8 @@ static int pidref_is_active_session(Manager *m, const PidRef *pid) { bool manager_is_inhibited( Manager *m, InhibitWhat w, - bool block, dual_timestamp *since, - bool ignore_inactive, + ManagerIsInhibitedFlags flags, uid_t uid_to_ignore, Inhibitor **ret_offending) { @@ -420,11 +419,11 @@ bool manager_is_inhibited( if (!(i->what & w)) continue; - if ((block && !IN_SET(i->mode, INHIBIT_BLOCK, INHIBIT_BLOCK_WEAK)) || - (!block && i->mode != INHIBIT_DELAY)) + if ((flags & MANAGER_IS_INHIBITED_CHECK_DELAY) != (i->mode == INHIBIT_DELAY)) continue; - if (ignore_inactive && pidref_is_active_session(m, &i->pid) <= 0) + if ((flags & MANAGER_IS_INHIBITED_IGNORE_INACTIVE) && + pidref_is_active_session(m, &i->pid) <= 0) continue; if (i->mode == INHIBIT_BLOCK_WEAK && diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 6b4d7a0689d..ae91e2d402e 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -67,12 +67,18 @@ int inhibitor_create_fifo(Inhibitor *i); bool inhibitor_is_orphan(Inhibitor *i); InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode); + +typedef enum ManagerIsInhibitedFlags { + MANAGER_IS_INHIBITED_CHECK_DELAY = 1 << 0, /* When set, we only check delay inhibitors. + * Otherwise, we only check block inhibitors. */ + MANAGER_IS_INHIBITED_IGNORE_INACTIVE = 1 << 1, /* When set, ignore inactive sessions. */ +} ManagerIsInhibitedFlags; + bool manager_is_inhibited( Manager *m, InhibitWhat w, - bool block, dual_timestamp *since, - bool ignore_inactive, + ManagerIsInhibitedFlags flags, uid_t uid_to_ignore, Inhibitor **ret_offending);