chiark / gitweb /
bus: add bus_name_has_owner() helper
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 28 Nov 2013 13:50:19 +0000 (14:50 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Thu, 28 Nov 2013 14:16:49 +0000 (15:16 +0100)
Small helper to run a synchronous "NameHasOwner" request on the
dbus-daemon.

src/libsystemd-bus/bus-util.c
src/libsystemd-bus/bus-util.h

index 2daf8c1..7a21975 100644 (file)
@@ -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,
index 20739a9..38d468e 100644 (file)
@@ -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);