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
				
			
		|  | @ -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, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue