diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-12-19 03:33:59 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-12-19 03:33:59 +0000 |
commit | 9b1a64193bda3a0ea8d83f1acf50eeea73473f7c (patch) | |
tree | 00ea9f5c0e1e70bdfae93b6656edb972fce6f535 /lib/libsystem.c | |
parent | 0dd9f22f581baa8e479feb37d4693430b77fc4d3 (diff) | |
download | netpbm-mirror-9b1a64193bda3a0ea8d83f1acf50eeea73473f7c.tar.gz netpbm-mirror-9b1a64193bda3a0ea8d83f1acf50eeea73473f7c.tar.xz netpbm-mirror-9b1a64193bda3a0ea8d83f1acf50eeea73473f7c.zip |
Don't try to swap user's input fd with stdin when it is already stdin. Same for output
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1060 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libsystem.c')
-rw-r--r-- | lib/libsystem.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/libsystem.c b/lib/libsystem.c index 31c23bf6..2b00191f 100644 --- a/lib/libsystem.c +++ b/lib/libsystem.c @@ -54,26 +54,31 @@ execProgram(const char * const progName, /* Make stdinFd Standard Input. Make stdoutFd Standard Output. */ - stdinSaveFd = dup(STDIN); - stdoutSaveFd = dup(STDOUT); - - close(STDIN); - close(STDOUT); - - dup2(stdinFd, STDIN); - dup2(stdoutFd, STDOUT); + if (stdinFd != STDIN) { + stdinSaveFd = dup(STDIN); + close(STDIN); + dup2(stdinFd, STDIN); + } + if (stdoutFd != STDOUT) { + stdoutSaveFd = dup(STDOUT); + close(STDOUT); + dup2(stdoutFd, STDOUT); + } rc = execvp(progName, (char **)argArray); execErrno = errno; - close(STDIN); - close(STDOUT); - dup2(stdinSaveFd, STDIN); - dup2(stdoutSaveFd, STDOUT); - close(stdinSaveFd); - close(stdoutSaveFd); - + if (stdinFd != STDIN) { + close(STDIN); + dup2(stdinSaveFd, STDIN); + close(stdinSaveFd); + } + if (stdoutFd != STDOUT) { + close(STDOUT); + dup2(stdoutSaveFd, STDOUT); + close(stdoutSaveFd); + } if (rc < 0) pm_error("Unable to exec '%s' " "(i.e. the program did not run at all). " |