summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-30 00:19:01 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-30 00:21:06 +0100
commit7adc46fcce257fcf4c83faa18b8c78f2a577e4f1 (patch)
tree073a6435743ed0f65abb895a9bd3049b9f136408 /src
parentdff55e5db393af91e912e509aac349cff4786de3 (diff)
bus: don't generate NameAcquired/NameLost messages in the library
The signals appear entirely redundant due to NameOwnerChange, hence don't do them in the new library, instead leave them for the compatibility bridge only. Also, set the serial number for synthesized messages to (uint32_t) -1.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-bus/bus-internal.h5
-rw-r--r--src/libsystemd-bus/bus-kernel.c80
-rw-r--r--src/libsystemd-bus/bus-socket.c14
-rw-r--r--src/libsystemd-bus/sd-bus.c46
4 files changed, 40 insertions, 105 deletions
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 9c46a78551..4881e0427c 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -295,10 +295,9 @@ int bus_ensure_running(sd_bus *bus);
int bus_start_running(sd_bus *bus);
int bus_next_address(sd_bus *bus);
-int bus_seal_message(sd_bus *b, sd_bus_message *m);
+int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m);
-int bus_rqueue_make_room(sd_bus *bus, unsigned n);
-int bus_rqueue_push(sd_bus *bus, sd_bus_message *m);
+int bus_rqueue_make_room(sd_bus *bus);
bool bus_pid_changed(sd_bus *bus);
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 8a0f085976..a8579c98fa 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -365,11 +365,7 @@ int bus_kernel_take_fd(sd_bus *b) {
/* the kernel told us the UUID of the underlying bus */
memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes));
- r = bus_start_running(b);
- if (r < 0)
- return r;
-
- return 1;
+ return bus_start_running(b);
}
int bus_kernel_connect(sd_bus *b) {
@@ -448,55 +444,18 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol
m->sender = "org.freedesktop.DBus";
- r = bus_seal_message(bus, m);
- if (r < 0)
- return r;
-
- r = bus_rqueue_push(bus, m);
+ r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
+ bus->rqueue[bus->rqueue_size++] = m;
m = NULL;
- return 1;
-}
-
-static int push_name_name_acquired(sd_bus *bus, const char *signal, const char *name) {
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
- int r;
-
- assert(bus);
-
- r = sd_bus_message_new_signal(
- bus,
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- signal,
- &m);
-
- if (r < 0)
- return r;
-
- r = sd_bus_message_append(m, "ss", name);
- if (r < 0)
- return r;
- m->sender = "org.freedesktop.DBus";
-
- r = bus_seal_message(bus, m);
- if (r < 0)
- return r;
-
- r = bus_rqueue_push(bus, m);
- if (r < 0)
- return r;
-
- m = NULL;
return 1;
}
static int translate_name_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *d) {
char new_owner[UNIQUE_NAME_MAX], old_owner[UNIQUE_NAME_MAX];
- int r;
assert(bus);
assert(k);
@@ -505,19 +464,6 @@ static int translate_name_change(sd_bus *bus, struct kdbus_msg *k, struct kdbus_
if (d->name_change.flags != 0)
return 0;
- /* First generate NameAcquired/NameList messages */
- if (d->type == KDBUS_ITEM_NAME_ADD && d->name_change.new_id == bus->unique_id) {
- r = push_name_name_acquired(bus, "NameAcquired", d->name_change.name);
- if (r < 0)
- return r;
-
- } else if (d->type == KDBUS_ITEM_NAME_REMOVE && d->name_change.old_id == bus->unique_id) {
- r = push_name_name_acquired(bus, "NameLost", d->name_change.name);
- if (r < 0)
- return r;
- }
-
- /* Then, generate NameOwnerChanged messages */
if (d->type == KDBUS_ITEM_NAME_ADD)
old_owner[0] = 0;
else
@@ -566,15 +512,13 @@ static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item *
m->sender = "org.freedesktop.DBus";
- r = bus_seal_message(bus, m);
- if (r < 0)
- return r;
-
- r = bus_rqueue_push(bus, m);
+ r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
+ bus->rqueue[bus->rqueue_size++] = m;
m = NULL;
+
return 1;
}
@@ -877,12 +821,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
m->kdbus = k;
m->release_kdbus = true;
m->free_fds = true;
-
fds = NULL;
- r = bus_rqueue_push(bus, m);
- if (r < 0)
- goto fail;
+ bus->rqueue[bus->rqueue_size++] = m;
return 1;
@@ -909,12 +850,7 @@ int bus_kernel_read_message(sd_bus *bus) {
assert(bus);
- /* Kernel messages might result in 2 new queued messages in
- * the worst case (NameOwnerChange and LostName for the same
- * well-known name, for example). Let's make room in
- * advance. */
-
- r = bus_rqueue_make_room(bus, 2);
+ r = bus_rqueue_make_room(bus);
if (r < 0)
return r;
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index 355f31c562..d7d3b4dac5 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -900,6 +900,10 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) {
assert(bus->rbuffer_size >= size);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
+ r = bus_rqueue_make_room(bus);
+ if (r < 0)
+ return r;
+
if (bus->rbuffer_size > size) {
b = memdup((const uint8_t*) bus->rbuffer + size,
bus->rbuffer_size - size);
@@ -925,11 +929,7 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) {
bus->fds = NULL;
bus->n_fds = 0;
- r = bus_rqueue_push(bus, t);
- if (r < 0) {
- sd_bus_message_unref(t);
- return r;
- }
+ bus->rqueue[bus->rqueue_size++] = t;
return 1;
}
@@ -953,10 +953,6 @@ int bus_socket_read_message(sd_bus *bus) {
assert(bus);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
- r = bus_rqueue_make_room(bus, 1);
- if (r < 0)
- return r;
-
r = bus_socket_read_message_need(bus, &need);
if (r < 0)
return r;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 86265955bb..0eb61c4bd3 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1231,7 +1231,8 @@ _public_ int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *server_id) {
return 0;
}
-int bus_seal_message(sd_bus *b, sd_bus_message *m) {
+static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
+ assert(b);
assert(m);
if (m->header->version > b->message_version)
@@ -1248,6 +1249,24 @@ int bus_seal_message(sd_bus *b, sd_bus_message *m) {
return bus_message_seal(m, ++b->serial);
}
+int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
+ assert(b);
+ assert(m);
+
+ if (m->header->version > b->message_version)
+ return -EPERM;
+
+ /* The bus specification says the serial number cannot be 0,
+ * hence let's fill something in for synthetic messages. Since
+ * synthetic messages might have a fake sender and we don't
+ * want to interfere with the real sender's serial numbers we
+ * pick a fixed, artifical one. We use (uint32_t) -1 rather
+ * than (uint64_t) -1 since dbus1 only had 32bit identifiers,
+ * even though kdbus can do 64bit. */
+
+ return bus_message_seal(m, 0xFFFFFFFFULL);
+}
+
static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx) {
int r;
@@ -1308,11 +1327,11 @@ static int bus_read_message(sd_bus *bus) {
return bus_socket_read_message(bus);
}
-int bus_rqueue_make_room(sd_bus *bus, unsigned n) {
+int bus_rqueue_make_room(sd_bus *bus) {
sd_bus_message **q;
unsigned x;
- x = bus->rqueue_size + n;
+ x = bus->rqueue_size + 1;
if (bus->rqueue_allocated >= x)
return 0;
@@ -1330,21 +1349,6 @@ int bus_rqueue_make_room(sd_bus *bus, unsigned n) {
return 0;
}
-int bus_rqueue_push(sd_bus *bus, sd_bus_message *m) {
- int r;
-
- assert(bus);
- assert(m);
-
- r = bus_rqueue_make_room(bus, 1);
- if (r < 0)
- return r;
-
- bus->rqueue[bus->rqueue_size++] = m;
-
- return 0;
-}
-
static int dispatch_rqueue(sd_bus *bus, sd_bus_message **m) {
int r, ret = 0;
@@ -1820,7 +1824,7 @@ static int process_timeout(sd_bus *bus) {
m->sender = "org.freedesktop.DBus";
- r = bus_seal_message(bus, m);
+ r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
@@ -2112,7 +2116,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
if (r < 0)
return r;
- r = bus_seal_message(bus, m);
+ r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
@@ -2143,7 +2147,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
m->sender = "org.freedesktop.DBus.Local";
- r = bus_seal_message(bus, m);
+ r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;