]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: define flags enum for manager_is_inhibited() 35253/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 20 Nov 2024 12:15:06 +0000 (13:15 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 11 Dec 2024 10:20:35 +0000 (10:20 +0000)
The most common case of block=true, ignore_inactive=false is mapped to flags=0.

For https://github.com/systemd/systemd/issues/34091.

src/login/logind-action.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-inhibit.h

index 8b3c345e7ab4d584e8ee6e7908cef794d734dcd6..712438f4b1e7bd2ae1cf61dd80e426d8dc3c9baa 100644 (file)
@@ -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));
index e86f11424461e22e9da11beffe9dd42b2b61eb50..bcb82582e64e5e7e4eb166f31e0fe702963cd0f5 100644 (file)
@@ -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;
index e14b681e9b45c0a1b6f57e673679b54ad68a5345..78b4783faa9fbe5c8257718cdc637fd002bde5dd 100644 (file)
@@ -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;
index e4d2e7a73f8cd71a0e1a042b07f11ec8264fc4de..ec870d10016e3b67d5cbbb7604e505097116619c 100644 (file)
@@ -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 &&
index 6b4d7a0689ddc739a0915a4070f680db58ab493e..ae91e2d402efb09549b623a8ae8a6f09fa782c7b 100644 (file)
@@ -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);