Use PR_SET_PDEATHSIG to ensure child cleanup
This commit is contained in:
		
							parent
							
								
									163fdf292e
								
							
						
					
					
						commit
						809ca33806
					
				
					 3 changed files with 13 additions and 3 deletions
				
			
		|  | @ -19,6 +19,10 @@ | |||
| #include <sys/syscall.h> | ||||
| #endif | ||||
| 
 | ||||
| #ifdef __linux__ | ||||
| #include <sys/prctl.h> | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| extern char * * environ; | ||||
| 
 | ||||
|  | @ -847,7 +851,8 @@ void killUser(uid_t uid) | |||
| //////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| 
 | ||||
| pid_t startProcess(std::function<void()> fun, const string & errorPrefix) | ||||
| pid_t startProcess(std::function<void()> fun, | ||||
|     bool dieWithParent, const string & errorPrefix) | ||||
| { | ||||
|     pid_t pid = fork(); | ||||
|     if (pid == -1) throw SysError("unable to fork"); | ||||
|  | @ -855,6 +860,10 @@ pid_t startProcess(std::function<void()> fun, const string & errorPrefix) | |||
|     if (pid == 0) { | ||||
|         _writeToStderr = 0; | ||||
|         try { | ||||
| #if __linux__ | ||||
|             if (dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) | ||||
|                 throw SysError("setting death signal"); | ||||
| #endif | ||||
|             restoreAffinity(); | ||||
|             fun(); | ||||
|         } catch (std::exception & e) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue