From f1617a3b61b4c6f9d4a2a6581d3794c079acc02a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Mar 2019 15:40:56 +0100 Subject: [PATCH] sd-bus: maintain a counter for incoming msgs Let's count incoming messages and attach the current counter when we first read them to the message objects. This allows us to nicely order messages later on. --- src/libsystemd/sd-bus/bus-internal.h | 1 + src/libsystemd/sd-bus/bus-message.h | 2 ++ src/libsystemd/sd-bus/bus-socket.c | 1 + src/libsystemd/sd-bus/sd-bus.c | 7 +++++++ 4 files changed, 11 insertions(+) diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 39610c5d450..f6289daac68 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -226,6 +226,7 @@ struct sd_bus { size_t wqueue_allocated; uint64_t cookie; + uint64_t read_counter; /* A counter for each incoming msg */ char *unique_name; uint64_t unique_id; diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h index a7c4f81c4ba..ced0bb3d34a 100644 --- a/src/libsystemd/sd-bus/bus-message.h +++ b/src/libsystemd/sd-bus/bus-message.h @@ -128,6 +128,8 @@ struct sd_bus_message { size_t header_offsets[_BUS_MESSAGE_HEADER_MAX]; unsigned n_header_offsets; + + uint64_t read_counter; }; static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 9221b33d487..3541c411a8b 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -1146,6 +1146,7 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) { bus->n_fds = 0; if (t) { + t->read_counter = ++bus->read_counter; bus->rqueue[bus->rqueue_size++] = bus_message_ref_queued(t, bus); sd_bus_message_unref(t); } diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 978a5056103..ac611d29759 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -484,6 +484,7 @@ static int synthesize_connected_signal(sd_bus *bus) { return r; bus_message_set_sender_local(bus, m); + m->read_counter = ++bus->read_counter; r = bus_seal_synthetic_message(bus, m); if (r < 0) @@ -2422,6 +2423,8 @@ static int process_timeout(sd_bus *bus) { if (r < 0) return r; + m->read_counter = ++bus->read_counter; + r = bus_seal_synthetic_message(bus, m); if (r < 0) return r; @@ -2524,6 +2527,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { synthetic_reply->realtime = m->realtime; synthetic_reply->monotonic = m->monotonic; synthetic_reply->seqnum = m->seqnum; + synthetic_reply->read_counter = m->read_counter; r = bus_seal_synthetic_message(bus, synthetic_reply); if (r < 0) @@ -2866,6 +2870,8 @@ static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c) if (r < 0) return r; + m->read_counter = ++bus->read_counter; + r = bus_seal_synthetic_message(bus, m); if (r < 0) return r; @@ -2930,6 +2936,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) { return r; bus_message_set_sender_local(bus, m); + m->read_counter = ++bus->read_counter; r = bus_seal_synthetic_message(bus, m); if (r < 0)