libvirt/SOURCES/libvirt-virsystemd-introduc...

103 lines
2.8 KiB
Diff

From a3a5c16f04d044502eecedbef6043bce79043df9 Mon Sep 17 00:00:00 2001
Message-Id: <a3a5c16f04d044502eecedbef6043bce79043df9@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 19 Feb 2021 13:33:53 +0100
Subject: [PATCH] virsystemd: introduce virSystemdGetMachineByPID
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 385704d5a4e1c02c21fb5779fa5067cf0d8ab56c)
Conflicts:
src/util/virsystemd.c
- missing upstream glib dbus rewrite
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <7de7eae45f139e79c45731263924ae078f3e33c5.1613737828.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/virsystemd.c | 46 +++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index ca708cd1bd..394eb13f38 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -200,19 +200,24 @@ virSystemdHasLogind(void)
}
-char *
-virSystemdGetMachineNameByPID(pid_t pid)
+/**
+ * virSystemdGetMachineByPID:
+ * @conn: dbus connection
+ * @pid: pid of running VM
+ *
+ * Returns dbus object path to VM registered with machined.
+ * On error returns NULL.
+ */
+static char *
+virSystemdGetMachineByPID(DBusConnection *conn,
+ pid_t pid)
{
- DBusConnection *conn;
DBusMessage *reply = NULL;
- char *name = NULL, *object = NULL;
+ char *object = NULL;
if (virSystemdHasMachined() < 0)
goto cleanup;
- if (!(conn = virDBusGetSystemBus()))
- goto cleanup;
-
if (virDBusCallMethod(conn, &reply, NULL,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
@@ -224,12 +229,33 @@ virSystemdGetMachineNameByPID(pid_t pid)
if (virDBusMessageDecode(reply, "o", &object) < 0)
goto cleanup;
- virDBusMessageUnref(reply);
- reply = NULL;
-
VIR_DEBUG("Domain with pid %lld has object path '%s'",
(long long) pid, object);
+ cleanup:
+ virDBusMessageUnref(reply);
+
+ return object;
+}
+
+
+char *
+virSystemdGetMachineNameByPID(pid_t pid)
+{
+ DBusConnection *conn;
+ DBusMessage *reply = NULL;
+ char *name = NULL, *object = NULL;
+
+ if (virSystemdHasMachined() < 0)
+ goto cleanup;
+
+ if (!(conn = virDBusGetSystemBus()))
+ goto cleanup;
+
+ object = virSystemdGetMachineByPID(conn, pid);
+ if (!object)
+ goto cleanup;
+
if (virDBusCallMethod(conn, &reply, NULL,
"org.freedesktop.machine1",
object,
--
2.30.0