- Timestamp:
- Dec 1, 2014 4:00:30 PM (10 years ago)
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 3 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 -
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r52890 r53421 1098 1098 #else 1099 1099 VBoxServiceVerbose(1, "Daemonizing...\n"); 1100 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */); 1100 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */, 1101 false /* fRespawn */); 1101 1102 if (RT_FAILURE(rc)) 1102 1103 return VBoxServiceError("Daemon failed: %Rrc\n", rc); -
trunk/src/VBox/Additions/x11/VBoxClient/main.cpp
r52647 r53421 271 271 int main(int argc, char *argv[]) 272 272 { 273 bool fDaemonise = true ;273 bool fDaemonise = true, fRespawn = true; 274 274 int rc; 275 275 const char *pcszFileName, *pcszStage; … … 311 311 fDaemonise = false; 312 312 } 313 else if (!strcmp(argv[i], "--no-respawn")) 314 { 315 fRespawn = false; 316 } 313 317 else if (!strcmp(argv[i], "--clipboard")) 314 318 { … … 373 377 VBClFatalError(("Creating pid-file path: %Rrc\n", rc)); 374 378 if (fDaemonise) 375 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */ );379 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */, fRespawn); 376 380 if (RT_FAILURE(rc)) 377 381 VBClFatalError(("Daemonizing: %Rrc\n", rc));
Note:
See TracChangeset
for help on using the changeset viewer.