--- ell/dbus-kernel.c | 13 ++++++++++++- ell/dbus-private.h | 4 +++- ell/dbus.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ell/dbus-kernel.c b/ell/dbus-kernel.c index b47f973..9bc99d7 100644 --- a/ell/dbus-kernel.c +++ b/ell/dbus-kernel.c @@ -626,7 +626,8 @@ int _dbus_kernel_recv(int fd, void *kdbus_pool, return r; } -int _dbus_kernel_name_acquire(int fd, const char *name) +int _dbus_kernel_name_acquire(int fd, const char *name, bool allow_replacement, + bool replace_existing, bool queue, bool *queued) { struct { struct kdbus_cmd head; @@ -651,9 +652,19 @@ int _dbus_kernel_name_acquire(int fd, const char *name) item->type = KDBUS_ITEM_NAME; strcpy(item->str, name); + if (replace_existing) + cmd_name.head.flags |= KDBUS_NAME_REPLACE_EXISTING; + if (allow_replacement) + cmd_name.head.flags |= KDBUS_NAME_ALLOW_REPLACEMENT; + if (queue) + cmd_name.head.flags |= KDBUS_NAME_QUEUE; + if (ioctl(fd, KDBUS_CMD_NAME_ACQUIRE, &cmd_name) < 0) return -errno; + if (queued) + *queued = !!(cmd_name.head.flags & KDBUS_NAME_IN_QUEUE); + return 0; } diff --git a/ell/dbus-private.h b/ell/dbus-private.h index b455df2..8309474 100644 --- a/ell/dbus-private.h +++ b/ell/dbus-private.h @@ -243,7 +243,9 @@ int _dbus_kernel_recv(int fd, void *kdbus_pool, _dbus_name_owner_change_func_t name_owner_change_func, void *user_data); -int _dbus_kernel_name_acquire(int fd, const char *name); +int _dbus_kernel_name_acquire(int fd, const char *name, bool allow_replacement, + bool replace_existing, bool queue, + bool *queued); int _dbus_kernel_add_match(int fd, uint64_t bloom_size, uint64_t bloom_n_hash, const struct _dbus_filter_condition *rule, int rule_len, unsigned int id); diff --git a/ell/dbus.c b/ell/dbus.c index 1570d33..e79e23d 100644 --- a/ell/dbus.c +++ b/ell/dbus.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "util.h" #include "io.h" @@ -1120,6 +1121,34 @@ static bool kdbus_get_name_owner(struct l_dbus *dbus, const char *name) return true; } +static uint32_t kdbus_name_acquire(struct l_dbus *dbus, const char *name, + bool allow_replacement, + bool replace_existing, bool queue, + l_dbus_name_acquire_func_t callback, + void *user_data) +{ + int fd = l_io_get_fd(dbus->io); + bool queued = false; + int r; + + r = _dbus_kernel_name_acquire(fd, name, allow_replacement, + replace_existing, queue, &queued); + if (r < 0 && r != -EALREADY) { + l_util_debug(dbus->debug_handler, + dbus->debug_data, strerror(-r)); + + if (callback) + callback(dbus, false, false, user_data); + + return 0; + } + + if (callback) + callback(dbus, true, queued, user_data); + + return 1; +} + static const struct l_dbus_ops kdbus_ops = { .version = 2, .free = kdbus_free, @@ -1130,6 +1159,7 @@ static const struct l_dbus_ops kdbus_ops = { .remove_match = kdbus_remove_match, .get_name_owner = kdbus_get_name_owner, }, + .name_acquire = kdbus_name_acquire, }; static struct l_dbus *setup_kdbus(int fd) -- 2.5.0