diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-29 23:44:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-30 15:21:54 +0100 |
commit | 9d373862243c7807e04a0c56ac5dfab3adbb410c (patch) | |
tree | 8ed15d891015d36bd4f9ea49f51d7c1771838516 /src/libsystemd-bus | |
parent | b29b8bc202979eed83846f55c6de34f7461ed15d (diff) |
bus: consider it an error if the first message we get on the bus is not a reply to HELLO
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r-- | src/libsystemd-bus/bus-internal.h | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 32 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h index c25a208aea..345e6568dc 100644 --- a/src/libsystemd-bus/bus-internal.h +++ b/src/libsystemd-bus/bus-internal.h @@ -123,6 +123,8 @@ struct sd_bus { char *exec_path; char **exec_argv; + + uint64_t hello_serial; }; static inline void bus_unrefp(sd_bus **b) { diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 08a218b7cc..314fa6b6bf 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -244,11 +244,7 @@ static int bus_send_hello(sd_bus *bus) { if (r < 0) return r; - r = sd_bus_send_with_reply(bus, m, hello_callback, NULL, 0, NULL); - if (r < 0) - return r; - - return r; + return sd_bus_send_with_reply(bus, m, hello_callback, NULL, 0, &bus->hello_serial); } int bus_start_running(sd_bus *bus) { @@ -1421,6 +1417,28 @@ static int process_timeout(sd_bus *bus) { return r < 0 ? r : 1; } +static int process_hello(sd_bus *bus, sd_bus_message *m) { + assert(bus); + assert(m); + + if (bus->state != BUS_HELLO) + return 0; + + /* Let's make sure the first message on the bus is the HELLO + * reply. But note that we don't actually parse the message + * here (we leave that to the usual reply handling), we just + * verify we don't let any earlier msg through. */ + + if (m->header->type != SD_BUS_MESSAGE_TYPE_METHOD_RETURN && + m->header->type != SD_BUS_MESSAGE_TYPE_METHOD_ERROR) + return -EIO; + + if (m->reply_serial != bus->hello_serial) + return -EIO; + + return 0; +} + static int process_reply(sd_bus *bus, sd_bus_message *m) { struct reply_callback *c; int r; @@ -1675,6 +1693,10 @@ static int process_message(sd_bus *bus, sd_bus_message *m) { assert(bus); assert(m); + r = process_hello(bus, m); + if (r != 0) + return r; + r = process_reply(bus, m); if (r != 0) return r; |