diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-04-23 18:12:45 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-04-23 18:12:45 +0000 |
commit | ed6bb995ac029606bf1f4fec56e91655d824ec24 (patch) | |
tree | 92a0fb4a0793543e0e526bf339c5a44b76ce8d5c | |
parent | 79f1c6bf5a89a4e92fbfb8e6930086ea98877c35 (diff) | |
download | netpbm-mirror-ed6bb995ac029606bf1f4fec56e91655d824ec24.tar.gz netpbm-mirror-ed6bb995ac029606bf1f4fec56e91655d824ec24.tar.xz netpbm-mirror-ed6bb995ac029606bf1f4fec56e91655d824ec24.zip |
Don't close inherited Standard Input
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2964 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | doc/HISTORY | 4 | ||||
-rw-r--r-- | lib/libsystem.c | 24 |
2 files changed, 22 insertions, 6 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 581e42ab..69e63e01 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -25,6 +25,10 @@ not yet BJH Release 10.79.00 pnmtojpeg: fix array bounds violation in argument list. Always broken (pnmtojpeg was new to Netpbm in Netpbm 8.2 (March 2000). + libnetpbm: fix bug: pm_system_XXX closes Standard Input if you + supply a Standard Output accepter but not a Standard Input + feeder. Broken since Netpbm 10.40 (September 2007). + Windows: fix bug: pm_system_lp() and pm_system_vp() fail silently instead of with a clear error message in an environment that does not provide Unix process management. Always broken. diff --git a/lib/libsystem.c b/lib/libsystem.c index 4ff473dd..57073dce 100644 --- a/lib/libsystem.c +++ b/lib/libsystem.c @@ -436,14 +436,23 @@ pm_system2_vp(const char * const progName, */ int progStdinFd; + /* File descriptor that the processor program will get as Standard + Input + */ + bool weCreatedStdinFd; + /* This program created (opened) file descriptor 'progStdinFd', + as opposed to inheriting it. + */ pid_t feederPid; pid_t processorPid; int termStatus; - if (stdinFeeder) + if (stdinFeeder) { createPipeFeeder(stdinFeeder, feederParm, &progStdinFd, &feederPid); - else { + weCreatedStdinFd = true; + } else { progStdinFd = STDIN; + weCreatedStdinFd = false; feederPid = 0; } @@ -456,10 +465,6 @@ pm_system2_vp(const char * const progName, spawnProcessor(progName, argArray, progStdinFd, &progStdoutFd, &processorPid); - /* The child process has cloned our 'progStdinFd'; we have no - more use for our copy. - */ - close(progStdinFd); /* Dispose of the stdout from that child */ (*stdoutAccepter)(progStdoutFd, accepterParm); close(progStdoutFd); @@ -470,6 +475,13 @@ pm_system2_vp(const char * const progName, spawnProcessor(progName, argArray, progStdinFd, NULL, &processorPid); } + if (weCreatedStdinFd) { + /* The child process has cloned our 'progStdinFd'; we have no + more use for our copy. + */ + close(progStdinFd); + } + waitpid(processorPid, &termStatus, 0); if (feederPid) |