[libvirt PATCH 11/15] systemd: register machines against session service

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

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

machined could quite easily support session management:
https://github.com/systemd/systemd/pull/15312

Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
 src/util/virsystemd.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 14d680532f..31f5498438 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -148,16 +148,18 @@ void virSystemdHasLogindResetCachedValue(void)
  *  0 = machine1 is available
  */
 static int
-virSystemdHasMachined(void)
+virSystemdHasMachined(DBusConnection **conn)
 {
     int ret;
     int val;
 
+    *conn = geteuid() ? virDBusGetSessionBus() : virDBusGetSystemBus();
+
     val = g_atomic_int_get(&virSystemdHasMachinedCachedValue);
     if (val != -1)
         return val;
 
-    if ((ret = virDBusSystemIsServiceEnabled("org.freedesktop.machine1")) < 0) {
+    if ((ret = virDBusIsServiceEnabled(*conn, "org.freedesktop.machine1")) < 0) {
         if (ret == -2)
             g_atomic_int_set(&virSystemdHasMachinedCachedValue, -2);
         return ret;
@@ -199,10 +201,7 @@ virSystemdGetMachineNameByPID(pid_t pid)
     DBusMessage *reply = NULL;
     char *name = NULL, *object = NULL;
 
-    if (virSystemdHasMachined() < 0)
-        goto cleanup;
-
-    if (!(conn = virDBusGetSystemBus()))
+    if (virSystemdHasMachined(&conn) < 0)
         goto cleanup;
 
     if (virDBusCallMethod(conn, &reply, NULL,
@@ -279,12 +278,9 @@ int virSystemdCreateMachine(const char *name,
     char *scopename = NULL;
     static int hasCreateWithNetwork = 1;
 
-    if ((ret = virSystemdHasMachined()) < 0)
+    if ((ret = virSystemdHasMachined(&conn)) < 0)
         return ret;
 
-    if (!(conn = virDBusGetSystemBus()))
-        return -1;
-
     ret = -1;
 
     creatorname = g_strdup_printf("libvirt-%s", drivername);
@@ -459,14 +455,11 @@ int virSystemdTerminateMachine(const char *name)
 
     memset(&error, 0, sizeof(error));
 
-    if ((ret = virSystemdHasMachined()) < 0)
+    if ((ret = virSystemdHasMachined(&conn)) < 0)
         goto cleanup;
 
     ret = -1;
 
-    if (!(conn = virDBusGetSystemBus()))
-        goto cleanup;
-
     /*
      * The systemd DBus API we're invoking has the
      * following signature
-- 
2.26.0.rc2.42.g98cedd0233





[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