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