mirror of
https://github.com/NixOS/nix
synced 2025-07-01 12:37:59 +02:00
Refactoring: Move all fork handling into a higher-order function
C++11 lambdas ftw.
This commit is contained in:
parent
1114c7bd57
commit
8e9140cfde
7 changed files with 128 additions and 206 deletions
|
@ -939,27 +939,14 @@ static void opServe(Strings opFlags, Strings opArgs)
|
|||
Pipe fromDecompressor;
|
||||
fromDecompressor.create();
|
||||
|
||||
Pid pid;
|
||||
pid = fork();
|
||||
|
||||
switch (pid) {
|
||||
|
||||
case -1:
|
||||
throw SysError("unable to fork");
|
||||
|
||||
case 0: /* child */
|
||||
try {
|
||||
fromDecompressor.readSide.close();
|
||||
if (dup2(fromDecompressor.writeSide, STDOUT_FILENO) == -1)
|
||||
throw SysError("dupping stdout");
|
||||
// FIXME: use absolute path.
|
||||
execlp(compression.c_str(), compression.c_str(), "-d", NULL);
|
||||
throw SysError(format("executing `%1%'") % compression);
|
||||
} catch (std::exception & e) {
|
||||
std::cerr << "error: " << e.what() << std::endl;
|
||||
}
|
||||
_exit(1);
|
||||
}
|
||||
Pid pid = startProcess([&]() {
|
||||
fromDecompressor.readSide.close();
|
||||
if (dup2(fromDecompressor.writeSide, STDOUT_FILENO) == -1)
|
||||
throw SysError("dupping stdout");
|
||||
// FIXME: use absolute path.
|
||||
execlp(compression.c_str(), compression.c_str(), "-d", NULL);
|
||||
throw SysError(format("executing `%1%'") % compression);
|
||||
});
|
||||
|
||||
fromDecompressor.writeSide.close();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue