summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-29 18:58:30 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-29 18:58:30 +0200
commit9030ca462bd13cd6536299814e4a71d5c5e85be9 (patch)
tree43716aa3042f274b4578799725cfb03c5682e9d8 /src
parent47ee3ee03483efd271642d5043070cbd171f19d4 (diff)
sd-bus: allow passing NULL as bus parameter to sd_bus_send()
If NULL is specified for the bus it is now automatically derived from the passed in message. This commit also changes a number of invocations of sd_bus_send() to make use of this.
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-manager.c8
-rw-r--r--src/import/importd.c2
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c20
-rw-r--r--src/login/logind-dbus.c8
-rw-r--r--src/machine/machine-dbus.c8
-rw-r--r--src/machine/machined-dbus.c4
6 files changed, 31 insertions, 19 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 5fb0da2cb2..632529fcbc 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -916,7 +916,7 @@ static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_e
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -985,7 +985,7 @@ static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_erro
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -1502,7 +1502,7 @@ static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bu
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
fail:
unit_file_list_free(h);
@@ -1620,7 +1620,7 @@ static int reply_unit_file_changes_and_free(
if (r < 0)
goto fail;
- return sd_bus_send(sd_bus_message_get_bus(message), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
fail:
unit_file_changes_free(changes, n_changes);
diff --git a/src/import/importd.c b/src/import/importd.c
index 4f3701f5c5..45d1d93343 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -1064,7 +1064,7 @@ static int method_list_transfers(sd_bus_message *msg, void *userdata, sd_bus_err
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(msg), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_cancel(sd_bus_message *msg, void *userdata, sd_bus_error *error) {
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 41fbe7d4af..214b3d04df 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1695,8 +1695,11 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
_cleanup_bus_message_unref_ sd_bus_message *m = sd_bus_message_ref(_m);
int r;
- assert_return(bus, -EINVAL);
assert_return(m, -EINVAL);
+
+ if (!bus)
+ bus = m->bus;
+
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS);
@@ -1781,8 +1784,11 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie) {
_public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *cookie) {
int r;
- assert_return(bus, -EINVAL);
assert_return(m, -EINVAL);
+
+ if (!bus)
+ bus = m->bus;
+
assert_return(!bus_pid_changed(bus), -ECHILD);
if (!BUS_IS_OPEN(bus->state))
@@ -1838,11 +1844,14 @@ _public_ int sd_bus_call_async(
_cleanup_bus_slot_unref_ sd_bus_slot *s = NULL;
int r;
- assert_return(bus, -EINVAL);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
assert_return(callback, -EINVAL);
+
+ if (!bus)
+ bus = m->bus;
+
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS);
@@ -1936,11 +1945,14 @@ _public_ int sd_bus_call(
unsigned i;
int r;
- assert_return(bus, -EINVAL);
assert_return(m, -EINVAL);
assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL);
assert_return(!bus_error_is_dirty(error), -EINVAL);
+
+ if (!bus)
+ bus = m->bus;
+
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS);
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 7603b0ec72..1f5cf865b1 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -428,7 +428,7 @@ static int method_list_sessions(sd_bus_message *message, void *userdata, sd_bus_
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_list_users(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -468,7 +468,7 @@ static int method_list_users(sd_bus_message *message, void *userdata, sd_bus_err
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_list_seats(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -505,7 +505,7 @@ static int method_list_seats(sd_bus_message *message, void *userdata, sd_bus_err
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -543,7 +543,7 @@ static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bu
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) {
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 4e73467b06..0892479a9a 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -335,7 +335,7 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -426,7 +426,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
int bus_machine_method_open_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -458,7 +458,7 @@ int bus_machine_method_open_pty(sd_bus_message *message, void *userdata, sd_bus_
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
int bus_machine_method_open_login(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@@ -551,7 +551,7 @@ int bus_machine_method_open_login(sd_bus_message *message, void *userdata, sd_bu
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(reply), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
int bus_machine_method_bind_mount(sd_bus_message *message, void *userdata, sd_bus_error *error) {
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 5036a63985..0e971a6789 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -255,7 +255,7 @@ static int method_list_machines(sd_bus_message *message, void *userdata, sd_bus_
if (r < 0)
return sd_bus_error_set_errno(error, r);
- return sd_bus_send(sd_bus_message_get_bus(message), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_create_or_register_machine(Manager *manager, sd_bus_message *message, bool read_network, Machine **_m, sd_bus_error *error) {
@@ -593,7 +593,7 @@ static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_er
if (r < 0)
return r;
- return sd_bus_send(sd_bus_message_get_bus(message), reply, NULL);
+ return sd_bus_send(NULL, reply, NULL);
}
static int method_open_machine_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {