#include <errno.h>
#include "strv.h"
-
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-message.h"
return 0;
}
-static int bus_request_name_kernel(sd_bus *bus, const char *name, unsigned flags) {
+static int bus_request_name_kernel(sd_bus *bus, const char *name, uint64_t flags) {
struct kdbus_cmd_name *n;
size_t l;
int r;
return 1;
}
-static int bus_request_name_dbus1(sd_bus *bus, const char *name, unsigned flags) {
+static int bus_request_name_dbus1(sd_bus *bus, const char *name, uint64_t flags) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- uint32_t ret;
+ uint32_t ret, param = 0;
int r;
assert(bus);
assert(name);
+ if (flags & SD_BUS_NAME_ALLOW_REPLACEMENT)
+ param |= BUS_NAME_ALLOW_REPLACEMENT;
+ if (flags & SD_BUS_NAME_REPLACE_EXISTING)
+ param |= BUS_NAME_REPLACE_EXISTING;
+ if (!(flags & SD_BUS_NAME_QUEUE))
+ param |= BUS_NAME_DO_NOT_QUEUE;
+
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
&reply,
"su",
name,
- flags);
+ param);
if (r < 0)
return r;
return -EIO;
}
-_public_ int sd_bus_request_name(sd_bus *bus, const char *name, unsigned flags) {
+_public_ int sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags) {
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_DO_NOT_QUEUE)), -EINVAL);
+ assert_return(!(flags & ~(SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_QUEUE)), -EINVAL);
if (bus->is_kernel)
return bus_request_name_kernel(bus, name, flags);
if (r < 0)
return r;
if (ret == BUS_NAME_NON_EXISTENT)
- return -ENOENT;
+ return -ESRCH;
if (ret == BUS_NAME_NOT_OWNER)
- return -EADDRNOTAVAIL;
+ return -EADDRINUSE;
if (ret == BUS_NAME_RELEASED)
return 0;
struct kdbus_cmd_name_list cmd = {};
struct kdbus_name_list *name_list;
struct kdbus_cmd_name *name;
+ uint64_t previous_id = 0;
int r;
/* Caller will free half-constructed list on failure... */
name_list = (struct kdbus_name_list *) ((uint8_t *) bus->kdbus_buffer + cmd.offset);
- KDBUS_PART_FOREACH(name, name_list, names) {
+ KDBUS_ITEM_FOREACH(name, name_list, names) {
- if (name->size > sizeof(*name)) {
- r = strv_extend(x, name->name);
- if (r < 0)
- return -ENOMEM;
- } else {
+ if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->id != previous_id) {
char *n;
if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0)
free(n);
return -ENOMEM;
}
+
+ previous_id = name->id;
}
+ if (name->size > sizeof(*name)) {
+ r = strv_extend(x, name->name);
+ if (r < 0)
+ return -ENOMEM;
+ }
}
r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd.offset);
}
if (activatable) {
- r = kernel_get_list(bus, KDBUS_NAME_LIST_STARTERS, &y);
+ r = kernel_get_list(bus, KDBUS_NAME_LIST_ACTIVATORS, &y);
if (r < 0)
return r;
cmd = alloca0(size);
strcpy(cmd->name, name);
}
+ cmd->flags = KDBUS_ATTACH_NAMES;
cmd->size = size;
r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
}
- KDBUS_PART_FOREACH(item, conn_info, items) {
+ KDBUS_ITEM_FOREACH(item, conn_info, items) {
switch (item->type) {
case KDBUS_ITEM_CMDLINE:
if (mask & SD_BUS_CREDS_CMDLINE) {
- c->cmdline_size = item->size - KDBUS_PART_HEADER_SIZE;
+ c->cmdline_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->cmdline = memdup(item->data, c->cmdline_size);
if (!c->cmdline) {
r = -ENOMEM;
SD_BUS_CREDS_INHERITABLE_CAPS | SD_BUS_CREDS_BOUNDING_CAPS) & mask;
if (m) {
- c->capability_size = item->size - KDBUS_PART_HEADER_SIZE;
+ c->capability_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->capability = memdup(item->data, c->capability_size);
if (!c->capability) {
r = -ENOMEM;
}
break;
- case KDBUS_ITEM_NAMES:
+ case KDBUS_ITEM_NAME:
if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
- c->well_known_names_size = item->size - KDBUS_PART_HEADER_SIZE;
- c->well_known_names = memdup(item->data, c->well_known_names_size);
- if (!c->well_known_names) {
- r = -ENOMEM;
+ r = strv_extend(&c->well_known_names, item->name.name);
+ if (r < 0)
goto fail;
- }
c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
}
return 0;
}
- if (old_owner) {
+ if (!isempty(old_owner)) {
r = bus_kernel_parse_unique_name(old_owner, &old_owner_id);
if (r < 0)
return 0;
return 0;
}
- if (new_owner) {
+ if (!isempty(new_owner)) {
r = bus_kernel_parse_unique_name(new_owner, &new_owner_id);
if (r < 0)
return r;
item->type = KDBUS_MATCH_BLOOM;
memcpy(item->data64, bloom, BLOOM_SIZE);
- item = KDBUS_PART_NEXT(item);
+ item = KDBUS_ITEM_NEXT(item);
}
if (sender) {