提交 a5021d69 编写于 作者: M Marc-André Lureau

util: add dbus helper unit

Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 a566907f
...@@ -2209,6 +2209,8 @@ F: qapi/migration.json ...@@ -2209,6 +2209,8 @@ F: qapi/migration.json
D-Bus D-Bus
M: Marc-André Lureau <marcandre.lureau@redhat.com> M: Marc-André Lureau <marcandre.lureau@redhat.com>
S: Maintained S: Maintained
F: util/dbus.c
F: include/qemu/dbus.h
F: docs/interop/dbus.rst F: docs/interop/dbus.rst
Seccomp Seccomp
......
/*
* 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.
*/
#ifndef DBUS_H
#define DBUS_H
#include <gio/gio.h>
GStrv qemu_dbus_get_queued_owners(GDBusConnection *connection,
const char *name,
Error **errp);
#endif /* DBUS_H */
...@@ -56,3 +56,6 @@ util-obj-$(call lnot,$(CONFIG_INOTIFY1)) += filemonitor-stub.o ...@@ -56,3 +56,6 @@ util-obj-$(call lnot,$(CONFIG_INOTIFY1)) += filemonitor-stub.o
util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o
util-obj-$(CONFIG_POSIX) += drm.o util-obj-$(CONFIG_POSIX) += drm.o
util-obj-y += guest-random.o util-obj-y += guest-random.o
util-obj-$(CONFIG_GIO) += dbus.o
dbus.o-cflags = $(GIO_CFLAGS)
dbus.o-libs = $(GIO_LIBS)
/*
* 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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册