[PATCH 1/4] Unify checking for machine1 systemd service

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Both virSystemdTerminateMachine and virSystemdCreateMachine
propagate the error to tell between a non-systemd system
and a hard error.

In virSystemdGetMachineNameByPID both are treated the same,
but an error is ignored by the callers.

Split out the checks into a separate function.
---
 src/util/virsystemd.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 7ec3eee..d7a4e78 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -182,6 +182,20 @@ virSystemdMakeMachineName(const char *drivername,
     return machinename;
 }
 
+/* -2 = machine1 is not supported on this machine
+ * -1 = error
+ *  0 = machine1 is available
+ */
+static int
+virSystemdHasCreateMachine(void)
+{
+    int ret;
+    if ((ret = virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0)
+        return ret;
+
+    return virDBusIsServiceRegistered("org.freedesktop.systemd1");
+}
+
 
 char *
 virSystemdGetMachineNameByPID(pid_t pid)
@@ -190,10 +204,7 @@ virSystemdGetMachineNameByPID(pid_t pid)
     DBusMessage *reply = NULL;
     char *name = NULL, *object = NULL;
 
-    if (virDBusIsServiceEnabled("org.freedesktop.machine1") < 0)
-        goto cleanup;
-
-    if (virDBusIsServiceRegistered("org.freedesktop.systemd1") < 0)
+    if (virSystemdHasCreateMachine() < 0)
         goto cleanup;
 
     if (!(conn = virDBusGetSystemBus()))
@@ -268,11 +279,7 @@ int virSystemdCreateMachine(const char *name,
     char *slicename = NULL;
     static int hasCreateWithNetwork = 1;
 
-    ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
-    if (ret < 0)
-        return ret;
-
-    if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
+    if ((ret = virSystemdHasCreateMachine()) < 0)
         return ret;
 
     if (!(conn = virDBusGetSystemBus()))
@@ -434,11 +441,7 @@ int virSystemdTerminateMachine(const char *name)
 
     memset(&error, 0, sizeof(error));
 
-    ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
-    if (ret < 0)
-        goto cleanup;
-
-    if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
+    if ((ret = virSystemdHasCreateMachine()) < 0)
         goto cleanup;
 
     ret = -1;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux