summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-12 20:00:19 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-12 20:00:45 +0100
commit3df7a7e610eece1362d0ab148f3d92b2c98277a1 (patch)
treefd9f85f460d001e838b334c70ca7847d1ac14edf /src/libsystemd-bus
parent0f437184b687af58c5c4b2e3201a83d98485b0e4 (diff)
bus: always pass valid timeout to kdbus
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-message.c3
-rw-r--r--src/libsystemd-bus/bus-message.h2
-rw-r--r--src/libsystemd-bus/sd-bus.c32
-rw-r--r--src/libsystemd-bus/test-bus-gvariant.c4
-rw-r--r--src/libsystemd-bus/test-bus-marshal.c4
-rw-r--r--src/libsystemd-bus/test-bus-match.c2
-rw-r--r--src/libsystemd-bus/test-bus-zero-copy.c2
7 files changed, 26 insertions, 23 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 0f19ee238a..a86cd9a196 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -2695,7 +2695,7 @@ static int bus_message_close_header(sd_bus_message *m) {
return 0;
}
-int bus_message_seal(sd_bus_message *m, uint64_t serial) {
+int bus_message_seal(sd_bus_message *m, uint64_t serial, usec_t timeout) {
struct bus_body_part *part;
size_t l, a;
unsigned i;
@@ -2742,6 +2742,7 @@ int bus_message_seal(sd_bus_message *m, uint64_t serial) {
return r;
m->header->serial = serial;
+ m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout;
/* Add padding at the end of the fields part, since we know
* the body needs to start at an 8 byte alignment. We made
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index 75a560b3c0..b9cd4c8f30 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -185,7 +185,7 @@ static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) {
return m->header->version == 2;
}
-int bus_message_seal(sd_bus_message *m, uint64_t serial);
+int bus_message_seal(sd_bus_message *m, uint64_t serial, usec_t timeout);
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 1a60356311..060dcc1436 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1276,7 +1276,7 @@ _public_ int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *server_id) {
return 0;
}
-static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
+static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) {
assert(b);
assert(m);
@@ -1296,7 +1296,10 @@ static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
return 0;
}
- return bus_message_seal(m, ++b->serial);
+ if (timeout == 0)
+ timeout = BUS_DEFAULT_TIMEOUT;
+
+ return bus_message_seal(m, ++b->serial, timeout);
}
int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
@@ -1311,7 +1314,7 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
* than (uint64_t) -1 since dbus1 only had 32bit identifiers,
* even though kdbus can do 64bit. */
- return bus_message_seal(m, 0xFFFFFFFFULL);
+ return bus_message_seal(m, 0xFFFFFFFFULL, 0);
}
static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx) {
@@ -1441,7 +1444,7 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial) {
if (!serial && !m->sealed)
m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
- r = bus_seal_message(bus, m);
+ r = bus_seal_message(bus, m, 0);
if (r < 0)
return r;
@@ -1516,9 +1519,6 @@ static usec_t calc_elapse(uint64_t usec) {
if (usec == (uint64_t) -1)
return 0;
- if (usec == 0)
- usec = BUS_DEFAULT_TIMEOUT;
-
return now(CLOCK_MONOTONIC) + usec;
}
@@ -1563,13 +1563,11 @@ _public_ int sd_bus_call_async(
if (r < 0)
return r;
- if (usec != (uint64_t) -1) {
- r = prioq_ensure_allocated(&bus->reply_callbacks_prioq, timeout_compare);
- if (r < 0)
- return r;
- }
+ r = prioq_ensure_allocated(&bus->reply_callbacks_prioq, timeout_compare);
+ if (r < 0)
+ return r;
- r = bus_seal_message(bus, m);
+ r = bus_seal_message(bus, m, usec);
if (r < 0)
return r;
@@ -1580,7 +1578,7 @@ _public_ int sd_bus_call_async(
c->callback = callback;
c->userdata = userdata;
c->serial = BUS_MESSAGE_SERIAL(m);
- c->timeout = calc_elapse(usec);
+ c->timeout = calc_elapse(m->timeout);
r = hashmap_put(bus->reply_callbacks, &c->serial, c);
if (r < 0) {
@@ -1675,11 +1673,15 @@ _public_ int sd_bus_call(
i = bus->rqueue_size;
+ r = bus_seal_message(bus, m, usec);
+ if (r < 0)
+ return r;
+
r = sd_bus_send(bus, m, &serial);
if (r < 0)
return r;
- timeout = calc_elapse(usec);
+ timeout = calc_elapse(m->timeout);
for (;;) {
usec_t left;
diff --git a/src/libsystemd-bus/test-bus-gvariant.c b/src/libsystemd-bus/test-bus-gvariant.c
index 7ceeb81b9d..de9f00124a 100644
--- a/src/libsystemd-bus/test-bus-gvariant.c
+++ b/src/libsystemd-bus/test-bus-gvariant.c
@@ -145,7 +145,7 @@ static void test_marshal(void) {
4711, "first-string-parameter", "(st)", "X", (uint64_t) 1111,
4712, "second-string-parameter", "(a(si))", 2, "Y", 5, "Z", 6) >= 0);
- assert_se(bus_message_seal(m, 4711) >= 0);
+ assert_se(bus_message_seal(m, 4711, 0) >= 0);
#ifdef HAVE_GLIB
{
@@ -185,7 +185,7 @@ static void test_marshal(void) {
assert_se(sd_bus_message_append(m, "as", 0) >= 0);
- assert_se(bus_message_seal(m, 4712) >= 0);
+ assert_se(bus_message_seal(m, 4712, 0) >= 0);
assert_se(bus_message_dump(m, NULL, true) >= 0);
}
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 79d693992a..069b0848e6 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_append_array(m, 'u', NULL, 0);
assert_se(r >= 0);
- r = bus_message_seal(m, 4711);
+ r = bus_message_seal(m, 4711, 0);
assert_se(r >= 0);
bus_message_dump(m, stdout, true);
@@ -253,7 +253,7 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_copy(copy, m, true);
assert_se(r >= 0);
- r = bus_message_seal(copy, 4712);
+ r = bus_message_seal(copy, 4712, 0);
assert_se(r >= 0);
fclose(ms);
diff --git a/src/libsystemd-bus/test-bus-match.c b/src/libsystemd-bus/test-bus-match.c
index af42f0baa7..25d2b927ed 100644
--- a/src/libsystemd-bus/test-bus-match.c
+++ b/src/libsystemd-bus/test-bus-match.c
@@ -113,7 +113,7 @@ int main(int argc, char *argv[]) {
assert_se(sd_bus_message_new_signal(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);
+ assert_se(bus_message_seal(m, 1, 0) >= 0);
zero(mask);
assert_se(bus_match_run(NULL, &root, m) == 0);
diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c
index 0b72fe5e7a..07ccbc3a9f 100644
--- a/src/libsystemd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd-bus/test-bus-zero-copy.c
@@ -133,7 +133,7 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_append(m, "u", 4711);
assert_se(r >= 0);
- r = bus_message_seal(m, 55);
+ r = bus_message_seal(m, 55, 0);
assert_se(r >= 0);
bus_message_dump(m, stdout, true);