1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00
This commit is contained in:
Wouter den Breejen 2007-07-06 19:15:05 +00:00
parent 40161d0be1
commit cc7d4c8bd7
8 changed files with 146 additions and 102 deletions

View file

@ -769,12 +769,8 @@ void killUser(uid_t uid)
//////////////////////////////////////////////////////////////////////
string runProgram(Path program, bool searchPath, const Strings & args)
{
/* Split args based on | for pipe-ing */
StringsList l;
/* Create a pipe. */
Pipe pipe;
pipe.create();
@ -809,78 +805,21 @@ string runProgram(Path program, bool searchPath, const Strings & args)
} catch (std::exception & e) {
std::cerr << "error: " << e.what() << std::endl;
}
quickExit(1);
}
/* Parent. */
pipe.writeSide.close();
string result = drainFD(pipe.readSide);
/* Wait for the child to finish. */
int status = pid.wait(true);
if (!statusOk(status))
throw Error(format("program `%1%' %2%")
% program % statusToString(status));
// Create a pipe.
Pipe pipe2;
pipe2.create();
// Fork.
Pid pid2;
pid2 = fork();
switch (pid2) {
case -1:
throw SysError("unable to fork");
case 0: // child
try {
pipe2.readSide.close();
if (dup2(pipe2.writeSide, STDOUT_FILENO) == -1)
throw SysError("dupping from-hook write side");
dup2(pipe.readSide, STDIN_FILENO);
Path s = "grep";
Strings args2;
args2.push_back("Revision");
std::vector<const char *> cargs; // careful with c_str()!
cargs.push_back(s.c_str());
for (Strings::const_iterator i = args2.begin(); i != args2.end(); ++i)
cargs.push_back(i->c_str());
cargs.push_back(0);
if (searchPath)
execvp(s.c_str(), (char * *) &cargs[0]);
else
execv(s.c_str(), (char * *) &cargs[0]);
throw SysError(format("executing `%1%'") % s);
} catch (std::exception & e) {
std::cerr << "error: " << e.what() << std::endl;
}
quickExit(1);
}
/* Parent. */
pipe2.writeSide.close();
/* wait for second ........... */
int status2 = pid2.wait(true);
if (!statusOk(status2))
throw Error(format("program `%1%' %2%")
% program % statusToString(status));
string result = drainFD(pipe2.readSide);
return result;
}
@ -1216,7 +1155,7 @@ PathSet pathSets_union(const PathSet & paths1, const PathSet & paths2)
set_union(vector1.begin(), vector1.end(),vector2.begin(), vector2.end(), back_inserter(setResult)); //Also available: set_symmetric_difference and set_intersection
PathSet diff;
for(int i=0; i<setResult.size(); i++)
for(unsigned int i=0; i<setResult.size(); i++)
diff.insert(setResult[i]);
return diff;