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