[PATCH 3/3] avoid closing fd more than once when running command fails

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

 



We should not set *outfd or *errfd if virExecWithHook() failed,
because the caller may close these fds.
---
 src/util/command.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/command.c b/src/util/command.c
index 5b94f1e..aef9131 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -493,6 +493,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]);
@@ -503,10 +507,6 @@ virExecWithHook(const char *const*argv,
             *errfd = pipeerr[0];
         }
 
-        if (forkRet < 0) {
-            goto cleanup;
-        }
-
         *retpid = pid;
 
         if (binary != argv[0])
-- 
1.7.1

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