Remove some redundant close() calls

They are unnecessary because we set the close-on-exec flag.
This commit is contained in:
Eelco Dolstra 2012-11-09 16:58:51 +01:00
parent 10dcee99ed
commit 198dbe7fa1
3 changed files with 8 additions and 18 deletions

View file

@ -368,8 +368,6 @@ void commonChildInit(Pipe & logPipe)
/* Dup the write side of the logger pipe into stderr. */ /* Dup the write side of the logger pipe into stderr. */
if (dup2(logPipe.writeSide, STDERR_FILENO) == -1) if (dup2(logPipe.writeSide, STDERR_FILENO) == -1)
throw SysError("cannot pipe standard error into log file"); throw SysError("cannot pipe standard error into log file");
logPipe.readSide.close();
logPipe.writeSide.close();
/* Dup stderr to stdout. */ /* Dup stderr to stdout. */
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1) if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
@ -681,12 +679,10 @@ HookInstance::HookInstance()
if (chdir("/") == -1) throw SysError("changing into `/"); if (chdir("/") == -1) throw SysError("changing into `/");
/* Dup the communication pipes. */ /* Dup the communication pipes. */
toHook.writeSide.close();
if (dup2(toHook.readSide, STDIN_FILENO) == -1) if (dup2(toHook.readSide, STDIN_FILENO) == -1)
throw SysError("dupping to-hook read side"); throw SysError("dupping to-hook read side");
/* Use fd 4 for the builder's stdout/stderr. */ /* Use fd 4 for the builder's stdout/stderr. */
builderOut.readSide.close();
if (dup2(builderOut.writeSide, 4) == -1) if (dup2(builderOut.writeSide, 4) == -1)
throw SysError("dupping builder's stdout/stderr"); throw SysError("dupping builder's stdout/stderr");
@ -2680,8 +2676,6 @@ void SubstitutionGoal::tryToRun()
if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1) if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1)
throw SysError("cannot dup output pipe into stdout"); throw SysError("cannot dup output pipe into stdout");
outPipe.readSide.close();
outPipe.writeSide.close();
/* Pass configuration options (including those overriden /* Pass configuration options (including those overriden
with --option) to the substituter. */ with --option) to the substituter. */

View file

@ -968,8 +968,6 @@ void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter &
with --option) to the substituter. */ with --option) to the substituter. */
setenv("_NIX_OPTIONS", settings.pack().c_str(), 1); setenv("_NIX_OPTIONS", settings.pack().c_str(), 1);
fromPipe.readSide.close();
toPipe.writeSide.close();
if (dup2(toPipe.readSide, STDIN_FILENO) == -1) if (dup2(toPipe.readSide, STDIN_FILENO) == -1)
throw SysError("dupping stdin"); throw SysError("dupping stdin");
if (dup2(fromPipe.writeSide, STDOUT_FILENO) == -1) if (dup2(fromPipe.writeSide, STDOUT_FILENO) == -1)

View file

@ -871,6 +871,12 @@ string runProgram(Path program, bool searchPath, const Strings & args)
{ {
checkInterrupt(); checkInterrupt();
std::vector<const char *> cargs; /* careful with c_str()! */
cargs.push_back(program.c_str());
for (Strings::const_iterator i = args.begin(); i != args.end(); ++i)
cargs.push_back(i->c_str());
cargs.push_back(0);
/* Create a pipe. */ /* Create a pipe. */
Pipe pipe; Pipe pipe;
pipe.create(); pipe.create();
@ -885,17 +891,9 @@ string runProgram(Path program, bool searchPath, const Strings & args)
case 0: /* child */ case 0: /* child */
try { try {
pipe.readSide.close();
if (dup2(pipe.writeSide, STDOUT_FILENO) == -1) if (dup2(pipe.writeSide, STDOUT_FILENO) == -1)
throw SysError("dupping stdout"); throw SysError("dupping stdout");
std::vector<const char *> cargs; /* careful with c_str()! */
cargs.push_back(program.c_str());
for (Strings::const_iterator i = args.begin(); i != args.end(); ++i)
cargs.push_back(i->c_str());
cargs.push_back(0);
if (searchPath) if (searchPath)
execvp(program.c_str(), (char * *) &cargs[0]); execvp(program.c_str(), (char * *) &cargs[0]);
else else