summaryrefslogtreecommitdiff
path: root/src/core/manager.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-03 01:33:45 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-03 02:34:13 +0100
commit8f8f05a919355095518911135c3d630f4620a9b0 (patch)
treecb7b75f124dd743d2bcaf366a4a64125d1c34253 /src/core/manager.c
parentd9256bac4da4241cb5d97960c899390839f2c6e5 (diff)
bus: add sd_bus_track object for tracking peers, and port core over to it
This is primarily useful for services that need to track clients which reference certain objects they maintain, or which explicitly want to subscribe to certain events. Something like this is done in a large number of services, and not trivial to do. Hence, let's unify this at one place. This also ports over PID 1 to use this to ensure that subscriptions to job and manager events are correctly tracked. As a side-effect this makes sure we properly serialize and restore the track list across daemon reexec/reload, which didn't work correctly before. This also simplifies how we distribute messages to broadcast to the direct busses: we only track subscriptions for the API bus and implicitly assume that all direct busses are subscribed. This should be a pretty OK simplification since clients connected via direct bus connections are shortlived anyway.
Diffstat (limited to 'src/core/manager.c')
-rw-r--r--src/core/manager.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index f5801b4749..9172a244ae 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -839,7 +839,7 @@ int manager_enumerate(Manager *m) {
}
static int manager_coldplug(Manager *m) {
- int r = 0, q;
+ int r = 0;
Iterator i;
Unit *u;
char *k;
@@ -848,12 +848,14 @@ static int manager_coldplug(Manager *m) {
/* Then, let's set up their initial state. */
HASHMAP_FOREACH_KEY(u, k, m->units, i) {
+ int q;
/* ignore aliases */
if (u->id != k)
continue;
- if ((q = unit_coldplug(u)) < 0)
+ q = unit_coldplug(u);
+ if (q < 0)
r = q;
}
@@ -996,6 +998,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
* didn't, then let's create the bus now. */
manager_setup_kdbus(m);
manager_connect_bus(m, !!serialization);
+ bus_track_coldplug(m, &m->subscribed, &m->deserialized_subscribed);
/* Third, fire things up! */
q = manager_coldplug(m);
@@ -2102,7 +2105,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) {
fprintf(f, "kdbus-fd=%i\n", copy);
}
- bus_serialize(m, f);
+ bus_track_serialize(m->subscribed, f);
fputc('\n', f);
@@ -2279,7 +2282,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
m->kdbus_fd = fdset_remove(fds, fd);
}
- } else if (bus_deserialize_item(m, l) == 0)
+ } else if (bus_track_deserialize_item(&m->deserialized_subscribed, l) == 0)
log_debug("Unknown serialization item '%s'", l);
}