diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-09 16:58:51 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-09 16:58:51 +0100 |
commit | 198dbe7fa1807f7464ef7c15c3fd0d230f7b844e (patch) | |
tree | 9de6323624865969161d3d885463b42ca4270d57 /src/libutil | |
parent | 10dcee99ed62a775c05f34aa70449945d537e1a2 (diff) |
Remove some redundant close() calls
They are unnecessary because we set the close-on-exec flag.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index bfed96846..7e5d8bb80 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -870,7 +870,13 @@ void killUser(uid_t uid) string runProgram(Path program, bool searchPath, const Strings & args) { 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. */ Pipe pipe; pipe.create(); @@ -885,23 +891,15 @@ string runProgram(Path program, bool searchPath, const Strings & args) case 0: /* child */ try { - pipe.readSide.close(); - if (dup2(pipe.writeSide, STDOUT_FILENO) == -1) 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) execvp(program.c_str(), (char * *) &cargs[0]); else execv(program.c_str(), (char * *) &cargs[0]); throw SysError(format("executing `%1%'") % program); - + } catch (std::exception & e) { std::cerr << "error: " << e.what() << std::endl; } |