From 8e9140cfdef9dbd1eb61e4c75c91d452ab5e4a74 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 10 Jul 2014 16:50:51 +0200 Subject: Refactoring: Move all fork handling into a higher-order function C++11 lambdas ftw. --- src/libutil/util.hh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libutil/util.hh') diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 07c027a1f9..ad0d377a4f 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -237,6 +238,7 @@ class Pid int killSignal; public: Pid(); + Pid(pid_t pid); ~Pid(); void operator =(pid_t pid); operator pid_t(); @@ -252,6 +254,11 @@ public: void killUser(uid_t uid); +/* Fork a process that runs the given function, and return the child + pid to the caller. */ +pid_t startProcess(std::function fun, const string & errorPrefix = "error: "); + + /* Run a program and return its stdout in a string (i.e., like the shell backtick operator). */ string runProgram(Path program, bool searchPath = false, -- cgit 1.4.1