diff options
Diffstat (limited to 'lib/libsystem.c')
-rw-r--r-- | lib/libsystem.c | 24 |
1 files changed, 18 insertions, 6 deletions
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) |