[systemd-devel] [PATCH 1/7] libsystemd-bus: bring definitions in sync with kdbus
Yin Kangkai
kangkai.yin at linux.intel.com
Tue Dec 3 18:31:50 PST 2013
On 2013-11-15, 19:32 +0100, Daniel Mack wrote:
> In particular, KDBUS_ITEM_NEXT is now called KDBUS_PART_NEXT, and
> KDBUS_ITEM_FOREACH was renamed to KDBUS_PART_FOREACH and takes one more
> argument to make it more flexible.
[...]
> ---
> src/libsystemd-bus/bus-control.c | 2 +-
> src/libsystemd-bus/bus-kernel.c | 12 ++++++------
> src/libsystemd-bus/bus-kernel.h | 14 +++++++-------
> 3 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
> index f217269..5c9e746 100644
> --- a/src/libsystemd-bus/bus-control.c
> +++ b/src/libsystemd-bus/bus-control.c
> @@ -468,7 +468,7 @@ int bus_add_match_internal(
> item->type = KDBUS_MATCH_BLOOM;
> memcpy(item->data64, bloom, BLOOM_SIZE);
>
> - item = KDBUS_ITEM_NEXT(item);
> + item = KDBUS_PART_NEXT(item);
> }
>
> if (sender) {
> diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
> index bf8de04..3ea85d4 100644
> --- a/src/libsystemd-bus/bus-kernel.c
> +++ b/src/libsystemd-bus/bus-kernel.c
> @@ -409,7 +409,7 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
> off = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer;
> ioctl(bus->input_fd, KDBUS_CMD_MSG_RELEASE, &off);
>
> - KDBUS_ITEM_FOREACH(d, k) {
> + KDBUS_PART_FOREACH(d, k, items) {
>
> if (d->type == KDBUS_MSG_FDS)
> close_many(d->fds, (d->size - offsetof(struct kdbus_item, fds)) / sizeof(int));
> @@ -435,7 +435,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
> if (k->payload_type != KDBUS_PAYLOAD_DBUS1)
> return 0;
>
> - KDBUS_ITEM_FOREACH(d, k) {
> + KDBUS_PART_FOREACH(d, k, items) {
> size_t l;
>
> l = d->size - offsetof(struct kdbus_item, data);
> @@ -489,7 +489,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
> if (r < 0)
> return r;
>
> - KDBUS_ITEM_FOREACH(d, k) {
> + KDBUS_PART_FOREACH(d, k, items) {
> size_t l;
>
> l = d->size - offsetof(struct kdbus_item, data);
> @@ -668,13 +668,13 @@ int bus_kernel_create(const char *name, char **s) {
>
> l = strlen(name);
> make = alloca0(offsetof(struct kdbus_cmd_bus_make, items) +
> - KDBUS_ITEM_HEADER_SIZE + sizeof(uint64_t) +
> - KDBUS_ITEM_HEADER_SIZE + DECIMAL_STR_MAX(uid_t) + 1 + l + 1);
> + KDBUS_PART_HEADER_SIZE + sizeof(uint64_t) +
> + KDBUS_PART_HEADER_SIZE + DECIMAL_STR_MAX(uid_t) + 1 + l + 1);
>
> n = make->items;
> n->type = KDBUS_MAKE_NAME;
> sprintf(n->str, "%lu-%s", (unsigned long) getuid(), name);
> - n->size = KDBUS_ITEM_HEADER_SIZE + strlen(n->str) + 1;
> + n->size = KDBUS_PART_HEADER_SIZE + strlen(n->str) + 1;
>
> make->size = offsetof(struct kdbus_cmd_bus_make, items) + n->size;
> make->flags = KDBUS_MAKE_POLICY_OPEN;
> diff --git a/src/libsystemd-bus/bus-kernel.h b/src/libsystemd-bus/bus-kernel.h
> index c4573c9..69df4f4 100644
> --- a/src/libsystemd-bus/bus-kernel.h
> +++ b/src/libsystemd-bus/bus-kernel.h
> @@ -23,16 +23,16 @@
>
> #include "sd-bus.h"
>
> -#define KDBUS_ITEM_NEXT(item) \
> +#define KDBUS_PART_NEXT(item) \
> (typeof(item))(((uint8_t *)item) + ALIGN8((item)->size))
>
> -#define KDBUS_ITEM_FOREACH(item, head) \
> - for (item = (head)->items; \
> - (uint8_t *)(item) < (uint8_t *)(head) + (head)->size; \
> - item = KDBUS_ITEM_NEXT(item))
> +#define KDBUS_PART_FOREACH(part, head, first) \
> + for (part = (head)->first; \
> + (uint8_t *)(part) < (uint8_t *)(head) + (head)->size; \
> + part = KDBUS_PART_NEXT(part))
>
> -#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
> -#define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
> +#define KDBUS_PART_HEADER_SIZE offsetof(struct kdbus_item, data)
[...]
> +#define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_PART_HEADER_SIZE)
We missed this one? KDBUS_ITEM_SIZE/KDBUS_PART_SIZE
Actually, I have a stupid question, do we have any particular reason
to use "part/PART"? giving the fact that we already have term "item"
everywhere in the code...
struct kdbus_item, items, kdbus_msg.items...
My opinion, on the contrary, we should replace all the KDBUS_PART_xxx
into KDBUS_ITEM_xxx, that seems more reasonable to me :)
[Same question to the kdbus code as well]
Thanks,
Kangkai
More information about the systemd-devel
mailing list