diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2019-09-27 12:16:54 +0400 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-01-06 18:41:32 +0400 |
commit | a5021d6991d9a573f6a47f2c1bfd45c586b89774 (patch) | |
tree | 7f0d2c9021f38fdb5ca8668a7817420ae05e1473 /util/dbus.c | |
parent | a566907f1b52c8e94d4add32f50fe9b7d8d12921 (diff) | |
download | qemu-a5021d6991d9a573f6a47f2c1bfd45c586b89774.zip qemu-a5021d6991d9a573f6a47f2c1bfd45c586b89774.tar.gz qemu-a5021d6991d9a573f6a47f2c1bfd45c586b89774.tar.bz2 |
util: add dbus helper unit
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'util/dbus.c')
-rw-r--r-- | util/dbus.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/util/dbus.c b/util/dbus.c new file mode 100644 index 0000000..9099dc5 --- /dev/null +++ b/util/dbus.c @@ -0,0 +1,57 @@ +/* + * Helpers for using D-Bus + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/dbus.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +/* + * qemu_dbus_get_queued_owners() - return the list of queued unique names + * @connection: A GDBusConnection + * @name: a service name + * + * Return: a GStrv of unique names, or NULL on failure. + */ +GStrv +qemu_dbus_get_queued_owners(GDBusConnection *connection, const char *name, + Error **errp) +{ + g_autoptr(GDBusProxy) proxy = NULL; + g_autoptr(GVariant) result = NULL; + g_autoptr(GVariant) child = NULL; + g_autoptr(GError) err = NULL; + + proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + NULL, &err); + if (!proxy) { + error_setg(errp, "Failed to create DBus proxy: %s", err->message); + return NULL; + } + + result = g_dbus_proxy_call_sync(proxy, "ListQueuedOwners", + g_variant_new("(s)", name), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, NULL, &err); + if (!result) { + if (g_error_matches(err, + G_DBUS_ERROR, + G_DBUS_ERROR_NAME_HAS_NO_OWNER)) { + return g_new0(char *, 1); + } + error_setg(errp, "Failed to call ListQueuedOwners: %s", err->message); + return NULL; + } + + child = g_variant_get_child_value(result, 0); + return g_variant_dup_strv(child, NULL); +} |