]> xenbits.xensource.com Git - libvirt.git/commitdiff
command: check for fork error before closing fd
authorWen Congyang <wency@cn.fujitsu.com>
Wed, 30 May 2012 09:20:44 +0000 (17:20 +0800)
committerEric Blake <eblake@redhat.com>
Thu, 31 May 2012 03:41:46 +0000 (21:41 -0600)
We should not set *outfd or *errfd if virExecWithHook() failed
because the caller may close these fds.

Bug present since v0.4.5 (commit 60ed1d2a).

src/util/command.c

index 1a225082ce2ac49990d37f2bdbc0815ee6ee3734..ba430784504110b398bc9711cbd414bdbc1378bc 100644 (file)
@@ -492,6 +492,10 @@ virExecWithHook(const char *const*argv,
     }
 
     if (pid) { /* parent */
+        if (forkRet < 0) {
+            goto cleanup;
+        }
+
         VIR_FORCE_CLOSE(null);
         if (outfd && *outfd == -1) {
             VIR_FORCE_CLOSE(pipeout[1]);
@@ -502,10 +506,6 @@ virExecWithHook(const char *const*argv,
             *errfd = pipeerr[0];
         }
 
-        if (forkRet < 0) {
-            goto cleanup;
-        }
-
         *retpid = pid;
 
         if (binary != argv[0])