From patchwork Fri Sep 27 13:42:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1168622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46fwgf6HMbz9sP3 for ; Sat, 28 Sep 2019 01:29:02 +1000 (AEST) Received: from localhost ([::1]:52420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDsB2-0005AM-Iw for incoming@patchwork.ozlabs.org; Fri, 27 Sep 2019 11:29:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39103) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDqWX-0006DX-66 for qemu-devel@nongnu.org; Fri, 27 Sep 2019 09:43:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDqWV-0005Q2-OF for qemu-devel@nongnu.org; Fri, 27 Sep 2019 09:43:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35884) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iDqWV-0005Pn-FK for qemu-devel@nongnu.org; Fri, 27 Sep 2019 09:43:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5C4D301A3AE for ; Fri, 27 Sep 2019 13:43:02 +0000 (UTC) Received: from localhost (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22C1710018F8; Fri, 27 Sep 2019 13:42:58 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v4 4/7] util: add dbus helper unit Date: Fri, 27 Sep 2019 17:42:21 +0400 Message-Id: <20190927134224.14550-5-marcandre.lureau@redhat.com> In-Reply-To: <20190927134224.14550-1-marcandre.lureau@redhat.com> References: <20190927134224.14550-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 27 Sep 2019 13:43:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_L?= =?utf-8?q?ureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau --- 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 219a76f0a1..dccea79d48 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2160,6 +2160,8 @@ F: qapi/migration.json D-Bus M: Marc-André Lureau 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 + +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 41bf59d127..f435cfbd64 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -54,5 +54,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); +}