diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-07-10T14·50+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-07-10T14·58+0200 |
commit | 8e9140cfdef9dbd1eb61e4c75c91d452ab5e4a74 (patch) | |
tree | d4480372c993c09c073e3561f3966f7595bcf2aa /src/nix-store/nix-store.cc | |
parent | 1114c7bd57bcab16255d5db5e6f66ae8dece7b1e (diff) |
Refactoring: Move all fork handling into a higher-order function
C++11 lambdas ftw.
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r-- | src/nix-store/nix-store.cc | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index bb5a9e2e0ba2..28b205b1fd7d 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -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(); |