From ac6ea9a555dc33d0f9978b92acbb5963e68f81ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 2 Jul 2009 15:58:38 -0400 Subject: mispipe: Fix closing of extra pipe FD before starting command so it is not inherited by daemons. Closes: #533448 (Thanks, Jeremie Koenig) --- mispipe.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'mispipe.c') 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)"); -- cgit v1.2.3