diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-08-19T13·07+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-08-19T13·07+0000 |
commit | 1472cc482503a39d173b5dcd34686fd6c3c644d6 (patch) | |
tree | 30e71e70b911665d62b8b3eb87760c0192d89c7d | |
parent | 2de850479101e5a378c87d1392ea03c63ce224cf (diff) |
* Pipe /dev/null into stdin.
-rw-r--r-- | src/exec.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/exec.cc b/src/exec.cc index fdfb467cca71..d4ee88f8aaf6 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -34,6 +34,9 @@ public: }; +static string pathNullDevice = "/dev/null"; + + /* Run a program. */ void runProgram(const string & program, const Strings & args, const Environment & env) @@ -97,6 +100,13 @@ void runProgram(const string & program, if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1) throw SysError("cannot dup stderr into stdout"); + /* Reroute stdin to /dev/null. */ + int fdDevNull = open(pathNullDevice.c_str(), O_RDWR); + if (fdDevNull == -1) + throw SysError(format("cannot open `%1%'") % pathNullDevice); + if (dup2(fdDevNull, STDIN_FILENO) == -1) + throw SysError("cannot dup null device into stdin"); + /* Execute the program. This should not return. */ execve(program.c_str(), (char * *) argArr, (char * *) envArr); |