chiark / gitweb /
logind: unify all session lock loop
authorLennart Poettering <lennart@poettering.net>
Sun, 28 Oct 2012 16:25:23 +0000 (17:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Oct 2012 02:40:42 +0000 (03:40 +0100)
src/login/logind-button.c
src/login/logind-dbus.c
src/login/logind-session-dbus.c
src/login/logind-session.h

index 778852698f2618e314a4f18b27e05515a72a5f93..8bbd731ae40569d727b480474734c0eb12c11aa0 100644 (file)
@@ -150,18 +150,6 @@ fail:
         return r;
 }
 
-static int lock_sessions(Manager *m) {
-        Iterator i;
-        Session *session;
-
-        log_info("Locking sessions...");
-
-        HASHMAP_FOREACH(session, m->sessions, i)
-                session_send_lock(session, true);
-
-        return 1;
-}
-
 static int button_handle(
                 Button *b,
                 InhibitWhat inhibit_key,
@@ -208,8 +196,11 @@ static int button_handle(
         }
 
         /* Locking is handled differently from the rest. */
-        if (handle == HANDLE_LOCK)
-                return lock_sessions(b->manager);
+        if (handle == HANDLE_LOCK) {
+                log_info("Locking sessions...");
+                session_send_lock_all(b->manager, true);
+                return 1;
+        }
 
         inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
 
index 3bcb91bf13fea32c47f8bf98a65999812074fe81..4326e5b87cf3c339638641629a7148a60ef1c605 100644 (file)
@@ -1812,7 +1812,7 @@ static DBusHandlerResult manager_message_handler(
 
                 session = hashmap_get(m->sessions, name);
                 if (!session)
-                        return bus_send_error_reply(connection, message, &error, -ENOENT);
+                        return bus_send_error_reply(connection, message, NULL, -ENOENT);
 
                 if (session_send_lock(session, streq(dbus_message_get_member(message), "LockSession")) < 0)
                         goto oom;
@@ -1822,12 +1822,9 @@ static DBusHandlerResult manager_message_handler(
                         goto oom;
 
         } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions")) {
-                Session *session;
-                Iterator i;
-
-                HASHMAP_FOREACH(session, m->sessions, i)
-                        if (session_send_lock(session, true) < 0)
-                                goto oom;
+                r = session_send_lock_all(m, true);
+                if (r < 0)
+                        bus_send_error_reply(connection, message, NULL, r);
 
                 reply = dbus_message_new_method_return(message);
                 if (!reply)
index 26c853e4ee321cef48ccabd808808a2efa856ad9..ef73cd434abbdd1e5e31fcc69ffe1516aa938b51 100644 (file)
@@ -570,3 +570,21 @@ int session_send_lock(Session *s, bool lock) {
 
         return 0;
 }
+
+int session_send_lock_all(Manager *m, bool lock) {
+        Session *session;
+        Iterator i;
+        int r = 0;
+
+        assert(m);
+
+        HASHMAP_FOREACH(session, m->sessions, i) {
+                int k;
+
+                k = session_send_lock(session, lock);
+                if (k < 0)
+                        r = k;
+        }
+
+        return r;
+}
index bfa4abd690b0a20383ff2fde6e5a7ac361d004e1..7598afa61880437880ef02a6dbcb6e3a60f70e1d 100644 (file)
@@ -132,6 +132,7 @@ extern const DBusObjectPathVTable bus_session_vtable;
 int session_send_signal(Session *s, bool new_session);
 int session_send_changed(Session *s, const char *properties);
 int session_send_lock(Session *s, bool lock);
+int session_send_lock_all(Manager *m, bool lock);
 
 const char* session_state_to_string(SessionState t);
 SessionState session_state_from_string(const char *s);