diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-22 09:51:44 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-22 09:51:44 +0000 |
commit | c9fbd2dfd51eebcb561f9b548c10c68ad89652e5 (patch) | |
tree | 623a3303d6ad1bb4af9c7b63754f2693af895e16 /src/libstore/store.cc | |
parent | 155d7c8dfa46da054beaf37d6415d52613e2bb17 (diff) |
* Wrapper class around pids.
Diffstat (limited to 'src/libstore/store.cc')
-rw-r--r-- | src/libstore/store.cc | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 59d4430fd..2ec93d63b 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -127,21 +127,22 @@ void copyPath(const Path & src, const Path & dst) use a thread). */ /* Create a pipe. */ - int fds[2]; - if (pipe(fds) == -1) throw SysError("creating pipe"); + Pipe pipe; + pipe.create(); /* Fork. */ - pid_t pid; - switch (pid = fork()) { + Pid pid; + pid = fork(); + switch (pid) { case -1: throw SysError("unable to fork"); case 0: /* child */ try { - close(fds[1]); + pipe.writeSide.close(); CopySource source; - source.fd = fds[0]; + source.fd = pipe.readSide; restorePath(dst, source); _exit(0); } catch (exception & e) { @@ -150,19 +151,16 @@ void copyPath(const Path & src, const Path & dst) _exit(1); } - close(fds[0]); - /* Parent. */ + pipe.readSide.close(); + CopySink sink; - sink.fd = fds[1]; + sink.fd = pipe.writeSide; dumpPath(src, sink); /* Wait for the child to finish. */ - int status; - if (waitpid(pid, &status, 0) != pid) - throw SysError("waiting for child"); - + int status = pid.wait(true); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) throw Error(format("cannot copy `%1% to `%2%': child %3%") % src % dst % statusToString(status)); |