summaryrefslogtreecommitdiff
path: root/mispipe.c
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-07-02 15:58:38 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-07-02 15:58:38 -0400
commitac6ea9a555dc33d0f9978b92acbb5963e68f81ae (patch)
tree87b36a53d6ad1998c4214b07a035f524cef648b3 /mispipe.c
parent6675d7c3b4b61ce03117f5878e62f31c64810dbc (diff)
downloadmoreutils-ac6ea9a555dc33d0f9978b92acbb5963e68f81ae.tar.gz
mispipe: Fix closing of extra pipe FD before starting command so it is not inherited by daemons. Closes: #533448 (Thanks, Jeremie Koenig)
Diffstat (limited to 'mispipe.c')
-rw-r--r--mispipe.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/mispipe.c b/mispipe.c
index 43ba76a..d183d04 100644
--- a/mispipe.c
+++ b/mispipe.c
@@ -107,15 +107,15 @@ static void subprocess2(const char* cmd) {
/* Make the reading end of the pipe the new standard input. */
if (dup2(filedes[0], 0) == -1)
error_with_errno("Failed (in child) redefining standard input");
+ /* Close the original file descriptor for it */
+ if (close(filedes[0]))
+ error_with_errno("Failed (in child) closing filedes[0]");
/* Close the other end of the pipe. */
if (close(filedes[1]))
error_with_errno("Failed (in child) closing filedes[1]");
/* Do the second command, and throw away the exit status. */
system(cmd);
- /* Close all the file descriptors. */
- if (close(filedes[0]))
- error_with_errno("Failed (in child) closing filedes[0]"
- " (while cleaning up)");
+ /* Close the standard input. */
if (close(0))
error_with_errno("Failed (in child) closing standard output "
" (while cleaning up)");
@@ -151,15 +151,15 @@ int main (int argc, const char ** argv) {
/* Make the writing end of the pipe the new standard output. */
if (dup2(filedes[1], 1) == -1)
error_with_errno("Failed redefining standard output");
+ /* Close the original file descriptor for it. */
+ if (close(filedes[1]))
+ error_with_errno("Failed closing filedes[1]");
/* Close the other end of the pipe. */
if (close(filedes[0]))
error_with_errno("Failed closing filedes[0]");
/* Do the first command, and (crucially) get the status. */
status_big = system(argv[1]);
- /* Close the pipe "standard output". */
- if (close(filedes[1]))
- error_with_errno("Failed closing filedes[1] (while cleaning up)");
/* Close standard output. */
if (close(1))
error_with_errno("Failed closing standard output (while cleaning up)");