[PATCH 1/7] lxc: Drop container stdio as late as possible

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

 



Makes it more likely we get useful error output in the logs

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/lxc/lxc_container.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 9ae93b5..173af07 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -751,9 +751,9 @@ static int lxcContainerChild( void *data )
 {
     lxc_child_argv_t *argv = data;
     virDomainDefPtr vmDef = argv->config;
-    int ttyfd;
+    int ttyfd = -1;
     int ret = -1;
-    char *ttyPath;
+    char *ttyPath = NULL;
     virDomainFSDefPtr root;
     virCommandPtr cmd = NULL;
 
@@ -786,16 +786,8 @@ static int lxcContainerChild( void *data )
         virReportSystemError(errno,
                              _("Failed to open tty %s"),
                              ttyPath);
-        VIR_FREE(ttyPath);
         goto cleanup;
     }
-    VIR_FREE(ttyPath);
-
-    if (lxcContainerSetStdio(argv->monitor, ttyfd) < 0) {
-        VIR_FORCE_CLOSE(ttyfd);
-        goto cleanup;
-    }
-    VIR_FORCE_CLOSE(ttyfd);
 
     if (lxcContainerSetupMounts(vmDef, root) < 0)
         goto cleanup;
@@ -806,17 +798,28 @@ static int lxcContainerChild( void *data )
 
     /* rename and enable interfaces */
     if (lxcContainerRenameAndEnableInterfaces(argv->nveths,
-                                              argv->veths) < 0)
+                                              argv->veths) < 0) {
         goto cleanup;
+    }
 
     /* drop a set of root capabilities */
     if (lxcContainerDropCapabilities() < 0)
         goto cleanup;
 
-    /* this function will only return if an error occured */
-    ret = virCommandExec(cmd);
+    if (lxcContainerSetStdio(argv->monitor, ttyfd) < 0) {
+        goto cleanup;
+    }
 
+    ret = 0;
 cleanup:
+    VIR_FREE(ttyPath);
+    VIR_FORCE_CLOSE(ttyfd);
+
+    if (ret == 0) {
+        /* this function will only return if an error occured */
+        ret = virCommandExec(cmd);
+    }
+
     virCommandFree(cmd);
     return ret;
 }
-- 
1.7.4.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]