From 8f8f05a919355095518911135c3d630f4620a9b0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 3 Mar 2014 01:33:45 +0100 Subject: 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. --- src/core/job.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/core/job.c') diff --git a/src/core/job.c b/src/core/job.c index 0cd4397bf2..9c099c686f 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -37,7 +37,7 @@ #include "special.h" #include "async.h" #include "virt.h" -#include "dbus-client-track.h" +#include "dbus.h" Job* job_new_raw(Unit *unit) { Job *j; @@ -90,7 +90,8 @@ void job_free(Job *j) { sd_event_source_unref(j->timer_event_source); - bus_client_track_free(j->subscribed); + sd_bus_track_unref(j->subscribed); + strv_free(j->deserialized_subscribed); free(j); } @@ -931,7 +932,7 @@ int job_serialize(Job *j, FILE *f, FDSet *fds) { if (j->begin_usec > 0) fprintf(f, "job-begin="USEC_FMT"\n", j->begin_usec); - bus_client_track_serialize(j->manager, f, j->subscribed); + bus_track_serialize(j->subscribed, f); /* End marker */ fputc('\n', f); @@ -1035,13 +1036,10 @@ int job_deserialize(Job *j, FILE *f, FDSet *fds) { else j->begin_usec = ull; - } else { - char t[strlen(l) + 1 + strlen(v) + 1]; + } else if (streq(l, "subscribed")) { - strcpy(stpcpy(stpcpy(t, l), "="), v); - - if (bus_client_track_deserialize_item(j->manager, &j->subscribed, t) == 0) - log_debug("Unknown deserialization key '%s'", l); + if (strv_extend(&j->deserialized_subscribed, v) < 0) + return log_oom(); } } } @@ -1051,6 +1049,12 @@ int job_coldplug(Job *j) { assert(j); + /* After deserialization is complete and the bus connection + * set up again, let's start watching our subscribers again */ + r = bus_track_coldplug(j->manager, &j->subscribed, &j->deserialized_subscribed); + if (r < 0) + return r; + if (j->begin_usec == 0 || j->unit->job_timeout == 0) return 0; -- cgit v1.2.3-54-g00ecf