Changeset 53421 in vbox for trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDaemonize.cpp
- Timestamp:
- Dec 1, 2014 4:00:30 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDaemonize.cpp
r48938 r53421 43 43 # include <sys/types.h> 44 44 # include <sys/stat.h> 45 # include <sys/wait.h> 45 46 # include <stdio.h> 46 47 # include <fcntl.h> … … 66 67 * @param fNoChDir Pass false to change working directory to root. 67 68 * @param fNoClose Pass false to redirect standard file streams to /dev/null. 69 * @param fRespawn Restart the daemonised process after five seconds if it 70 * terminates abnormally. 68 71 * 69 72 * @todo Use RTProcDaemonize instead of this. 70 */ 71 VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose) 73 * @todo Implement fRespawn on OS/2. 74 * @todo Make the respawn interval configurable. But not until someone 75 * actually needs that. 76 */ 77 VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose, bool fRespawn) 72 78 { 73 79 #if defined(RT_OS_OS2) … … 76 82 DosGetInfoBlocks(&pTib, &pPib); 77 83 84 AssertRelease(!fRespawn); 78 85 /* Get the full path to the executable. */ 79 86 char szExe[CCHMAXPATH]; … … 211 218 # endif /* RT_OS_LINUX */ 212 219 220 if (fRespawn) 221 /* We implement re-spawning as a third fork(), with the parent process 222 * monitoring the child and re-starting it after a delay if it exits 223 * abnormally. */ 224 for (;;) 225 { 226 int iStatus, rcWait; 227 228 pid = fork(); 229 if (pid == -1) 230 return RTErrConvertFromErrno(errno); 231 if (pid == 0) 232 return VINF_SUCCESS; 233 do 234 rcWait = waitpid(pid, &iStatus, 0); 235 while (rcWait == -1 && errno == EINTR); 236 if (rcWait == -1) 237 exit(1); 238 if (WIFEXITED(iStatus) && WEXITSTATUS(iStatus) == 0) 239 exit(0); 240 sleep(5); 241 } 213 242 return VINF_SUCCESS; 214 243 #endif
Note:
See TracChangeset
for help on using the changeset viewer.