]> err.no Git - systemd/commitdiff
logind: send out PropertyChanged signals where appropriate
authorLennart Poettering <lennart@poettering.net>
Tue, 21 Jun 2011 19:46:13 +0000 (21:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Jun 2011 19:46:13 +0000 (21:46 +0200)
12 files changed:
src/logind-dbus.c
src/logind-seat-dbus.c
src/logind-seat.c
src/logind-seat.h
src/logind-session-dbus.c
src/logind-session.c
src/logind-session.h
src/logind-user-dbus.c
src/logind-user.c
src/logind-user.h
src/logind.c
src/logind.h

index f9ee7e5553a3090a1db537d171a3a4984f5eb227..f73307f806c8abc12cf50da64fe9f2871bd4de77 100644 (file)
@@ -604,3 +604,25 @@ oom:
 const DBusObjectPathVTable bus_manager_vtable = {
         .message_function = manager_message_handler
 };
+
+int manager_send_changed(Manager *manager, const char *properties) {
+        DBusMessage *m;
+        int r = -ENOMEM;
+
+        assert(manager);
+
+        m = bus_properties_changed_new("/org/freedesktop/login1", "org.freedesktop.login1.Manager", properties);
+        if (!m)
+                goto finish;
+
+        if (!dbus_connection_send(manager->bus, m, NULL))
+                goto finish;
+
+        r = 0;
+
+finish:
+        if (m)
+                dbus_message_unref(m);
+
+        return r;
+}
index 33eafe5ee5dd2a0e71398fa0f26d6063bf23a66d..1895fe6cc36c2e4531a6846d014ec46e2654092b 100644 (file)
@@ -370,3 +370,31 @@ finish:
 
         return r;
 }
+
+int seat_send_changed(Seat *s, const char *properties) {
+        DBusMessage *m;
+        int r = -ENOMEM;
+        char *p = NULL;
+
+        assert(s);
+
+        p = seat_bus_path(s);
+        if (!p)
+                return -ENOMEM;
+
+        m = bus_properties_changed_new(p, "org.freedesktop.login1.Seat", properties);
+        if (!m)
+                goto finish;
+
+        if (!dbus_connection_send(s->manager->bus, m, NULL))
+                goto finish;
+
+        r = 0;
+
+finish:
+        if (m)
+                dbus_message_unref(m);
+        free(p);
+
+        return r;
+}
index 95c66dd7125649cff8d54efbe6c475e65109bc9f..09356b6b09488fba05f903ba02d0db118532873d 100644 (file)
@@ -226,8 +226,33 @@ int seat_apply_acls(Seat *s, Session *old_active) {
         return r;
 }
 
+int seat_set_active(Seat *s, Session *session) {
+        Session *old_active;
+
+        assert(s);
+        assert(session);
+        assert(session->seat == s);
+
+        if (session == s->active)
+                return 0;
+
+        old_active = s->active;
+        s->active = session;
+
+        seat_apply_acls(s, old_active);
+
+        if (session && session->started)
+                session_send_changed(session, "Active\0");
+
+        if (!session || session->started)
+                seat_send_changed(s, "ActiveSession\0");
+
+        return 0;
+}
+
 int seat_active_vt_changed(Seat *s, int vtnr) {
-        Session *i, *new_active = NULL, *old_active;
+        Session *i, *new_active = NULL;
+        int r;
 
         assert(s);
         assert(vtnr >= 1);
@@ -243,16 +268,10 @@ int seat_active_vt_changed(Seat *s, int vtnr) {
                         break;
                 }
 
-        if (new_active == s->active)
-                return 0;
-
-        old_active = s->active;
-        s->active = new_active;
-
-        seat_apply_acls(s, old_active);
+        r = seat_set_active(s, new_active);
         manager_spawn_autovt(s->manager, vtnr);
 
-        return 0;
+        return r;
 }
 
 int seat_read_active_vt(Seat *s) {
@@ -361,17 +380,19 @@ int seat_attach_session(Seat *s, Session *session) {
         assert(session);
         assert(!session->seat);
 
-        if (!seat_is_vtconsole(s)) {
-                if (s->sessions)
-                        return -EEXIST;
-
-                assert(!s->active);
-                s->active = session;
-        }
+        if (!seat_is_vtconsole(s) && s->sessions)
+                return -EEXIST;
 
         session->seat = s;
         LIST_PREPEND(Session, sessions_by_seat, s->sessions, session);
 
+        seat_send_changed(s, "Sessions\0");
+
+        if (!seat_is_vtconsole(s)) {
+                assert(!s->active);
+                seat_set_active(s, session);
+        }
+
         return 0;
 }
 
index a7cd6c7e47c194f48886a3807c04294f86a4002b..275939e176cb87169fdf0e440867fdc3564fc917 100644 (file)
@@ -54,6 +54,7 @@ int seat_save(Seat *s);
 int seat_load(Seat *s);
 
 int seat_apply_acls(Seat *s, Session *old_active);
+int seat_set_active(Seat *s, Session *session);
 int seat_active_vt_changed(Seat *s, int vtnr);
 int seat_read_active_vt(Seat *s);
 
@@ -75,5 +76,6 @@ char *seat_bus_path(Seat *s);
 extern const DBusObjectPathVTable bus_seat_vtable;
 
 int seat_send_signal(Seat *s, bool new_seat);
+int seat_send_changed(Seat *s, const char *properties);
 
 #endif
index edc96dd6443a91b298a3b729d10ff8b4ca535973..0ce880c590b80f9323a404d33fa753af762b04b7 100644 (file)
@@ -419,3 +419,31 @@ finish:
 
         return r;
 }
+
+int session_send_changed(Session *s, const char *properties) {
+        DBusMessage *m;
+        int r = -ENOMEM;
+        char *p = NULL;
+
+        assert(s);
+
+        p = session_bus_path(s);
+        if (!p)
+                return -ENOMEM;
+
+        m = bus_properties_changed_new(p, "org.freedesktop.login1.Session", properties);
+        if (!m)
+                goto finish;
+
+        if (!dbus_connection_send(s->manager->bus, m, NULL))
+                goto finish;
+
+        r = 0;
+
+finish:
+        if (m)
+                dbus_message_unref(m);
+        free(p);
+
+        return r;
+}
index 26f857dc3956e78a33815de6a2abe80e74b73796..5ba6b21eeb8c56f799f7a8da1efb3fc70fbcea93 100644 (file)
@@ -76,8 +76,12 @@ void session_free(Session *s) {
                         s->user->display = NULL;
         }
 
-        if (s->seat)
+        if (s->seat) {
+                if (s->seat->active == s)
+                        s->seat->active = NULL;
+
                 LIST_REMOVE(Session, sessions_by_seat, s->seat->sessions, s);
+        }
 
         free(s->cgroup_path);
         strv_free(s->controllers);
@@ -229,7 +233,7 @@ int session_load(Session *s) {
                         s->kill_processes = k;
         }
 
-        if (seat) {
+        if (seat && !s->seat) {
                 Seat *o;
 
                 o = hashmap_get(s->manager->seats, seat);
@@ -430,6 +434,9 @@ int session_start(Session *s) {
         assert(s);
         assert(s->user);
 
+        if (s->started)
+                return 0;
+
         /* Create cgroup */
         r = session_create_cgroup(s);
         if (r < 0)
@@ -443,8 +450,19 @@ int session_start(Session *s) {
 
         dual_timestamp_get(&s->timestamp);
 
+        s->started = true;
+
         session_send_signal(s, true);
 
+        if (s->seat) {
+                if (s->seat->active == s)
+                        seat_send_changed(s->seat, "Sessions\0ActiveSession\0");
+                else
+                        seat_send_changed(s->seat, "Sessions\0");
+        }
+
+        user_send_changed(s->user, "Sessions\0");
+
         return 0;
 }
 
@@ -521,7 +539,8 @@ int session_stop(Session *s) {
 
         assert(s);
 
-        session_send_signal(s, false);
+        if (!s->started)
+                return 0;
 
         /* Kill cgroup */
         k = session_kill_cgroup(s);
@@ -534,6 +553,19 @@ int session_stop(Session *s) {
         unlink(s->state_file);
         session_add_to_gc_queue(s);
 
+        session_send_signal(s, false);
+
+        if (s->seat) {
+                if (s->seat->active == s)
+                        seat_set_active(s->seat, NULL);
+
+                seat_send_changed(s->seat, "Sessions\0");
+        }
+
+        user_send_changed(s->user, "Sessions\0");
+
+        s->started = false;
+
         return r;
 }
 
@@ -607,6 +639,27 @@ void session_set_idle_hint(Session *s, bool b) {
 
         s->idle_hint = b;
         dual_timestamp_get(&s->idle_hint_timestamp);
+
+        session_send_changed(s,
+                             "IdleHint\0"
+                             "IdleSinceHint\0"
+                             "IdleSinceHintMonotonic\0");
+
+        if (s->seat)
+                seat_send_changed(s->seat,
+                                  "IdleHint\0"
+                                  "IdleSinceHint\0"
+                                  "IdleSinceHintMonotonic\0");
+
+        user_send_changed(s->user,
+                          "IdleHint\0"
+                          "IdleSinceHint\0"
+                          "IdleSinceHintMonotonic\0");
+
+        manager_send_changed(s->manager,
+                             "IdleHint\0"
+                             "IdleSinceHint\0"
+                             "IdleSinceHintMonotonic\0");
 }
 
 int session_check_gc(Session *s) {
index a30c3e727ea9c71c3a16456682f48b00dd441601..d2f25523eccda8c15bffa911ee2c148c883627a3 100644 (file)
@@ -72,6 +72,7 @@ struct Session {
 
         bool kill_processes;
         bool in_gc_queue:1;
+        bool started:1;
 
         LIST_FIELDS(Session, sessions_by_user);
         LIST_FIELDS(Session, sessions_by_seat);
@@ -97,6 +98,7 @@ char *session_bus_path(Session *s);
 extern const DBusObjectPathVTable bus_session_vtable;
 
 int session_send_signal(Session *s, bool new_session);
+int session_send_changed(Session *s, const char *properties);
 
 const char* session_type_to_string(SessionType t);
 SessionType session_type_from_string(const char *s);
index c8d47de0e7358ea9d0b058c0150038acac4fd488..623f2c9c24a044a7a659c5154c51643b3569af25 100644 (file)
@@ -353,3 +353,31 @@ finish:
 
         return r;
 }
+
+int user_send_changed(User *u, const char *properties) {
+        DBusMessage *m;
+        int r = -ENOMEM;
+        char *p = NULL;
+
+        assert(u);
+
+        p = user_bus_path(u);
+        if (!p)
+                return -ENOMEM;
+
+        m = bus_properties_changed_new(p, "org.freedesktop.login1.User", properties);
+        if (!m)
+                goto finish;
+
+        if (!dbus_connection_send(u->manager->bus, m, NULL))
+                goto finish;
+
+        r = 0;
+
+finish:
+        if (m)
+                dbus_message_unref(m);
+        free(p);
+
+        return r;
+}
index 70d6a9a5242a22c1e033a793a69ce60e76989a82..cb3e44197fc6d6b1de3c24d1991f875c93b28b9b 100644 (file)
@@ -260,6 +260,9 @@ int user_start(User *u) {
 
         assert(u);
 
+        if (u->started)
+                return 0;
+
         /* Make XDG_RUNTIME_DIR */
         r = user_mkdir_runtime_path(u);
         if (r < 0)
@@ -280,6 +283,8 @@ int user_start(User *u) {
 
         dual_timestamp_get(&u->timestamp);
 
+        u->started = true;
+
         user_send_signal(u, true);
 
         return 0;
@@ -361,6 +366,9 @@ int user_stop(User *u) {
         int r = 0, k;
         assert(u);
 
+        if (!u->started)
+                return 0;
+
         LIST_FOREACH(sessions_by_user, s, u->sessions) {
                 k = session_stop(s);
                 if (k < 0)
@@ -387,6 +395,8 @@ int user_stop(User *u) {
         unlink(u->state_file);
         user_add_to_gc_queue(u);
 
+        u->started = false;
+
         return r;
 }
 
index c6f14011099c8db2c7361633421ea128f97d2547..dd0dcad9cfa65bec5d3fd69b270482b068a95552 100644 (file)
@@ -55,6 +55,7 @@ struct User {
         dual_timestamp timestamp;
 
         bool in_gc_queue:1;
+        bool started:1;
 
         LIST_HEAD(Session, sessions);
         LIST_FIELDS(User, gc_queue);
@@ -76,6 +77,7 @@ char *user_bus_path(User *s);
 extern const DBusObjectPathVTable bus_user_vtable;
 
 int user_send_signal(User *u, bool new_user);
+int user_send_changed(User *u, const char *properties);
 
 const char* user_state_to_string(UserState s);
 UserState user_state_from_string(const char *s);
index d72a5bfa8b11e77b0cfb83ae8a2edbaaa63f2211..cdb4da7f25813f3c8994f77bdae02c21b4bf87cf 100644 (file)
@@ -890,7 +890,6 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
         return idle_hint;
 }
 
-
 int manager_startup(Manager *m) {
         int r;
         Seat *seat;
index e18a357c9a633091a61c7aacd01f08562b0ba7c0..1b7a2b2398d76a80df06fb9957d36c95cd1f93d1 100644 (file)
@@ -114,4 +114,6 @@ bool x11_display_is_local(const char *display);
 
 extern const DBusObjectPathVTable bus_manager_vtable;
 
+int manager_send_changed(Manager *manager, const char *properties);
+
 #endif