Changeset 5866 in vbox
- Timestamp:
- Nov 28, 2007 6:31:32 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/xclient/main.cpp
r5823 r5866 29 29 30 30 #include <sys/types.h> 31 #include <sys/stat.h> /* For umask */ 32 #include <fcntl.h> /* For open */ 31 33 #include <unistd.h> 32 34 #include <getopt.h> 33 35 36 #include <sys/time.h> /* For getrlimit */ 37 #include <sys/resource.h> /* For getrlimit */ 38 34 39 #include <X11/Xlib.h> 35 40 #include <X11/Intrinsic.h> … … 44 49 45 50 /** 46 * Become a daemon process51 * Go through the long Un*x ritual required to become a daemon process. 47 52 */ 48 53 void vboxDaemonise(void) 49 54 { 50 /* First fork and exit the parent process, so that we are sure we are not session leader. */ 55 /** rlimit structure for finding out how many open files we may have. */ 56 struct rlimit rlim; 57 58 /* To make sure that we are not currently a session leader, we must first fork and let 59 the parent process exit, as a newly created child is never session leader. This will 60 allow us to call setsid() later. */ 51 61 if (fork() != 0) 52 62 { 53 63 exit(0); 54 64 } 55 /* Detach from the controlling terminal by creating our own session. */ 65 /* Find the maximum number of files we can have open and close them all. */ 66 if (0 != getrlimit(RLIMIT_NOFILE, &rlim)) 67 { 68 /* For some reason the call failed. In that case we will just close the three 69 standard files and hope. */ 70 rlim.rlim_cur = 3; 71 } 72 for (int i = 0; i < rlim.rlim_cur; ++i) 73 { 74 close(i); 75 } 76 /* Change to the root directory to avoid keeping the one we were started in open. */ 77 chdir("/"); 78 /* Set our umask to zero. */ 79 umask(0); 80 /* And open /dev/null on stdin/out/err. */ 81 open("/dev/null", O_RDONLY); 82 open("/dev/null", O_WRONLY); 83 dup(1); 84 /* Detach from the controlling terminal by creating our own session, to avoid receiving 85 signals from the old session. */ 56 86 setsid(); 57 /* And change to the root directory to avoid holding the one we were started in open. */ 58 chdir("/"); 59 /* Close the standard files. */ 60 close(0); 61 close(1); 62 close(2); 87 /* And fork again, letting the parent exit, to make us a child of init and avoid zombies. */ 88 if (fork() != 0) 89 { 90 exit(0); 91 } 63 92 } 64 93 … … 131 160 } 132 161 } 162 if (gbDaemonise) 163 { 164 vboxDaemonise(); 165 } 133 166 /* Initialise our runtime before all else. */ 134 167 RTR3Init(false); … … 175 208 } 176 209 #endif /* SEAMLESS_LINUX defined */ 177 if (gbDaemonise)178 {179 vboxDaemonise();180 }181 210 vboxClipboardMain(); 182 211 vboxClipboardDisconnect();
Note:
See TracChangeset
for help on using the changeset viewer.