summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-02 15:27:30 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-03 17:22:59 +0900
commit3ecafb1f5be6cdd43438231e7eddb1b67e5d02f9 (patch)
treee48b4025429bb02e1004339576f625657579fa26
parent89d2da287b945206aba9865ca3eb78a07d22c421 (diff)
downloadsystemd-3ecafb1f5be6cdd43438231e7eddb1b67e5d02f9.tar.gz
logind: simplify flags handling a bit
Let's split out the two codepaths a bit, and emphasize which ones it the new-style and which the old-style codepath, and let's clearly convert the params of the old-stye into the new style for further processing, so that the old style path is brief and isolated. No change in behaviour. Follow-up for: 8885fed4e3a52cf1bf105e42043203c485ed9d92
-rw-r--r--src/login/logind-dbus.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 8f27fe7ee9..7e55173e27 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1871,8 +1871,8 @@ static int method_do_shutdown_or_sleep(
bool with_flags,
sd_bus_error *error) {
- int interactive = false, r;
- uint64_t flags = 0;
+ uint64_t flags;
+ int r;
assert(m);
assert(message);
@@ -1880,19 +1880,25 @@ static int method_do_shutdown_or_sleep(
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
- if (with_flags)
+ if (with_flags) {
+ /* New style method: with flags parameter (and interactive bool in the bus message header) */
r = sd_bus_message_read(message, "t", &flags);
- else
- r = sd_bus_message_read(message, "b", &interactive);
-
- if (r < 0)
- return r;
+ if (r < 0)
+ return r;
+ if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
+ } else {
+ /* Old style method: no flags parameter, but interactive bool passed as boolean in
+ * payload. Let's convert this argument to the new-style flags parameter for our internal
+ * use. */
+ int interactive;
- if (with_flags && (flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
- "Invalid flags parameter");
+ r = sd_bus_message_read(message, "b", &interactive);
+ if (r < 0)
+ return r;
- SET_FLAG(flags, SD_LOGIND_INTERACTIVE, interactive);
+ flags = interactive ? SD_LOGIND_INTERACTIVE : 0;
+ }
/* Don't allow multiple jobs being executed at the same time */
if (m->action_what > 0)