summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-bus/bus-message.c44
-rw-r--r--src/libsystemd-bus/bus-message.h1
-rw-r--r--src/libsystemd-bus/sd-bus.c5
3 files changed, 30 insertions, 20 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 4c5588cf8a..ccea12055d 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -245,6 +245,8 @@ int sd_bus_message_new_signal(
return -EINVAL;
if (!member)
return -EINVAL;
+ if (!m)
+ return -EINVAL;
t = message_new(bus, SD_BUS_MESSAGE_TYPE_SIGNAL);
if (!t)
@@ -283,6 +285,8 @@ int sd_bus_message_new_method_call(
return -EINVAL;
if (!member)
return -EINVAL;
+ if (!m)
+ return -EINVAL;
t = message_new(bus, SD_BUS_MESSAGE_TYPE_METHOD_CALL);
if (!t)
@@ -315,9 +319,10 @@ fail:
return r;
}
-int sd_bus_message_new_method_return(
+static int message_new_reply(
sd_bus *bus,
sd_bus_message *call,
+ uint8_t type,
sd_bus_message **m) {
sd_bus_message *t;
@@ -327,12 +332,15 @@ int sd_bus_message_new_method_return(
return -EINVAL;
if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
return -EINVAL;
+ if (!m)
+ return -EINVAL;
- t = message_new(bus, SD_BUS_MESSAGE_TYPE_METHOD_RETURN);
+ t = message_new(bus, type);
if (!t)
return -ENOMEM;
t->reply_serial = BUS_MESSAGE_SERIAL(call);
+
r = message_append_field_uint32(t, SD_BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial);
if (r < 0)
goto fail;
@@ -343,14 +351,23 @@ int sd_bus_message_new_method_return(
goto fail;
}
+ t->dont_send = !!(call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED);
+
*m = t;
- return 0;
fail:
message_free(t);
return r;
}
+int sd_bus_message_new_method_return(
+ sd_bus *bus,
+ sd_bus_message *call,
+ sd_bus_message **m) {
+
+ return message_new_reply(bus, call, SD_BUS_MESSAGE_TYPE_METHOD_RETURN, m);
+}
+
int sd_bus_message_new_method_error(
sd_bus *bus,
sd_bus_message *call,
@@ -360,29 +377,16 @@ int sd_bus_message_new_method_error(
sd_bus_message *t;
int r;
- if (!call)
- return -EINVAL;
- if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
- return -EINVAL;
if (!e)
return -EINVAL;
if (!e->name)
return -EINVAL;
+ if (!m)
+ return -EINVAL;
- t = message_new(bus, SD_BUS_MESSAGE_TYPE_METHOD_ERROR);
- if (!t)
- return -ENOMEM;
-
- t->reply_serial = BUS_MESSAGE_SERIAL(call);
- r = message_append_field_uint32(t, SD_BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial);
+ r = message_new_reply(bus, call, SD_BUS_MESSAGE_TYPE_METHOD_ERROR, &t);
if (r < 0)
- goto fail;
-
- if (call->sender) {
- r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, call->sender, &t->sender);
- if (r < 0)
- goto fail;
- }
+ return r;
r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name);
if (r < 0)
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index c62659e424..bfd2b12280 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -71,6 +71,7 @@ struct sd_bus_message {
bool free_header:1;
bool free_fields:1;
bool free_body:1;
+ bool dont_send:1;
struct bus_header *header;
void *fields;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index d80f09793c..f7d7644463 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -996,6 +996,11 @@ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial) {
if (r < 0)
return r;
+ /* If this is a reply and no reply was requested, then let's
+ * suppress this, if we can */
+ if (m->dont_send && !serial)
+ return 0;
+
if (bus->wqueue_size <= 0) {
size_t idx = 0;