diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-util.c | 26 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-util.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c index 2daf8c1dc4..7a21975092 100644 --- a/src/libsystemd-bus/bus-util.c +++ b/src/libsystemd-bus/bus-util.c @@ -103,6 +103,32 @@ int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t return 0; } +int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error) { + _cleanup_bus_message_unref_ sd_bus_message *rep = NULL; + int r, has_owner = 0; + + assert(c); + assert(name); + + r = sd_bus_call_method(c, + "org.freedesktop.DBus", + "/org/freedesktop/dbus", + "org.freedesktop.DBus", + "NameHasOwner", + error, + &rep, + "s", + name); + if (r < 0) + return r; + + r = sd_bus_message_read_basic(rep, 'b', &has_owner); + if (r < 0) + return sd_bus_error_set_errno(error, r); + + return has_owner; +} + int bus_verify_polkit( sd_bus *bus, sd_bus_message *m, diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h index 20739a92bd..38d468edad 100644 --- a/src/libsystemd-bus/bus-util.h +++ b/src/libsystemd-bus/bus-util.h @@ -56,6 +56,8 @@ int bus_async_unregister_and_quit(sd_event *e, sd_bus *bus, const char *name); int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout); +int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error); + int bus_check_peercred(sd_bus *c); int bus_verify_polkit(sd_bus *bus, sd_bus_message *m, const char *action, bool interactive, bool *_challenge, sd_bus_error *e); |