chiark / gitweb /
Prep v239: A few cosmetic upgrades
[elogind.git] / src / login / logind-dbus.c
index 507368604911774a57efae577f27ff79e14c4d4a..5178dd8477f1476f5f0151e8b3568d905df1540c 100644 (file)
@@ -1,9 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2011 Lennart Poettering
-***/
 
 #include <errno.h>
 #include <pwd.h>
@@ -245,9 +240,9 @@ static int property_get_preparing(
         assert(m);
 
         if (streq(property, "PreparingForShutdown"))
-                b = !!(m->action_what & INHIBIT_SHUTDOWN);
+                b = m->action_what & INHIBIT_SHUTDOWN;
         else
-                b = !!(m->action_what & INHIBIT_SLEEP);
+                b = m->action_what & INHIBIT_SLEEP;
 
         return sd_bus_message_append(reply, "b", b);
 }
@@ -1984,6 +1979,9 @@ static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_e
                         m, message,
 #if 0 /// elogind uses HandleAction instead of const char* unti names
                         SPECIAL_HYBRID_SLEEP_TARGET,
+#else
+                        HANDLE_HYBRID_SLEEP,
+#endif // 0
                         INHIBIT_SLEEP,
                         "org.freedesktop.login1.hibernate",
                         "org.freedesktop.login1.hibernate-multiple-sessions",
@@ -1997,9 +1995,10 @@ static int method_suspend_then_hibernate(sd_bus_message *message, void *userdata
 
         return method_do_shutdown_or_sleep(
                         m, message,
+#if 0 /// elogind uses HandleAction instead of const char* unti names
                         SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET,
 #else
-                        HANDLE_HYBRID_SLEEP,
+                        HANDLE_SUSPEND_THEN_HIBERNATE,
 #endif // 0
                         INHIBIT_SLEEP,
                         "org.freedesktop.login1.hibernate",
@@ -2343,11 +2342,11 @@ static int method_can_shutdown_or_sleep(
         if (sleep_verb) {
 #if 0 /// elogind needs to have the manager being passed
                 r = can_sleep(sleep_verb);
-                if (IN_SET(r,  0, -ENOSPC))
-                        return sd_bus_reply_method_return(message, "s", "na");
 #else
                 r = can_sleep(m, sleep_verb);
 #endif // 0
+                if (IN_SET(r,  0, -ENOSPC))
+                        return sd_bus_reply_method_return(message, "s", "na");
                 if (r < 0)
                         return r;
         }
@@ -2368,6 +2367,7 @@ static int method_can_shutdown_or_sleep(
         blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL);
 
         handle = handle_action_from_string(sleep_verb);
+#if 0 /// elogind uses its own variant, which can use the handle directly.
         if (handle >= 0) {
                 const char *target;
 
@@ -2384,7 +2384,12 @@ static int method_can_shutdown_or_sleep(
                                 goto finish;
                         }
                 }
+#else
+                if ( (handle <= HANDLE_IGNORE) || (handle >= _HANDLE_ACTION_MAX) ) {
+                        result = "no";
+                        goto finish;
         }
+#endif // 0
 
         if (multiple_sessions) {
                 r = bus_test_polkit(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, UID_INVALID, &challenge, error);