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
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
if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
return -ENOMEM;
- r = strv_push(x, n);
- if (r < 0) {
- free(n);
- return -ENOMEM;
- }
+ r = strv_consume(x, n);
+ if (r < 0)
+ return r;
previous_id = name->owner_id;
}
_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
/* 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)
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
int bus_add_match_internal_kernel(
sd_bus *bus,
- uint64_t id,
struct bus_match_component *components,
unsigned n_components,
uint64_t cookie) {
m = alloca0(sz);
m->size = sz;
m->cookie = cookie;
- m->owner_id = id;
item = m->items;
return 0;
}
+#define internal_match(bus, m) \
+ ((bus)->hello_flags & KDBUS_HELLO_MONITOR \
+ ? (isempty(m) ? "eavesdrop='true'" : strappenda((m), ",eavesdrop='true'")) \
+ : (m))
+
static int bus_add_match_internal_dbus1(
sd_bus *bus,
const char *match) {
+ const char *e;
+
assert(bus);
assert(match);
+ e = internal_match(bus, match);
+
return sd_bus_call_method(
bus,
"org.freedesktop.DBus",
NULL,
NULL,
"s",
- match);
+ e);
}
int bus_add_match_internal(
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)
sd_bus *bus,
const char *match) {
+ const char *e;
+
assert(bus);
assert(match);
+ e = internal_match(bus, match);
+
return sd_bus_call_method(
bus,
"org.freedesktop.DBus",
NULL,
NULL,
"s",
- match);
+ e);
}
int bus_remove_match_internal(
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);