From e12d81ae80214ef05ddedafd016bdd604ce17d12 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Nov 2014 14:59:12 +0100 Subject: sd-bus: given that the kernel now passes the auxgroups list as 32bit array to us, no need to convert to uid_t manually This way, we can save one allocation and avoid copying the array unnecesarily. --- src/libsystemd/sd-bus/bus-control.c | 22 +++++++++++++--------- src/libsystemd/sd-bus/bus-creds.c | 3 +-- src/libsystemd/sd-bus/bus-kernel.c | 17 +++-------------- 3 files changed, 17 insertions(+), 25 deletions(-) (limited to 'src/libsystemd/sd-bus') diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index 9cd5cd5fb6..758715d74e 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -402,6 +402,10 @@ static int bus_populate_creds_from_items( uint64_t m; int r; + assert(bus); + assert(info); + assert(c); + KDBUS_ITEM_FOREACH(item, info, items) { switch (item->type) { @@ -590,18 +594,18 @@ static int bus_populate_creds_from_items( case KDBUS_ITEM_AUXGROUPS: if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) { - size_t i, n; - uid_t *u; + size_t n; + uid_t *g; - n = (item->size - offsetof(struct kdbus_item, data64)) / sizeof(uint64_t); - u = new(uid_t, n); - if (!u) - return -ENOMEM; + assert_cc(sizeof(gid_t) == sizeof(uint32_t)); - for (i = 0; i < n; i++) - u[i] = (uid_t) item->data64[i]; + n = (item->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t); + g = newdup(gid_t, item->data32, n); + if (!g) + return -ENOMEM; - c->supplementary_gids = u; + free(c->supplementary_gids); + c->supplementary_gids = g; c->n_supplementary_gids = n; c->mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS; diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 43315b5b50..8aa53362fb 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -53,8 +53,6 @@ void bus_creds_done(sd_bus_creds *c) { strv_free(c->cmdline_array); strv_free(c->well_known_names); - - free(c->supplementary_gids); } _public_ sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c) { @@ -97,6 +95,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) { free(c->unique_name); free(c->cgroup_root); free(c->description); + free(c->supplementary_gids); free(c); } } else { diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 907c5c5cf6..2beaa892bc 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -677,21 +677,10 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { case KDBUS_ITEM_AUXGROUPS: if (bus->creds_mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) { - size_t i, n; - uid_t *u; - n = (d->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t); - u = new(uid_t, n); - if (!u) { - r = -ENOMEM; - goto fail; - } - - for (i = 0; i < n; i++) - u[i] = (uid_t) d->data32[i]; - - m->creds.supplementary_gids = u; - m->creds.n_supplementary_gids = n; + assert_cc(sizeof(gid_t) == sizeof(uint32_t)); + m->creds.n_supplementary_gids = (d->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t); + m->creds.supplementary_gids = (gid_t*) d->data32; m->creds.mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS; } -- cgit v1.2.3-54-g00ecf