about summary refs log tree commit diff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-10T14·50+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-10T14·58+0200
commit8e9140cfdef9dbd1eb61e4c75c91d452ab5e4a74 (patch)
treed4480372c993c09c073e3561f3966f7595bcf2aa /src/libutil/util.hh
parent1114c7bd57bcab16255d5db5e6f66ae8dece7b1e (diff)
Refactoring: Move all fork handling into a higher-order function
C++11 lambdas ftw.
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 07c027a1f919..ad0d377a4f5e 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -7,6 +7,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <signal.h>
+#include <functional>
 
 #include <cstdio>
 
@@ -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<void()> 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,