summaryrefslogtreecommitdiff
path: root/src/core/dbus-unit.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/dbus-unit.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/dbus-unit.c')
-rw-r--r--src/core/dbus-unit.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 24d8a598e7..515ac8b78c 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -26,10 +26,10 @@
#include "strv.h"
#include "path-util.h"
#include "fileio.h"
-#include "dbus-unit.h"
-#include "dbus-manager.h"
#include "bus-errors.h"
-#include "dbus-client-track.h"
+#include "dbus.h"
+#include "dbus-manager.h"
+#include "dbus-unit.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState);
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode);
@@ -589,7 +589,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
SD_BUS_VTABLE_END
};
-static int send_new_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_new_signal(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_free_ char *p = NULL;
Unit *u = userdata;
@@ -615,10 +615,10 @@ static int send_new_signal(sd_bus *bus, const char *destination, void *userdata)
if (r < 0)
return r;
- return sd_bus_send_to(bus, m, destination, NULL);
+ return sd_bus_send(bus, m, NULL);
}
-static int send_changed_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_changed_signal(sd_bus *bus, void *userdata) {
_cleanup_free_ char *p = NULL;
Unit *u = userdata;
int r;
@@ -667,14 +667,14 @@ void bus_unit_send_change_signal(Unit *u) {
if (!u->id)
return;
- r = bus_manager_foreach_client(u->manager, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
+ r = bus_foreach_bus(u->manager, NULL, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
if (r < 0)
log_debug("Failed to send unit change signal for %s: %s", u->id, strerror(-r));
u->sent_dbus_new_signal = true;
}
-static int send_removed_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_removed_signal(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_free_ char *p = NULL;
Unit *u = userdata;
@@ -700,7 +700,7 @@ static int send_removed_signal(sd_bus *bus, const char *destination, void *userd
if (r < 0)
return r;
- return sd_bus_send_to(bus, m, destination, NULL);
+ return sd_bus_send(bus, m, NULL);
}
void bus_unit_send_removed_signal(Unit *u) {
@@ -713,7 +713,7 @@ void bus_unit_send_removed_signal(Unit *u) {
if (!u->id)
return;
- r = bus_manager_foreach_client(u->manager, send_removed_signal, u);
+ r = bus_foreach_bus(u->manager, NULL, send_removed_signal, u);
if (r < 0)
log_debug("Failed to send unit remove signal for %s: %s", u->id, strerror(-r));
}
@@ -765,9 +765,17 @@ int bus_unit_queue_job(
if (r < 0)
return r;
- r = bus_client_track(&j->subscribed, bus, sd_bus_message_get_sender(message));
- if (r < 0)
- return r;
+ if (bus == u->manager->api_bus) {
+ if (!j->subscribed) {
+ r = sd_bus_track_new(bus, &j->subscribed, NULL, NULL);
+ if (r < 0)
+ return r;
+ }
+
+ r = sd_bus_track_add_sender(j->subscribed, message);
+ if (r < 0)
+ return r;
+ }
path = job_dbus_path(j);
if (!path)