]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
command: avoid double close in virExecWithHook
authorJán Tomko <jtomko@redhat.com>
Tue, 21 Aug 2012 09:01:44 +0000 (11:01 +0200)
committerEric Blake <eblake@redhat.com>
Tue, 21 Aug 2012 17:46:49 +0000 (11:46 -0600)
Fix possible double close in the child process after the fork in case
infd and outfd are equal, just like they are after being called from
virNetSocketNewConnectCommand.

src/util/command.c

index 7755572d4ee2acaa0f41372ee5e38e58b359001f..49ec1787c118911169df0005095a9c728ab06f91 100644 (file)
@@ -547,17 +547,13 @@ virExecWithHook(const char *const*argv,
         goto fork_error;
     }
 
-    if (infd != STDIN_FILENO && infd != null)
+    if (infd != STDIN_FILENO && infd != null && infd != childerr &&
+        infd != childout)
         VIR_FORCE_CLOSE(infd);
-    if (childout > STDERR_FILENO && childout != null) {
-        tmpfd = childout;   /* preserve childout value */
-        VIR_FORCE_CLOSE(tmpfd);
-    }
-    if (childerr > STDERR_FILENO &&
-        childerr != childout &&
-        childerr != null) {
+    if (childout > STDERR_FILENO && childout != null && childout != childerr)
+        VIR_FORCE_CLOSE(childout);
+    if (childerr > STDERR_FILENO && childerr != null)
         VIR_FORCE_CLOSE(childerr);
-    }
     VIR_FORCE_CLOSE(null);
 
     /* Initialize full logging for a while */