chiark / gitweb /
logind: add PreparingForShutdown/PreparingForSleep properties
[elogind.git] / src / login / logind-dbus.c
index 6175d57d8c34fc59a22e76d99aa326f528d68696..a2ead8609bd1158e62dd81f88d20e56ec052e296 100644 (file)
         "  <property name=\"HandlePowerKey\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"HandleSleepKey\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"HandleLidSwitch\" type=\"s\" access=\"read\"/>\n" \
+        "  <property name=\"PreparingForShutdown\" type=\"b\" access=\"read\"/>\n" \
+        "  <property name=\"PreparingForSleep\" type=\"b\" access=\"read\"/>\n" \
         " </interface>\n"
 
 #define INTROSPECTION_BEGIN                                             \
@@ -273,6 +275,22 @@ static int bus_manager_append_inhibited(DBusMessageIter *i, const char *property
         return 0;
 }
 
+static int bus_manager_append_preparing(DBusMessageIter *i, const char *property, void *data) {
+        Manager *m = data;
+        dbus_bool_t b;
+
+        assert(i);
+        assert(property);
+
+        if (streq(property, "PreparingForShutdown"))
+                b = !!(m->delayed_what & INHIBIT_SHUTDOWN);
+        else
+                b = !!(m->delayed_what & INHIBIT_SLEEP);
+
+        dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b);
+        return 0;
+}
+
 static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {
         Session *session = NULL;
         User *user = NULL;
@@ -930,27 +948,20 @@ static int have_multiple_sessions(
                 DBusMessage *message,
                 DBusError *error) {
 
-        Session *s;
+        Session *session;
+        Iterator i;
+        unsigned long ul;
 
         assert(m);
 
-        if (hashmap_size(m->sessions) > 1)
-                return true;
-
-        /* Hmm, there's only one session, but let's make sure it
-         * actually belongs to the user who is asking. If not, better
-         * be safe than sorry. */
-
-        s = hashmap_first(m->sessions);
-        if (s) {
-                unsigned long ul;
+        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
+        if (ul == (unsigned long) -1)
+                return -EIO;
 
-                ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
-                if (ul == (unsigned long) -1)
-                        return -EIO;
-
-                return s->user->uid != ul;
-        }
+        /* Check for other users' sessions. Greeter sessions do not count. */
+        HASHMAP_FOREACH(session, m->sessions, i)
+                if (session->class == SESSION_USER && session->user->uid != ul)
+                        return true;
 
         return false;
 }
@@ -1068,8 +1079,10 @@ static int bus_manager_can_shutdown_or_sleep(
                 if (r < 0)
                         return r;
 
-                result = "na";
-                goto finish;
+                if (r == 0) {
+                        result = "na";
+                        goto finish;
+                }
         }
 
         r = have_multiple_sessions(connection, m, message, error);
@@ -1086,11 +1099,11 @@ static int bus_manager_can_shutdown_or_sleep(
 
                 if (r > 0)
                         result = "yes";
-                        else if (challenge)
-                                result = "challenge";
-                        else
-                                result = "no";
-                }
+                else if (challenge)
+                        result = "challenge";
+                else
+                        result = "no";
+        }
 
         if (blocked) {
                 r = verify_polkit(connection, message, action_ignore_inhibit, false, &challenge, error);
@@ -1271,6 +1284,8 @@ static const BusProperty bus_login_manager_properties[] = {
         { "HandlePowerKey",         bus_manager_append_handle_button,   "s",  offsetof(Manager, handle_power_key)    },
         { "HandleSleepKey",         bus_manager_append_handle_button,   "s",  offsetof(Manager, handle_sleep_key)    },
         { "HandleLidSwitch",        bus_manager_append_handle_button,   "s",  offsetof(Manager, handle_lid_switch)   },
+        { "PreparingForShutdown",   bus_manager_append_preparing,       "b",  0 },
+        { "PreparingForSleep",      bus_manager_append_preparing,       "b",  0 },
         { NULL, }
 };