summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2015-08-05 15:58:39 +0200
committerDaniel Mack <daniel@zonque.org>2015-08-05 17:06:45 +0200
commit3cde9e8fa0ae2a424ae2e6e27e14668ca5d90c98 (patch)
treed8320bbaeec3fae3b838278f4c764f185eabe7c9
parent652f0e397fab33e325f4119dceece9f334f549cf (diff)
logind: switch to sd_bus_track helper
Let logind use the sd_bus_track helper object to track the controllers of sessions. This does not only remove quite some code but also kills the unconditional matches for all NameOwnerChanged signals. The latter is something we should never ever do, as it wakes up the daemon every time a client connects, which doesn't scale.
-rw-r--r--src/login/logind-core.c38
-rw-r--r--src/login/logind-dbus.c35
-rw-r--r--src/login/logind-session.c25
-rw-r--r--src/login/logind-session.h1
-rw-r--r--src/login/logind.c18
-rw-r--r--src/login/logind.h5
6 files changed, 23 insertions, 99 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 96a20e27b9..6c05c11dbd 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -183,44 +183,6 @@ int manager_add_button(Manager *m, const char *name, Button **_button) {
return 0;
}
-int manager_watch_busname(Manager *m, const char *name) {
- char *n;
- int r;
-
- assert(m);
- assert(name);
-
- if (set_get(m->busnames, (char*) name))
- return 0;
-
- n = strdup(name);
- if (!n)
- return -ENOMEM;
-
- r = set_put(m->busnames, n);
- if (r < 0) {
- free(n);
- return r;
- }
-
- return 0;
-}
-
-void manager_drop_busname(Manager *m, const char *name) {
- Session *session;
- Iterator i;
-
- assert(m);
- assert(name);
-
- /* keep it if the name still owns a controller */
- HASHMAP_FOREACH(session, m->sessions, i)
- if (session_is_controller(session, name))
- return;
-
- free(set_remove(m->busnames, (char*) name));
-}
-
int manager_process_seat_device(Manager *m, struct udev_device *d) {
Device *device;
int r;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index b0cd85e985..1647bb293a 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -2652,41 +2652,6 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error
return 0;
}
-int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
- const char *name, *old, *new;
- Manager *m = userdata;
- Session *session;
- Iterator i;
- int r;
- char *key;
-
- assert(message);
- assert(m);
-
- r = sd_bus_message_read(message, "sss", &name, &old, &new);
- if (r < 0) {
- bus_log_parse_error(r);
- return r;
- }
-
- if (isempty(old) || !isempty(new))
- return 0;
-
- key = set_remove(m->busnames, (char*) old);
- if (!key)
- return 0;
-
- /* Drop all controllers owned by this name */
-
- free(key);
-
- HASHMAP_FOREACH(session, m->sessions, i)
- if (session_is_controller(session, old))
- session_drop_controller(session);
-
- return 0;
-}
-
int manager_send_changed(Manager *manager, const char *property, ...) {
char **l;
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 9a2da7906e..fc92f7f73b 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -1120,7 +1120,18 @@ static void session_release_controller(Session *s, bool notify) {
session_device_free(sd);
s->controller = NULL;
- manager_drop_busname(s->manager, name);
+ s->track = sd_bus_track_unref(s->track);
+}
+
+static int on_bus_track(sd_bus_track *track, void *userdata) {
+ Session *s = userdata;
+
+ assert(track);
+ assert(s);
+
+ session_drop_controller(s);
+
+ return 0;
}
int session_set_controller(Session *s, const char *sender, bool force) {
@@ -1139,8 +1150,13 @@ int session_set_controller(Session *s, const char *sender, bool force) {
if (!name)
return -ENOMEM;
- r = manager_watch_busname(s->manager, name);
- if (r)
+ s->track = sd_bus_track_unref(s->track);
+ r = sd_bus_track_new(s->manager->bus, &s->track, on_bus_track, s);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_track_add_name(s->track, name);
+ if (r < 0)
return r;
/* When setting a session controller, we forcibly mute the VT and set
@@ -1153,7 +1169,7 @@ int session_set_controller(Session *s, const char *sender, bool force) {
* or reset the VT in case it crashed/exited, too. */
r = session_prepare_vt(s);
if (r < 0) {
- manager_drop_busname(s->manager, name);
+ s->track = sd_bus_track_unref(s->track);
return r;
}
@@ -1171,6 +1187,7 @@ void session_drop_controller(Session *s) {
if (!s->controller)
return;
+ s->track = sd_bus_track_unref(s->track);
session_release_controller(s, false);
session_save(s);
session_restore_vt(s);
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index b8565ebf51..d054c33cec 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -117,6 +117,7 @@ struct Session {
char *controller;
Hashmap *devices;
+ sd_bus_track *track;
LIST_FIELDS(Session, sessions_by_user);
LIST_FIELDS(Session, sessions_by_seat);
diff --git a/src/login/logind.c b/src/login/logind.c
index e2fb496289..49a2811842 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -76,10 +76,7 @@ static Manager *manager_new(void) {
m->user_units = hashmap_new(&string_hash_ops);
m->session_units = hashmap_new(&string_hash_ops);
- m->busnames = set_new(&string_hash_ops);
-
- if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames ||
- !m->user_units || !m->session_units)
+ if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units)
goto fail;
m->kill_exclude_users = strv_new("root", NULL);
@@ -141,8 +138,6 @@ static void manager_free(Manager *m) {
hashmap_free(m->user_units);
hashmap_free(m->session_units);
- set_free_free(m->busnames);
-
sd_event_source_unref(m->idle_action_event_source);
sd_event_source_unref(m->inhibit_timeout_source);
sd_event_source_unref(m->scheduled_shutdown_timeout_source);
@@ -629,17 +624,6 @@ static int manager_connect_bus(Manager *m) {
r = sd_bus_add_match(m->bus,
NULL,
"type='signal',"
- "sender='org.freedesktop.DBus',"
- "interface='org.freedesktop.DBus',"
- "member='NameOwnerChanged',"
- "path='/org/freedesktop/DBus'",
- match_name_owner_changed, m);
- if (r < 0)
- return log_error_errno(r, "Failed to add match for NameOwnerChanged: %m");
-
- r = sd_bus_add_match(m->bus,
- NULL,
- "type='signal',"
"sender='org.freedesktop.systemd1',"
"interface='org.freedesktop.systemd1.Manager',"
"member='JobRemoved',"
diff --git a/src/login/logind.h b/src/login/logind.h
index ad437b72cb..ce99d75bc1 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -48,8 +48,6 @@ struct Manager {
Hashmap *inhibitors;
Hashmap *buttons;
- Set *busnames;
-
LIST_HEAD(Seat, seat_gc_queue);
LIST_HEAD(Session, session_gc_queue);
LIST_HEAD(User, user_gc_queue);
@@ -181,9 +179,6 @@ int manager_job_is_active(Manager *manager, const char *path);
/* gperf lookup function */
const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
-int manager_watch_busname(Manager *manager, const char *name);
-void manager_drop_busname(Manager *manager, const char *name);
-
int manager_set_lid_switch_ignore(Manager *m, usec_t until);
int config_parse_tmpfs_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);