[systemd-devel] [RFC][PATCH] bus: Add destination field to sd_bus_message_new_signal() and sd_bus_emit_signal()
Lukasz Skalski
l.skalski at partner.samsung.com
Thu Dec 5 04:13:57 PST 2013
destination - the unique bus name for the destination for the signal
or NULL to emit to all listeners.
This path makes libsystemd-bus API more consistent and similar
to GDBUS API, for reference:
gboolean g_dbus_connection_emit_signal (GDBusConnection *connection,
const gchar *destination_bus_name,
const gchar *object_path,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters,
GError **error);
---
src/cgroups-agent/cgroups-agent.c | 1 +
src/core/dbus-job.c | 6 ++++--
src/core/dbus-manager.c | 12 ++++++------
src/core/dbus-unit.c | 6 ++++--
src/core/dbus.c | 4 ++--
src/libsystemd-bus/bus-convenience.c | 3 ++-
src/libsystemd-bus/bus-kernel.c | 1 +
src/libsystemd-bus/bus-message.c | 8 ++++++++
src/libsystemd-bus/bus-objects.c | 6 +++---
src/libsystemd-bus/sd-bus.c | 1 +
src/libsystemd-bus/test-bus-chat.c | 1 +
src/libsystemd-bus/test-bus-kernel-bloom.c | 2 +-
src/libsystemd-bus/test-bus-kernel.c | 2 +-
src/libsystemd-bus/test-bus-match.c | 2 +-
src/login/logind-dbus.c | 1 +
src/login/logind-seat-dbus.c | 1 +
src/login/logind-session-dbus.c | 2 ++
src/login/logind-session-device.c | 8 +++-----
src/login/logind-user-dbus.c | 1 +
src/machine/machine-dbus.c | 1 +
src/systemd/sd-bus.h | 4 ++--
21 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/src/cgroups-agent/cgroups-agent.c b/src/cgroups-agent/cgroups-agent.c
index d1d843b..8c7237f 100644
--- a/src/cgroups-agent/cgroups-agent.c
+++ b/src/cgroups-agent/cgroups-agent.c
@@ -53,6 +53,7 @@ int main(int argc, char *argv[]) {
}
r = sd_bus_emit_signal(bus,
+ NULL,
"/org/freedesktop/systemd1/agent",
"org.freedesktop.systemd1.Agent",
"Released",
diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c
index 8c12b52..c689751 100644
--- a/src/core/dbus-job.c
+++ b/src/core/dbus-job.c
@@ -137,6 +137,7 @@ static int send_new_signal(sd_bus *bus, const char *destination, Job *j) {
r = sd_bus_message_new_signal(
bus,
+ destination,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"JobNew",
@@ -148,7 +149,7 @@ static int send_new_signal(sd_bus *bus, const char *destination, Job *j) {
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, Job *j) {
@@ -196,6 +197,7 @@ static int send_removed_signal(sd_bus *bus, const char *destination, Job *j) {
r = sd_bus_message_new_signal(
bus,
+ destination,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"JobRemoved",
@@ -207,7 +209,7 @@ static int send_removed_signal(sd_bus *bus, const char *destination, Job *j) {
if (r < 0)
return r;
- return sd_bus_send_to(bus, m, destination, NULL);
+ return sd_bus_send(bus, m, NULL);
}
void bus_job_send_removed_signal(Job *j) {
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index a2707ee..718d383 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1338,11 +1338,11 @@ static int send_unit_files_changed(sd_bus *bus, const char *destination, void *u
assert(bus);
- r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged", &message);
+ r = sd_bus_message_new_signal(bus, destination, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged", &message);
if (r < 0)
return r;
- return sd_bus_send_to(bus, message, destination, NULL);
+ return sd_bus_send(bus, message, NULL);
}
static int reply_unit_file_changes_and_free(
@@ -1668,7 +1668,7 @@ static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
assert(bus);
assert(times);
- r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished", &message);
+ r = sd_bus_message_new_signal(bus, destination, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished", &message);
if (r < 0)
return r;
@@ -1676,7 +1676,7 @@ static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
if (r < 0)
return r;
- return sd_bus_send_to(bus, message, destination, NULL);
+ return sd_bus_send(bus, message, NULL);
}
void bus_manager_send_finished(
@@ -1704,7 +1704,7 @@ static int send_reloading(sd_bus *bus, const char *destination, void *userdata)
assert(bus);
- r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading", &message);
+ r = sd_bus_message_new_signal(bus, destination, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading", &message);
if (r < 0)
return r;
@@ -1712,7 +1712,7 @@ static int send_reloading(sd_bus *bus, const char *destination, void *userdata)
if (r < 0)
return r;
- return sd_bus_send_to(bus, message, destination, NULL);
+ return sd_bus_send(bus, message, NULL);
}
void bus_manager_send_reloading(Manager *m, bool active) {
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 1fec0e3..a56802e 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -612,6 +612,7 @@ static int send_new_signal(sd_bus *bus, const char *destination, void *userdata)
r = sd_bus_message_new_signal(
bus,
+ destination,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"UnitNew",
@@ -623,7 +624,7 @@ 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) {
@@ -701,6 +702,7 @@ static int send_removed_signal(sd_bus *bus, const char *destination, void *userd
r = sd_bus_message_new_signal(
bus,
+ destination,
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"UnitRemoved",
@@ -712,7 +714,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) {
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 25d83a6..c81ee10 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -190,7 +190,7 @@ failed:
log_debug("D-Bus activation failed for %s: %s", name, bus_error_message(&error, r));
- r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure", &reply);
+ r = sd_bus_message_new_signal(bus, "org.freedesktop.DBus", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure", &reply);
if (r < 0) {
bus_log_create_error(r);
return 0;
@@ -202,7 +202,7 @@ failed:
return 0;
}
- r = sd_bus_send_to(bus, reply, "org.freedesktop.DBus", NULL);
+ r = sd_bus_send(bus, reply, NULL);
if (r < 0) {
log_error("Failed to respond with to bus activation request: %s", strerror(-r));
return r;
diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
index 3964960..a35109f 100644
--- a/src/libsystemd-bus/bus-convenience.c
+++ b/src/libsystemd-bus/bus-convenience.c
@@ -27,6 +27,7 @@
_public_ int sd_bus_emit_signal(
sd_bus *bus,
+ const char *destination,
const char *path,
const char *interface,
const char *member,
@@ -39,7 +40,7 @@ _public_ int sd_bus_emit_signal(
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
- r = sd_bus_message_new_signal(bus, path, interface, member, &m);
+ r = sd_bus_message_new_signal(bus, destination, path, interface, member, &m);
if (r < 0)
return r;
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 2c87f22..ae85cc7 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -479,6 +479,7 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol
r = sd_bus_message_new_signal(
bus,
+ NULL,
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"NameOwnerChanged",
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 4c0e27f..5ae53ab 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -504,6 +504,7 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
_public_ int sd_bus_message_new_signal(
sd_bus *bus,
+ const char *destination,
const char *path,
const char *interface,
const char *member,
@@ -513,6 +514,7 @@ _public_ int sd_bus_message_new_signal(
int r;
assert_return(!bus || bus->state != BUS_UNSET, -ENOTCONN);
+ assert_return(!destination || service_name_is_valid(destination), -EINVAL);
assert_return(object_path_is_valid(path), -EINVAL);
assert_return(interface_name_is_valid(interface), -EINVAL);
assert_return(member_name_is_valid(member), -EINVAL);
@@ -534,6 +536,12 @@ _public_ int sd_bus_message_new_signal(
if (r < 0)
goto fail;
+ if (destination) {
+ r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &t->destination);
+ if (r < 0)
+ goto fail;
+ }
+
*m = t;
return 0;
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index 7cd34c9..5f00a5a 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -1879,7 +1879,7 @@ static int emit_properties_changed_on_interface(
if (!n)
return 0;
- r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
+ r = sd_bus_message_new_signal(bus, NULL, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
if (r < 0)
return r;
@@ -2202,7 +2202,7 @@ _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, ch
if (m)
m = sd_bus_message_unref(m);
- r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", &m);
+ r = sd_bus_message_new_signal(bus, NULL, path, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", &m);
if (r < 0)
return r;
@@ -2270,7 +2270,7 @@ _public_ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path,
if (strv_isempty(interfaces))
return 0;
- r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", &m);
+ r = sd_bus_message_new_signal(bus, NULL, path, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", &m);
if (r < 0)
return r;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index fef122b..9196ca8 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2151,6 +2151,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
/* Then, synthesize a Disconnected message */
r = sd_bus_message_new_signal(
bus,
+ NULL,
"/org/freedesktop/DBus/Local",
"org.freedesktop.DBus.Local",
"Disconnected",
diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c
index 021379f..98a168b 100644
--- a/src/libsystemd-bus/test-bus-chat.c
+++ b/src/libsystemd-bus/test-bus-chat.c
@@ -407,6 +407,7 @@ static void* client2(void*p) {
r = sd_bus_message_new_signal(
bus,
+ NULL,
"/foobar",
"foo.bar",
"Notify",
diff --git a/src/libsystemd-bus/test-bus-kernel-bloom.c b/src/libsystemd-bus/test-bus-kernel-bloom.c
index 62983ea..7454d0e 100644
--- a/src/libsystemd-bus/test-bus-kernel-bloom.c
+++ b/src/libsystemd-bus/test-bus-kernel-bloom.c
@@ -74,7 +74,7 @@ static void test_one(
assert_se(r >= 0);
log_debug("signal");
- r = sd_bus_emit_signal(a, path, interface, member, "s", arg0);
+ r = sd_bus_emit_signal(a, NULL, path, interface, member, "s", arg0);
assert_se(r >= 0);
r = sd_bus_process(b, &m);
diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c
index 785e245..3879f56 100644
--- a/src/libsystemd-bus/test-bus-kernel.c
+++ b/src/libsystemd-bus/test-bus-kernel.c
@@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
r = sd_bus_add_match(b, "interface='waldo.com',member='Piep'", NULL, NULL);
assert_se(r >= 0);
- r = sd_bus_emit_signal(a, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name");
+ r = sd_bus_emit_signal(a, NULL, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name");
assert_se(r >= 0);
r = sd_bus_process(b, &m);
diff --git a/src/libsystemd-bus/test-bus-match.c b/src/libsystemd-bus/test-bus-match.c
index af42f0b..07061f7 100644
--- a/src/libsystemd-bus/test-bus-match.c
+++ b/src/libsystemd-bus/test-bus-match.c
@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
bus_match_dump(&root, 0);
- assert_se(sd_bus_message_new_signal(NULL, "/foo/bar", "bar.x", "waldo", &m) >= 0);
+ assert_se(sd_bus_message_new_signal(NULL, NULL, "/foo/bar", "bar.x", "waldo", &m) >= 0);
assert_se(sd_bus_message_append(m, "ssss", "one", "two", "/prefix/three", "prefix.four") >= 0);
assert_se(bus_message_seal(m, 1) >= 0);
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 0461d18..ebf5061 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1389,6 +1389,7 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
assert(signal_name[w]);
return sd_bus_emit_signal(m->bus,
+ NULL,
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
signal_name[w],
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 23f975b..354c128 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -366,6 +366,7 @@ int seat_send_signal(Seat *s, bool new_seat) {
return sd_bus_emit_signal(
s->manager->bus,
+ NULL,
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
new_seat ? "SeatNew" : "SeatRemoved",
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index 4bbe75e..dca460d 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -581,6 +581,7 @@ int session_send_signal(Session *s, bool new_session) {
return sd_bus_emit_signal(
s->manager->bus,
+ NULL,
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
new_session ? "SessionNew" : "SessionRemoved",
@@ -616,6 +617,7 @@ int session_send_lock(Session *s, bool lock) {
return sd_bus_emit_signal(
s->manager->bus,
+ NULL,
p,
"org.freedesktop.login1.Session",
lock ? "Lock" : "Unlock",
diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c
index 592bcf2..7abb4ad 100644
--- a/src/login/logind-session-device.c
+++ b/src/login/logind-session-device.c
@@ -62,17 +62,15 @@ static int session_device_notify(SessionDevice *sd, enum SessionDeviceNotificati
return -ENOMEM;
r = sd_bus_message_new_signal(
- sd->session->manager->bus, path,
+ sd->session->manager->bus,
+ sd->session->controller,
+ path,
"org.freedesktop.login1.Session",
(type == SESSION_DEVICE_RESUME) ? "ResumeDevice" : "PauseDevice",
&m);
if (!m)
return r;
- r = sd_bus_message_set_destination(m, sd->session->controller);
- if (r < 0)
- return r;
-
switch (type) {
case SESSION_DEVICE_RESUME:
r = sd_bus_message_append(m, "uuh", major, minor, sd->fd);
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index b034515..96419c9 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -340,6 +340,7 @@ int user_send_signal(User *u, bool new_user) {
return sd_bus_emit_signal(
u->manager->bus,
+ NULL,
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
new_user ? "UserNew" : "UserRemoved",
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 1f24b11..8bc886b 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -248,6 +248,7 @@ int machine_send_signal(Machine *m, bool new_machine) {
return sd_bus_emit_signal(
m->manager->bus,
+ NULL,
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
new_machine ? "MachineNew" : "MachineRemoved",
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 1c0d12a..0fca699 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -164,7 +164,7 @@ int sd_bus_remove_object_manager(sd_bus *bus, const char *path);
/* Message object */
-int sd_bus_message_new_signal(sd_bus *bus, const char *path, const char *interface, const char *member, sd_bus_message **m);
+int sd_bus_message_new_signal(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
int sd_bus_message_new_method_call(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
int sd_bus_message_new_method_return(sd_bus_message *call, sd_bus_message **m);
int sd_bus_message_new_method_error(sd_bus_message *call, const sd_bus_error *e, sd_bus_message **m);
@@ -254,7 +254,7 @@ int sd_bus_reply_method_errorf(sd_bus_message *call, const char *name, const cha
int sd_bus_reply_method_errno(sd_bus_message *call, int error, const sd_bus_error *e);
int sd_bus_reply_method_errnof(sd_bus_message *call, int error, const char *format, ...) _sd_printf_(3, 0);
-int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
+int sd_bus_emit_signal(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, const char *types, ...);
int sd_bus_emit_properties_changed_strv(sd_bus *bus, const char *path, const char *interface, char **names);
int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...) _sd_sentinel_;
--
1.8.3.2
More information about the systemd-devel
mailing list