X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fbus-control.c;h=6f0bf06a5fa1f20c990697d89d64e691592eb51a;hb=c85a5a243bc65b48b2b416315bee0e9057ef7fa3;hp=0fc2b1a67d19e49a15617692193590069b01b58d;hpb=98a4025806f478fc791b6bcf2ad4764c2e43b168;p=elogind.git diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c index 0fc2b1a67..6f0bf06a5 100644 --- a/src/libsystemd-bus/bus-control.c +++ b/src/libsystemd-bus/bus-control.c @@ -403,10 +403,9 @@ static int bus_get_owner_kdbus( uint64_t mask, sd_bus_creds **creds) { - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL; - struct kdbus_cmd_name_info *cmd; - struct kdbus_name_info *name_info; + struct kdbus_cmd_conn_info *cmd; + struct kdbus_conn_info *conn_info; struct kdbus_item *item; size_t size; uint64_t m, id; @@ -416,34 +415,34 @@ static int bus_get_owner_kdbus( if (r < 0) return r; if (r > 0) { - size = offsetof(struct kdbus_cmd_name_info, name); + size = offsetof(struct kdbus_cmd_conn_info, name); cmd = alloca0(size); cmd->id = id; } else { - size = offsetof(struct kdbus_cmd_name_info, name) + strlen(name) + 1; + size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1; cmd = alloca0(size); strcpy(cmd->name, name); } cmd->size = size; - r = ioctl(bus->input_fd, KDBUS_CMD_NAME_INFO, cmd); + r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd); if (r < 0) return -errno; - name_info = (struct kdbus_name_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset); + conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset); c = bus_creds_new(); if (!c) return -ENOMEM; if (mask & SD_BUS_CREDS_UNIQUE_NAME) { - if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) name_info->id) < 0) + if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) return -ENOMEM; c->mask |= SD_BUS_CREDS_UNIQUE_NAME; } - KDBUS_PART_FOREACH(item, name_info, items) { + KDBUS_PART_FOREACH(item, conn_info, items) { switch (item->type) { @@ -599,7 +598,7 @@ _public_ int sd_bus_get_owner( assert_return(bus, -EINVAL); assert_return(name, -EINVAL); - assert_return(mask <= _SD_BUS_CREDS_MAX, -ENOTSUP); + assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP); assert_return(mask == 0 || creds, -EINVAL); assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); @@ -669,6 +668,7 @@ static int add_name_change_match(sd_bus *bus, } if (is_name_id <= 0) { + struct kdbus_cmd_match *m; size_t sz, l; /* If the name argument is missing or is a well-known @@ -682,85 +682,74 @@ static int add_name_change_match(sd_bus *bus, offsetof(struct kdbus_notify_name_change, name) + l+1); - { - union { - uint8_t buffer[sz]; - struct kdbus_cmd_match match; - } m; - - memzero(&m, sz); - - m.match.size = sz; - m.match.cookie = cookie; - m.match.src_id = KDBUS_SRC_ID_KERNEL; + m = alloca0(sz); + m->size = sz; + m->cookie = cookie; + m->src_id = KDBUS_SRC_ID_KERNEL; - item = m.match.items; - item->size = - offsetof(struct kdbus_item, name_change) + - offsetof(struct kdbus_notify_name_change, name) + - l+1; + item = m->items; + item->size = + offsetof(struct kdbus_item, name_change) + + offsetof(struct kdbus_notify_name_change, name) + + l+1; - item->name_change.old_id = old_owner_id; - item->name_change.new_id = new_owner_id; + item->name_change.old_id = old_owner_id; + item->name_change.new_id = new_owner_id; - if (name) - strcpy(item->name_change.name, name); + if (name) + strcpy(item->name_change.name, name); - /* If the old name is unset or empty, then - * this can match against added names */ - if (!old_owner || old_owner[0] == 0) { - item->type = KDBUS_MATCH_NAME_ADD; + /* If the old name is unset or empty, then + * this can match against added names */ + if (!old_owner || old_owner[0] == 0) { + item->type = KDBUS_MATCH_NAME_ADD; - r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); - if (r < 0) - return -errno; - } + r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); + if (r < 0) + return -errno; + } - /* If the new name is unset or empty, then - * this can match against removed names */ - if (!new_owner || new_owner[0] == 0) { - item->type = KDBUS_MATCH_NAME_REMOVE; + /* If the new name is unset or empty, then + * this can match against removed names */ + if (!new_owner || new_owner[0] == 0) { + item->type = KDBUS_MATCH_NAME_REMOVE; - r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); - if (r < 0) - return -errno; - } + r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); + if (r < 0) + return -errno; + } - /* If the neither name is explicitly set to - * the empty string, then this can match - * agains changed names */ - if (!(old_owner && old_owner[0] == 0) && - !(new_owner && new_owner[0] == 0)) { - item->type = KDBUS_MATCH_NAME_CHANGE; + /* If the neither name is explicitly set to + * the empty string, then this can match + * agains changed names */ + if (!(old_owner && old_owner[0] == 0) && + !(new_owner && new_owner[0] == 0)) { + item->type = KDBUS_MATCH_NAME_CHANGE; - r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); - if (r < 0) - return -errno; - } + r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); + if (r < 0) + return -errno; } } if (is_name_id != 0) { - uint64_t sz = - ALIGN8(offsetof(struct kdbus_cmd_match, items) + - offsetof(struct kdbus_item, id_change) + - sizeof(struct kdbus_notify_id_change)); - union { - uint8_t buffer[sz]; - struct kdbus_cmd_match match; - } m; + struct kdbus_cmd_match *m; + uint64_t sz; /* If the name argument is missing or is a unique * name, then add KDBUS_MATCH_ID_{ADD,REMOVE} matches * for it */ - memzero(&m, sz); + sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) + + offsetof(struct kdbus_item, id_change) + + sizeof(struct kdbus_notify_id_change)); - m.match.size = sz; - m.match.cookie = cookie; - m.match.src_id = KDBUS_SRC_ID_KERNEL; + m = alloca0(sz); + m->size = sz; + m->cookie = cookie; + m->src_id = KDBUS_SRC_ID_KERNEL; - item = m.match.items; + item = m->items; item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change); item->id_change.id = name_id;