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

[libvirt] [PATCH v3 06/12] LXC: Move creating /dev/ptmx to virLXCControllerSetupDevPTS



Make codes clearer and reduce some virAsprintf.

Signed-off-by: Gao feng <gaofeng cn fujitsu com>
---
 src/lxc/lxc_controller.c | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index e9808f3..7d10660 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1245,7 +1245,6 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
 {
     size_t i;
     int ret = -1;
-    char *ptmx = NULL;
     char *path = NULL;
     const struct {
         int maj;
@@ -1283,30 +1282,8 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
         VIR_FREE(path);
     }
 
-    if (virAsprintf(&ptmx, "/%s/%s.devpts/ptmx",
-                    LXC_STATE_DIR, ctrl->def->name) < 0) {
-        virReportOOMError();
-        goto out;
-    }
-
-    if (access(ptmx, W_OK)) {
-        if (virAsprintf(&path, "/%s/%s.dev/ptmx",
-                        LXC_STATE_DIR, ctrl->def->name)) {
-            virReportOOMError();
-            goto out;
-        }
-        /* Legacy devpts, so we need to just use shared one */
-        dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
-        if (mknod(path, S_IFCHR, dev) < 0 ||
-            chmod(path, 0666)) {
-            virReportSystemError(errno,  _("Failed to make device %s"), path);
-            goto out;
-        }
-    }
-
     ret = 0;
 out:
-    VIR_FREE(ptmx);
     VIR_FREE(path);
     return ret;
 }
@@ -1492,6 +1469,7 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
     char *mount_options = NULL;
     char *opts = NULL;
     char *devpts = NULL;
+    char *path = NULL;
     int ret = -1;
 
     VIR_DEBUG("Setting up private /dev/pts");
@@ -1537,9 +1515,25 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
         goto cleanup;
     }
 
+    if (access(ctrl->devptmx, W_OK) < 0) {
+        if (virAsprintf(&path, "/%s/%s.dev/ptmx",
+                        LXC_STATE_DIR, ctrl->def->name)) {
+            virReportOOMError();
+            goto cleanup;
+        }
+        /* Legacy devpts, so we need to just use shared one */
+        dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
+        if (mknod(path, S_IFCHR, dev) < 0 ||
+            chmod(path, 0666)) {
+            virReportSystemError(errno,  _("Failed to make device %s"), path);
+            goto cleanup;
+        }
+    }
+
     ret = 0;
 
 cleanup:
+    VIR_FREE(path);
     VIR_FREE(opts);
     VIR_FREE(devpts);
     VIR_FREE(mount_options);
@@ -1708,10 +1702,10 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
     if (virLXCControllerSetupResourceLimits(ctrl, cgroup) < 0)
         goto cleanup;
 
-    if (virLXCControllerSetupDevPTS(ctrl) < 0)
+    if (virLXCControllerPopulateDevices(ctrl) < 0)
         goto cleanup;
 
-    if (virLXCControllerPopulateDevices(ctrl) < 0)
+    if (virLXCControllerSetupDevPTS(ctrl) < 0)
         goto cleanup;
 
     if (virLXCControllerSetupFuse(ctrl) < 0)
-- 
1.8.1.4


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