]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: drop one duplicate param in manager_is_inhibited()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 20 Nov 2024 08:38:52 +0000 (09:38 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 11 Dec 2024 10:20:35 +0000 (10:20 +0000)
In the review in https://github.com/systemd/systemd/pull/30307#pullrequestreview-2255002732
removal of the excessive boolean parameters was requested. We don't need
a separate boolean param here, since we always pass true with a uid and
false otherwise.

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 db9a0e1bbae3313dba50465a8b2884c2f7ea9cdc..8b3c345e7ab4d584e8ee6e7908cef794d734dcd6 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, false, 0, &offending)) {
+            manager_is_inhibited(m, inhibit_operation, /* block= */ true, NULL, false, 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, false, 0, NULL)) {
+                if (manager_is_inhibited(m, inhibit_key, /* block= */ true, NULL, true, UID_INVALID, NULL)) {
                         log_debug("Refusing %s operation, %s is inhibited.",
                                   handle_action_to_string(handle),
                                   inhibit_what_to_string(inhibit_key));
index fad276f195e5c120f32337c42f4c60697b12a48b..e86f11424461e22e9da11beffe9dd42b2b61eb50 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, false, 0, NULL);
+        idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, /* block= */ true, t, false, UID_INVALID, NULL);
 
         HASHMAP_FOREACH(s, m->sessions) {
                 dual_timestamp k;
index 80a2470a71f747d8c24d7a19dc7e9d4ef0ce9533..e14b681e9b45c0a1b6f57e673679b54ad68a5345 100644 (file)
@@ -1931,7 +1931,7 @@ 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, false, 0, &offending)) {
+        if (manager_is_inhibited(manager, manager->delayed_action->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, &offending)) {
                 _cleanup_free_ char *comm = NULL, *u = NULL;
 
                 if (!timeout)
@@ -2033,7 +2033,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, false, 0, NULL);
+                manager_is_inhibited(m, a->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, NULL);
 
         if (delayed)
                 /* Shutdown is delayed, keep in mind what we
@@ -2077,7 +2077,7 @@ static int verify_shutdown_creds(
                 return r;
 
         multiple_sessions = r > 0;
-        blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, true, uid, &offending);
+        blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, &offending);
         interactive = flags & SD_LOGIND_INTERACTIVE;
 
         if (multiple_sessions) {
@@ -2820,7 +2820,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, true, uid, NULL);
+        blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, NULL);
 
         if (check_unit_state && a->target) {
                 _cleanup_free_ char *load_state = NULL;
index 887bfb7eaf01335089fec7e87a9eafabf874aad5..e4d2e7a73f8cd71a0e1a042b07f11ec8264fc4de 100644 (file)
@@ -402,8 +402,7 @@ bool manager_is_inhibited(
                 bool block,
                 dual_timestamp *since,
                 bool ignore_inactive,
-                bool ignore_uid,
-                uid_t uid,
+                uid_t uid_to_ignore,
                 Inhibitor **ret_offending) {
 
         Inhibitor *i, *offending = NULL;
@@ -428,11 +427,12 @@ bool manager_is_inhibited(
                 if (ignore_inactive && pidref_is_active_session(m, &i->pid) <= 0)
                         continue;
 
-                if (i->mode == INHIBIT_BLOCK_WEAK && ignore_uid && i->uid == uid)
+                if (i->mode == INHIBIT_BLOCK_WEAK &&
+                    uid_is_valid(uid_to_ignore) &&
+                    uid_to_ignore == i->uid)
                         continue;
 
-                if (!inhibited ||
-                    i->since.monotonic < ts.monotonic)
+                if (!inhibited || i->since.monotonic < ts.monotonic)
                         ts = i->since;
 
                 inhibited = true;
index 16abd6958cc7da24a76180919d0aa5f767785365..6b4d7a0689ddc739a0915a4070f680db58ab493e 100644 (file)
@@ -67,7 +67,14 @@ int inhibitor_create_fifo(Inhibitor *i);
 bool inhibitor_is_orphan(Inhibitor *i);
 
 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode);
-bool manager_is_inhibited(Manager *m, InhibitWhat w, bool block, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
+bool manager_is_inhibited(
+                Manager *m,
+                InhibitWhat w,
+                bool block,
+                dual_timestamp *since,
+                bool ignore_inactive,
+                uid_t uid_to_ignore,
+                Inhibitor **ret_offending);
 
 static inline bool inhibit_what_is_valid(InhibitWhat w) {
         return w > 0 && w < _INHIBIT_WHAT_MAX;