diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-11-28 14:50:19 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-28 15:16:49 +0100 |
commit | 5fd38859b30b95008e483109578c7fef2b5072f3 (patch) | |
tree | cb79e0875b75a3f88ce2c7462121ed3900984866 /src/libsystemd-bus | |
parent | 3fdb2494c1e24c0a020f5b54022d2c751fd26f50 (diff) |
bus: add bus_name_has_owner() helper
Small helper to run a synchronous "NameHasOwner" request on the
dbus-daemon.
Diffstat (limited to 'src/libsystemd-bus')
-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); |