assert(name);
l = strlen(name);
- size = offsetof(struct kdbus_cmd_name, name) + l + 1;
- n = alloca0(size);
+ size = offsetof(struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(l + 1);
+ n = alloca0_align(size, 8);
n->size = size;
kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
- memcpy(n->name, name, l+1);
+
+ n->items[0].size = KDBUS_ITEM_HEADER_SIZE + l + 1;
+ n->items[0].type = KDBUS_ITEM_NAME;
+ memcpy(n->items[0].str, name, l+1);
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(n, n->size);
assert_return(bus, -EINVAL);
assert_return(name, -EINVAL);
assert_return(bus->bus_client, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(!(flags & ~(SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_QUEUE)), -EINVAL);
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(name[0] != ':', -EINVAL);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
if (bus->is_kernel)
return bus_request_name_kernel(bus, name, flags);
else
static int bus_release_name_kernel(sd_bus *bus, const char *name) {
struct kdbus_cmd_name *n;
- size_t l;
+ size_t size, l;
int r;
assert(bus);
assert(name);
l = strlen(name);
- n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
- n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
- memcpy(n->name, name, l+1);
+ size = offsetof(struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(l + 1);
+ n = alloca0_align(size, 8);
+ n->size = size;
+
+ n->items[0].size = KDBUS_ITEM_HEADER_SIZE + l + 1;
+ n->items[0].type = KDBUS_ITEM_NAME;
+ memcpy(n->items[0].str, name, l+1);
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(n, n->size);
assert_return(bus, -EINVAL);
assert_return(name, -EINVAL);
assert_return(bus->bus_client, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(name[0] != ':', -EINVAL);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
if (bus->is_kernel)
return bus_release_name_kernel(bus, name);
else
KDBUS_ITEM_FOREACH(name, name_list, names) {
+ struct kdbus_item *item;
+ const char *entry_name = NULL;
+
if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->owner_id != previous_id) {
char *n;
previous_id = name->owner_id;
}
- if (name->size > sizeof(*name) && service_name_is_valid(name->name)) {
- r = strv_extend(x, name->name);
+ KDBUS_ITEM_FOREACH(item, name, items)
+ if (item->type == KDBUS_ITEM_NAME)
+ entry_name = item->str;
+
+ if (entry_name && service_name_is_valid(entry_name)) {
+ r = strv_extend(x, entry_name);
if (r < 0)
return -ENOMEM;
}
_public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable) {
assert_return(bus, -EINVAL);
assert_return(acquired || activatable, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
if (bus->is_kernel)
return bus_list_names_kernel(bus, acquired, activatable);
else
return r;
if (r > 0) {
size = offsetof(struct kdbus_cmd_conn_info, name);
- cmd = alloca0(size);
+ cmd = alloca0_align(size, 8);
cmd->id = id;
} else {
size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1;
- cmd = alloca0(size);
+ cmd = alloca0_align(size, 8);
strcpy(cmd->name, name);
}
/* Non-activated names are considered not available */
if (conn_info->flags & KDBUS_HELLO_ACTIVATOR)
- return name[0] == ':' ? -ENXIO : -ENOENT;
+ return name[0] == ':' ? -ENXIO : -ESRCH;
c = bus_creds_new();
if (!c)
goto fail;
}
- if (!bus->cgroup_root) {
- r = cg_get_root_path(&bus->cgroup_root);
- if (r < 0)
- goto fail;
- }
+ r = bus_get_root_path(bus);
+ if (r < 0)
+ goto fail;
c->cgroup_root = strdup(bus->cgroup_root);
if (!c->cgroup_root) {
assert_return(name, -EINVAL);
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);
assert_return(service_name_is_valid(name), -EINVAL);
assert_return(bus->bus_client, -ENODATA);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
if (bus->is_kernel)
return bus_get_owner_kdbus(bus, name, mask, creds);
else
offsetof(struct kdbus_notify_name_change, name) +
l);
- m = alloca0(sz);
+ m = alloca0_align(sz, 8);
m->size = sz;
m->cookie = cookie;
offsetof(struct kdbus_item, id_change) +
sizeof(struct kdbus_notify_id_change));
- m = alloca0(sz);
+ m = alloca0_align(sz, 8);
m->size = sz;
m->cookie = cookie;
int bus_add_match_internal_kernel(
sd_bus *bus,
- uint64_t id,
struct bus_match_component *components,
unsigned n_components,
uint64_t cookie) {
if (using_bloom)
sz += ALIGN8(offsetof(struct kdbus_item, data64) + bus->bloom_size);
- m = alloca0(sz);
+ m = alloca0_align(sz, 8);
m->size = sz;
m->cookie = cookie;
- m->owner_id = id;
item = m->items;
uint64_t cookie) {
assert(bus);
- assert(match);
if (bus->is_kernel)
- return bus_add_match_internal_kernel(bus, 0, components, n_components, cookie);
+ return bus_add_match_internal_kernel(bus, components, n_components, cookie);
else
return bus_add_match_internal_dbus1(bus, match);
}
int bus_remove_match_internal_kernel(
sd_bus *bus,
- uint64_t id,
uint64_t cookie) {
struct kdbus_cmd_match m;
zero(m);
m.size = offsetof(struct kdbus_cmd_match, items);
m.cookie = cookie;
- m.owner_id = id;
r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
if (r < 0)
uint64_t cookie) {
assert(bus);
- assert(match);
if (bus->is_kernel)
- return bus_remove_match_internal_kernel(bus, 0, cookie);
+ return bus_remove_match_internal_kernel(bus, cookie);
else
return bus_remove_match_internal_dbus1(bus, match);
}
assert_return(bus, -EINVAL);
assert_return(name, -EINVAL);
assert_return(machine, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(service_name_is_valid(name), -EINVAL);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
if (streq_ptr(name, bus->unique_name))
return sd_id128_get_machine(machine);