All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com,
	dgilbert@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	pbonzini@redhat.com
Subject: [PATCH v6 4/8] util: add dbus helper unit
Date: Wed, 11 Dec 2019 17:45:02 +0400	[thread overview]
Message-ID: <20191211134506.1803403-5-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20191211134506.1803403-1-marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 MAINTAINERS         |  2 ++
 include/qemu/dbus.h | 18 +++++++++++++++
 util/Makefile.objs  |  3 +++
 util/dbus.c         | 55 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+)
 create mode 100644 include/qemu/dbus.h
 create mode 100644 util/dbus.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 19faa0e868..f08fb4f24e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2202,6 +2202,8 @@ F: qapi/migration.json
 D-Bus
 M: Marc-André Lureau <marcandre.lureau@redhat.com>
 S: Maintained
+F: util/dbus.c
+F: include/qemu/dbus.h
 F: docs/interop/dbus.rst
 
 Seccomp
diff --git a/include/qemu/dbus.h b/include/qemu/dbus.h
new file mode 100644
index 0000000000..efd74bef96
--- /dev/null
+++ b/include/qemu/dbus.h
@@ -0,0 +1,18 @@
+/*
+ * 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);
+
+#endif /* DBUS_H */
diff --git a/util/Makefile.objs b/util/Makefile.objs
index df124af1c5..80b76352cd 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -55,5 +55,8 @@ util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o
 util-obj-$(CONFIG_LINUX) += vfio-helpers.o
 util-obj-$(CONFIG_POSIX) += drm.o
 util-obj-y += guest-random.o
+util-obj-$(CONFIG_GIO) += dbus.o
+dbus.o-cflags = $(GIO_CFLAGS)
+dbus.o-libs = $(GIO_LIBS)
 
 stub-obj-y += filemonitor-stub.o
diff --git a/util/dbus.c b/util/dbus.c
new file mode 100644
index 0000000000..bb51870e54
--- /dev/null
+++ b/util/dbus.c
@@ -0,0 +1,55 @@
+/*
+ * 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"
+
+/*
+ * 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)
+{
+    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_report("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_report("Failed to call ListQueuedOwners: %s", err->message);
+        return NULL;
+    }
+
+    child = g_variant_get_child_value(result, 0);
+    return g_variant_dup_strv(child, NULL);
+}
-- 
2.24.0.308.g228f53135a



  parent reply	other threads:[~2019-12-11 13:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11 13:44 [PATCH v6 0/8] Add dbus-vmstate Marc-André Lureau
2019-12-11 13:44 ` [PATCH v6 1/8] vmstate: add qom interface to get id Marc-André Lureau
2019-12-11 13:45 ` [PATCH v6 2/8] vmstate: replace DeviceState with VMStateIf Marc-André Lureau
2019-12-11 13:45 ` [PATCH v6 3/8] docs: start a document to describe D-Bus usage Marc-André Lureau
2019-12-12 11:36   ` Daniel P. Berrangé
2019-12-11 13:45 ` Marc-André Lureau [this message]
2019-12-12 11:38   ` [PATCH v6 4/8] util: add dbus helper unit Daniel P. Berrangé
2019-12-11 13:45 ` [PATCH v6 5/8] Add dbus-vmstate object Marc-André Lureau
2019-12-12 12:03   ` Daniel P. Berrangé
2019-12-16  7:44     ` Marc-André Lureau
2019-12-13 16:32   ` Dr. David Alan Gilbert
2019-12-11 13:45 ` [PATCH v6 6/8] configure: add GDBUS_CODEGEN Marc-André Lureau
2019-12-12 12:05   ` Daniel P. Berrangé
2019-12-19 12:54     ` Marc-André Lureau
2019-12-11 13:45 ` [PATCH v6 7/8] dockerfiles: add dbus-daemon to some of latest distributions Marc-André Lureau
2019-12-12 12:06   ` Daniel P. Berrangé
2019-12-19 12:23     ` Marc-André Lureau
2019-12-19 12:30       ` Daniel P. Berrangé
2019-12-11 13:45 ` [PATCH v6 8/8] tests: add dbus-vmstate-test Marc-André Lureau
2019-12-12 12:11   ` Daniel P. Berrangé
2019-12-13 18:20   ` Dr. David Alan Gilbert
2019-12-16  9:58     ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191211134506.1803403-5-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=mprivozn@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.