chiark / gitweb /
Prep v239: Fix and add debug messages to method_can_shutdown_or_sleep()
[elogind.git] / src / login / logind-dbus.c
index 63d1313bd5d45846e85df935b718391c5dadb363..9d70928691eda62c0c8f8772964c8c08a59799d4 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);
 }
@@ -1436,8 +1431,7 @@ static int bus_manager_log_shutdown(
         return log_struct(LOG_NOTICE,
                           "MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
                           p,
-                          q,
-                          NULL);
+                          q);
 }
 #endif // 0
 
@@ -1985,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",
@@ -1998,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",
@@ -2344,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;
         }
@@ -2369,7 +2367,9 @@ 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 (handle >= 0) {
+#if 0 /// elogind uses its own variant, which can use the handle directly.
                 const char *target;
 
                 target = manager_target_for_action(handle);
@@ -2386,6 +2386,11 @@ static int method_can_shutdown_or_sleep(
                         }
                 }
         }
+#else
+                log_debug_elogind("CanShutDownOrSleep: %s [%d] %s blocked",
+                                  sleep_verb, handle, blocked ? "is" : "not");
+#endif // 0
+        }
 
         if (multiple_sessions) {
                 r = bus_test_polkit(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, UID_INVALID, &challenge, error);
@@ -2398,6 +2403,8 @@ static int method_can_shutdown_or_sleep(
                         result = "challenge";
                 else
                         result = "no";
+                log_debug_elogind("CanShutDownOrSleep: multiple_sessions: %s = %s",
+                                  action_multiple_sessions, result);
         }
 
         if (blocked) {
@@ -2411,6 +2418,8 @@ static int method_can_shutdown_or_sleep(
                         result = "challenge";
                 else
                         result = "no";
+                log_debug_elogind("CanShutDownOrSleep: blocked          : %s = %s",
+                                  action_ignore_inhibit, result);
         }
 
         if (!multiple_sessions && !blocked) {
@@ -2427,6 +2436,8 @@ static int method_can_shutdown_or_sleep(
                         result = "challenge";
                 else
                         result = "no";
+                log_debug_elogind("CanShutDownOrSleep: regular          : %s = %s",
+                                  action, result);
         }
 
  finish:
@@ -2820,7 +2831,7 @@ const sd_bus_vtable manager_vtable[] = {
         SD_BUS_PROPERTY("ScheduledShutdown", "(st)", property_get_scheduled_shutdown, 0, 0),
         SD_BUS_PROPERTY("Docked", "b", property_get_docked, 0, 0),
         SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(Manager, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
-        SD_BUS_PROPERTY("RuntimeDirectorySize", "t", bus_property_get_size, offsetof(Manager, runtime_dir_size), SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("RuntimeDirectorySize", "t", NULL, offsetof(Manager, runtime_dir_size), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("InhibitorsMax", "t", NULL, offsetof(Manager, inhibitors_max), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("NCurrentInhibitors", "t", property_get_hashmap_size, offsetof(Manager, inhibitors), 0),
         SD_BUS_PROPERTY("SessionsMax", "t", NULL, offsetof(Manager, sessions_max), SD_BUS_VTABLE_PROPERTY_CONST),