[PATCH 2/2] Implementation deficiency in virInitctlSetRunLevel v3

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

 



Use helper virProcessRunInMountNamespace in lxcDomainShutdownFlags and
lxcDomainReboot.

---
 src/lxc/lxc_driver.c |   44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index e5298d1..7f4acbe 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2694,12 +2694,21 @@ lxcConnectListAllDomains(virConnectPtr conn,
 
 
 static int
+virDomainShutdownCallback(pid_t pid ATTRIBUTE_UNUSED,
+                          void* opaque ATTRIBUTE_UNUSED)
+{
+    int rc;
+    rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF, NULL);
+    return rc;
+}
+
+
+static int
 lxcDomainShutdownFlags(virDomainPtr dom,
                        unsigned int flags)
 {
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
-    char *vroot = NULL;
     int ret = -1;
     int rc;
 
@@ -2726,14 +2735,12 @@ lxcDomainShutdownFlags(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virAsprintf(&vroot, "/proc/%llu/root",
-                    (unsigned long long)priv->initpid) < 0)
-        goto cleanup;
-
     if (flags == 0 ||
         (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
-        if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF,
-                                        vroot)) < 0) {
+        rc = virProcessRunInMountNamespace(priv->initpid,
+                                           (virProcessNamespaceCallback) virDomainShutdownCallback,
+                                           NULL);
+        if (rc < 0) {
             goto cleanup;
         }
         if (rc == 0 && flags != 0 &&
@@ -2761,7 +2768,6 @@ lxcDomainShutdownFlags(virDomainPtr dom,
     ret = 0;
 
 cleanup:
-    VIR_FREE(vroot);
     if (vm)
         virObjectUnlock(vm);
     return ret;
@@ -2773,13 +2779,22 @@ lxcDomainShutdown(virDomainPtr dom)
     return lxcDomainShutdownFlags(dom, 0);
 }
 
+
+virDomainRebootCallback(pid_t pid ATTRIBUTE_UNUSED,
+                        void* opaque ATTRIBUTE_UNUSED)
+{
+    int rc;
+    rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT, NULL);
+    return rc;
+}
+
+
 static int
 lxcDomainReboot(virDomainPtr dom,
                 unsigned int flags)
 {
     virLXCDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
-    char *vroot = NULL;
     int ret = -1;
     int rc;
 
@@ -2806,14 +2821,12 @@ lxcDomainReboot(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virAsprintf(&vroot, "/proc/%llu/root",
-                    (unsigned long long)priv->initpid) < 0)
-        goto cleanup;
-
     if (flags == 0 ||
         (flags & VIR_DOMAIN_REBOOT_INITCTL)) {
-        if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT,
-                                        vroot)) < 0) {
+        rc = virProcessRunInMountNamespace(priv->initpid,
+                                           (virProcessNamespaceCallback) virDomainRebootCallback,
+                                           NULL);
+        if (rc < 0) {
             goto cleanup;
         }
         if (rc == 0 && flags != 0 &&
@@ -2841,7 +2854,6 @@ lxcDomainReboot(virDomainPtr dom,
     ret = 0;
 
 cleanup:
-    VIR_FREE(vroot);
     if (vm)
         virObjectUnlock(vm);
     return ret;
-- 
1.7.10.4

--
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]