summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-06-21 20:43:34 +0200
committerLennart Poettering <lennart@poettering.net>2011-06-21 20:43:34 +0200
commitda11939561b1e6eeb1131b68dbf43042fd633a05 (patch)
tree56b654d78e646a0de6a0db4656da9b758e49258c /src
parente1c9c2d53606f987110b4215cf08c236af637ff1 (diff)
logind: send dbus signals when sessions/users/seats come and go
Diffstat (limited to 'src')
-rw-r--r--src/logind-seat-dbus.c37
-rw-r--r--src/logind-seat.c4
-rw-r--r--src/logind-seat.h2
-rw-r--r--src/logind-session-dbus.c37
-rw-r--r--src/logind-session.c4
-rw-r--r--src/logind-session.h2
-rw-r--r--src/logind-user-dbus.c40
-rw-r--r--src/logind-user.c4
-rw-r--r--src/logind-user.h2
9 files changed, 132 insertions, 0 deletions
diff --git a/src/logind-seat-dbus.c b/src/logind-seat-dbus.c
index 32171ce401..33eafe5ee5 100644
--- a/src/logind-seat-dbus.c
+++ b/src/logind-seat-dbus.c
@@ -333,3 +333,40 @@ char *seat_bus_path(Seat *s) {
return r;
}
+
+int seat_send_signal(Seat *s, bool new_seat) {
+ DBusMessage *m;
+ int r = -ENOMEM;
+ char *p = NULL;
+
+ assert(s);
+
+ m = dbus_message_new_signal("/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ new_seat ? "SeatNew" : "SeatRemoved");
+
+ if (!m)
+ return -ENOMEM;
+
+ p = seat_bus_path(s);
+ if (!p)
+ goto finish;
+
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_STRING, &s->id,
+ DBUS_TYPE_OBJECT_PATH, &p,
+ DBUS_TYPE_INVALID))
+ goto finish;
+
+ if (!dbus_connection_send(s->manager->bus, m, NULL))
+ goto finish;
+
+ r = 0;
+
+finish:
+ dbus_message_unref(m);
+ free(p);
+
+ return r;
+}
diff --git a/src/logind-seat.c b/src/logind-seat.c
index 751f59a48d..95c66dd712 100644
--- a/src/logind-seat.c
+++ b/src/logind-seat.c
@@ -314,6 +314,8 @@ int seat_start(Seat *s) {
s->started = true;
+ seat_send_signal(s, true);
+
return 0;
}
@@ -327,6 +329,8 @@ int seat_stop(Seat *s) {
log_info("Removed seat %s.", s->id);
+ seat_send_signal(s, false);
+
seat_stop_sessions(s);
unlink(s->state_file);
diff --git a/src/logind-seat.h b/src/logind-seat.h
index dfbb2a2a0a..a7cd6c7e47 100644
--- a/src/logind-seat.h
+++ b/src/logind-seat.h
@@ -74,4 +74,6 @@ char *seat_bus_path(Seat *s);
extern const DBusObjectPathVTable bus_seat_vtable;
+int seat_send_signal(Seat *s, bool new_seat);
+
#endif
diff --git a/src/logind-session-dbus.c b/src/logind-session-dbus.c
index 6bded6a454..edc96dd644 100644
--- a/src/logind-session-dbus.c
+++ b/src/logind-session-dbus.c
@@ -382,3 +382,40 @@ char *session_bus_path(Session *s) {
return r;
}
+
+int session_send_signal(Session *s, bool new_session) {
+ DBusMessage *m;
+ int r = -ENOMEM;
+ char *p = NULL;
+
+ assert(s);
+
+ m = dbus_message_new_signal("/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ new_session ? "SessionNew" : "SessionRemoved");
+
+ if (!m)
+ return -ENOMEM;
+
+ p = session_bus_path(s);
+ if (!p)
+ goto finish;
+
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_STRING, &s->id,
+ DBUS_TYPE_OBJECT_PATH, &p,
+ DBUS_TYPE_INVALID))
+ goto finish;
+
+ if (!dbus_connection_send(s->manager->bus, m, NULL))
+ goto finish;
+
+ r = 0;
+
+finish:
+ dbus_message_unref(m);
+ free(p);
+
+ return r;
+}
diff --git a/src/logind-session.c b/src/logind-session.c
index 0d34037b5d..26f857dc39 100644
--- a/src/logind-session.c
+++ b/src/logind-session.c
@@ -443,6 +443,8 @@ int session_start(Session *s) {
dual_timestamp_get(&s->timestamp);
+ session_send_signal(s, true);
+
return 0;
}
@@ -519,6 +521,8 @@ int session_stop(Session *s) {
assert(s);
+ session_send_signal(s, false);
+
/* Kill cgroup */
k = session_kill_cgroup(s);
if (k < 0)
diff --git a/src/logind-session.h b/src/logind-session.h
index 9f58165da9..a30c3e727e 100644
--- a/src/logind-session.h
+++ b/src/logind-session.h
@@ -96,6 +96,8 @@ char *session_bus_path(Session *s);
extern const DBusObjectPathVTable bus_session_vtable;
+int session_send_signal(Session *s, bool new_session);
+
const char* session_type_to_string(SessionType t);
SessionType session_type_from_string(const char *s);
diff --git a/src/logind-user-dbus.c b/src/logind-user-dbus.c
index 3be2c05d26..c8d47de0e7 100644
--- a/src/logind-user-dbus.c
+++ b/src/logind-user-dbus.c
@@ -313,3 +313,43 @@ char *user_bus_path(User *u) {
return s;
}
+
+int user_send_signal(User *u, bool new_user) {
+ DBusMessage *m;
+ int r = -ENOMEM;
+ char *p = NULL;
+ uint32_t uid;
+
+ assert(u);
+
+ m = dbus_message_new_signal("/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ new_user ? "UserNew" : "UserRemoved");
+
+ if (!m)
+ return -ENOMEM;
+
+ p = user_bus_path(u);
+ if (!p)
+ goto finish;
+
+ uid = u->uid;
+
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_OBJECT_PATH, &p,
+ DBUS_TYPE_INVALID))
+ goto finish;
+
+ if (!dbus_connection_send(u->manager->bus, m, NULL))
+ goto finish;
+
+ r = 0;
+
+finish:
+ dbus_message_unref(m);
+ free(p);
+
+ return r;
+}
diff --git a/src/logind-user.c b/src/logind-user.c
index 206064f103..70d6a9a524 100644
--- a/src/logind-user.c
+++ b/src/logind-user.c
@@ -280,6 +280,8 @@ int user_start(User *u) {
dual_timestamp_get(&u->timestamp);
+ user_send_signal(u, true);
+
return 0;
}
@@ -365,6 +367,8 @@ int user_stop(User *u) {
r = k;
}
+ user_send_signal(u, false);
+
/* Kill systemd */
k = user_stop_service(u);
if (k < 0)
diff --git a/src/logind-user.h b/src/logind-user.h
index c891119e27..c6f1401109 100644
--- a/src/logind-user.h
+++ b/src/logind-user.h
@@ -75,6 +75,8 @@ char *user_bus_path(User *s);
extern const DBusObjectPathVTable bus_user_vtable;
+int user_send_signal(User *u, bool new_user);
+
const char* user_state_to_string(UserState s);
UserState user_state_from_string(const char *s);