chiark / gitweb /
bus: add macro for iterating through body parts of a message
authorLennart Poettering <lennart@poettering.net>
Tue, 14 May 2013 23:43:15 +0000 (01:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 14 May 2013 23:43:15 +0000 (01:43 +0200)
src/libsystemd-bus/bus-kernel.c
src/libsystemd-bus/bus-message.c
src/libsystemd-bus/bus-message.h
src/libsystemd-bus/bus-socket.c

index 5b1769c..3aa4084 100644 (file)
@@ -184,12 +184,13 @@ static int bus_message_setup_bloom(sd_bus_message *m, void *bloom) {
 }
 
 static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
+        struct bus_body_part *part;
         struct kdbus_item *d;
         bool well_known;
         uint64_t unique;
         size_t sz, dl;
+        unsigned i;
         int r;
-        struct bus_body_part *part;
 
         assert(b);
         assert(m);
@@ -253,7 +254,7 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
         if (m->fields)
                 append_payload_vec(&d, m->fields, ALIGN8(m->header->fields_size));
 
-        for (part = &m->body; part && part->size > 0; part = part->next)
+        MESSAGE_FOREACH_PART(part, i, m)
                 append_payload_vec(&d, part->data, part->size);
 
         if (m->kdbus->dst_id == KDBUS_DST_ID_BROADCAST) {
index 721dafe..3790102 100644 (file)
@@ -3600,9 +3600,11 @@ int bus_message_seal(sd_bus_message *m, uint64_t serial) {
                 m->header->fields_size -= a;
         }
 
-        for (i = 0, part = &m->body; i < m->n_body_parts; i++, part = part->next)
-                if (part->memfd >= 0 && part->sealed)
+        MESSAGE_FOREACH_PART(part, i, m)
+                if (part->memfd >= 0 && !part->sealed) {
                         ioctl(part->memfd, KDBUS_CMD_MEMFD_SEAL_SET, 1);
+                        part->sealed = true;
+                }
 
         m->header->serial = serial;
         m->sealed = true;
@@ -3906,7 +3908,7 @@ int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
                         e = mempset(e, 0, 8 - (m->header->fields_size % 8));
         }
 
-        for (i = 0, part = &m->body; i < m->n_body_parts; i++, part = part->next)
+        MESSAGE_FOREACH_PART(part, i, m)
                 e = mempcpy(e, part->data, part->size);
 
         assert(total == (size_t) ((uint8_t*) e - (uint8_t*) p));
index 1c50c73..01a1e01 100644 (file)
@@ -217,3 +217,6 @@ int bus_message_parse_fields(sd_bus_message *m);
 int bus_header_size(struct bus_header *h, size_t *sum);
 
 struct bus_body_part *message_append_part(sd_bus_message *m);
+
+#define MESSAGE_FOREACH_PART(part, i, m) \
+        for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next)
index 4a07869..f43b7da 100644 (file)
@@ -102,7 +102,7 @@ static int bus_message_setup_iovec(sd_bus_message *m) {
                         return r;
         }
 
-        for (i = 0, part = &m->body; i < m->n_body_parts; i++, part = part->next) {
+        MESSAGE_FOREACH_PART(part, i, m)  {
                 r = append_iovec(m, part->data, part->size);
                 if (r < 0)
                         return r;