b12df0
From 6751217a032dd1a8e8ee324332f29786265f0ebe Mon Sep 17 00:00:00 2001
b12df0
From: Lennart Poettering <lennart@poettering.net>
b12df0
Date: Tue, 2 Feb 2021 15:27:30 +0100
b12df0
Subject: [PATCH] logind: simplify flags handling a bit
b12df0
b12df0
Let's split out the two codepaths a bit, and emphasize which ones it the
b12df0
new-style and which the old-style codepath, and let's clearly convert
b12df0
the params of the old-stye into the new style for further processing, so
b12df0
that the old style path is brief and isolated.
b12df0
b12df0
No change in behaviour.
b12df0
b12df0
Follow-up for: 8885fed4e3a52cf1bf105e42043203c485ed9d92
b12df0
b12df0
(cherry picked from commit d3e99bc0c7f785dcf4e73cfed12f74002e73be5f)
b12df0
b12df0
Related: #1269726
b12df0
---
b12df0
 src/login/logind-dbus.c | 30 ++++++++++++++++++------------
b12df0
 1 file changed, 18 insertions(+), 12 deletions(-)
b12df0
b12df0
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
b12df0
index 0c43fbb3e0..ae9abc9bce 100644
b12df0
--- a/src/login/logind-dbus.c
b12df0
+++ b/src/login/logind-dbus.c
b12df0
@@ -1776,8 +1776,8 @@ static int method_do_shutdown_or_sleep(
b12df0
                 bool with_flags,
b12df0
                 sd_bus_error *error) {
b12df0
 
b12df0
-        int interactive = false, r;
b12df0
-        uint64_t flags = 0;
b12df0
+        uint64_t flags;
b12df0
+        int r;
b12df0
 
b12df0
         assert(m);
b12df0
         assert(message);
b12df0
@@ -1785,19 +1785,25 @@ static int method_do_shutdown_or_sleep(
b12df0
         assert(w >= 0);
b12df0
         assert(w <= _INHIBIT_WHAT_MAX);
b12df0
 
b12df0
-        if (with_flags)
b12df0
+        if (with_flags) {
b12df0
+                /* New style method: with flags parameter (and interactive bool in the bus message header) */
b12df0
                 r = sd_bus_message_read(message, "t", &flags);
b12df0
-        else
b12df0
-                r = sd_bus_message_read(message, "b", &interactive);
b12df0
-
b12df0
-        if (r < 0)
b12df0
-                return r;
b12df0
+                if (r < 0)
b12df0
+                        return r;
b12df0
+                if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
b12df0
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
b12df0
+        } else {
b12df0
+                /* Old style method: no flags parameter, but interactive bool passed as boolean in
b12df0
+                 * payload. Let's convert this argument to the new-style flags parameter for our internal
b12df0
+                 * use. */
b12df0
+                int interactive;
b12df0
 
b12df0
-        if (with_flags && (flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC))
b12df0
-                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
b12df0
-                                         "Invalid flags parameter");
b12df0
+                r = sd_bus_message_read(message, "b", &interactive);
b12df0
+                if (r < 0)
b12df0
+                        return r;
b12df0
 
b12df0
-        SET_FLAG(flags, SD_LOGIND_INTERACTIVE, interactive);
b12df0
+                flags = interactive ? SD_LOGIND_INTERACTIVE : 0;
b12df0
+        }
b12df0
 
b12df0
         /* Don't allow multiple jobs being executed at the same time */
b12df0
         if (m->action_what)