chiark / gitweb /
bus: don't attach KDBUS_ITEM_ID to match ioctl() if we don't need it
authorLennart Poettering <lennart@poettering.net>
Mon, 23 Dec 2013 21:32:33 +0000 (22:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 23 Dec 2013 21:32:33 +0000 (22:32 +0100)
src/libsystemd-bus/bus-control.c

index 942bc017886e90a88080ad92665fe458c61b7a79..1eed7b9e320952036e3f78899cd65d635381717d 100644 (file)
@@ -907,8 +907,7 @@ int bus_add_match_internal_kernel(
 
         zero(bloom);
 
 
         zero(bloom);
 
-        sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
-                    offsetof(struct kdbus_item, id) + sizeof(uint64_t));
+        sz = ALIGN8(offsetof(struct kdbus_cmd_match, items));
 
         for (i = 0; i < n_components; i++) {
                 struct bus_match_component *c = &components[i];
 
         for (i = 0; i < n_components; i++) {
                 struct bus_match_component *c = &components[i];
@@ -922,8 +921,9 @@ int bus_add_match_internal_kernel(
                         r = bus_kernel_parse_unique_name(c->value_str, &src_id);
                         if (r < 0)
                                 return r;
                         r = bus_kernel_parse_unique_name(c->value_str, &src_id);
                         if (r < 0)
                                 return r;
-
-                        if (r == 0) {
+                        else if (r > 0)
+                                sz += ALIGN8(offsetof(struct kdbus_item, id) + sizeof(uint64_t));
+                        else  {
                                 sender = c->value_str;
                                 sender_length = strlen(sender);
                                 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
                                 sender = c->value_str;
                                 sender_length = strlen(sender);
                                 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
@@ -1026,19 +1026,22 @@ int bus_add_match_internal_kernel(
         m->owner_id = id;
 
         item = m->items;
         m->owner_id = id;
 
         item = m->items;
-        item->size = offsetof(struct kdbus_item, id) + sizeof(uint64_t);
-        item->type = KDBUS_ITEM_ID;
-        item->id = src_id;
 
 
-        if (using_bloom) {
+        if (src_id != KDBUS_MATCH_ID_ANY) {
+                item->size = offsetof(struct kdbus_item, id) + sizeof(uint64_t);
+                item->type = KDBUS_ITEM_ID;
+                item->id = src_id;
                 item = KDBUS_ITEM_NEXT(item);
                 item = KDBUS_ITEM_NEXT(item);
+        }
+
+        if (using_bloom) {
                 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
                 item->type = KDBUS_ITEM_BLOOM;
                 memcpy(item->data64, bloom, BLOOM_SIZE);
                 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
                 item->type = KDBUS_ITEM_BLOOM;
                 memcpy(item->data64, bloom, BLOOM_SIZE);
+                item = KDBUS_ITEM_NEXT(item);
         }
 
         if (sender) {
         }
 
         if (sender) {
-                item = KDBUS_ITEM_NEXT(item);
                 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
                 item->type = KDBUS_ITEM_NAME;
                 memcpy(item->str, sender, sender_length + 1);
                 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
                 item->type = KDBUS_ITEM_NAME;
                 memcpy(item->str, sender, sender_length + 1);