Changeset 23045
- Timestamp:
- 02/08/07 10:04:06 (22 months ago)
- Location:
- trunk/launchd/src
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchd.8
r20773 r23045 38 38 .Sh OPTIONS 39 39 .Bl -tag -width -indent 40 .It Fl d41 Daemonize. Useful when passing a command to launchd on the command line.42 40 .It Fl D 43 41 Debug. Prints syslog messages to stderr and adjusts logging via 44 42 .Xr syslog 3 45 43 to LOG_DEBUG. 46 .It Fl S Ar SessionType47 Instruct launchd to which session type it is.48 44 .El 49 45 .Sh OPTIONS WHEN RUN AS PID 1 -
trunk/launchd/src/launchd.c
r23042 r23045 84 84 85 85 static void signal_callback(void *, struct kevent *); 86 static void ppidexit_callback(void);87 86 static void debugshutdown_callback(void); 88 87 static void pfsystem_callback(void *, struct kevent *); 89 88 90 89 static kq_callback kqsignal_callback = signal_callback; 91 static kq_callback kqppidexit_callback = (kq_callback)ppidexit_callback;92 90 static kq_callback kqdebugshutdown_callback = (kq_callback)debugshutdown_callback; 93 91 static kq_callback kqpfsystem_callback = pfsystem_callback; … … 124 122 SIGWINCH, SIGINFO, SIGUSR1, SIGUSR2 125 123 }; 126 bool sflag = false, dflag = false,Dflag = false;124 bool sflag = false, Dflag = false; 127 125 char ldconf[PATH_MAX] = PID1LAUNCHD_CONF; 128 126 const char *h = getenv("HOME"); 129 const char *session_type = NULL;130 127 const char *optargs = NULL; 131 job_t fbj = NULL;132 128 struct stat sb; 133 129 size_t i, checkin_fdcnt = 0; 134 130 int *checkin_fds = NULL; 135 131 mach_port_t checkin_mport = MACH_PORT_NULL; 136 int ch, ker,logopts;132 int ch, logopts; 137 133 138 134 testfd_or_openfd(STDIN_FILENO, _PATH_DEVNULL, O_RDONLY); … … 201 197 optargs = "s"; 202 198 } else { 203 optargs = "D S:dh";199 optargs = "Dh"; 204 200 } 205 201 206 202 while ((ch = getopt(argc, argv, optargs)) != -1) { 207 203 switch (ch) { 208 case 'S': session_type = optarg; break; /* what type of session we're creating */209 204 case 'D': Dflag = true; break; /* debug */ 210 case 'd': dflag = true; break; /* daemonize */211 205 case 's': sflag = true; break; /* single user */ 212 206 case 'h': usage(stdout); break; /* help */ … … 223 217 /* main phase three: get the party started */ 224 218 225 if (dflag) {226 launchd_assumes(daemon(0, 0) == 0);227 }228 229 219 logopts = LOG_PID|LOG_CONS; 230 220 if (Dflag) { … … 255 245 launchd_assert(rlcj != NULL); 256 246 257 if (argv[0]) {258 fbj = job_new(root_jobmgr, FIRSTBORN_LABEL, NULL, (const char *const *)argv, NULL);259 }260 261 247 if (NULL == getenv("PATH")) { 262 248 setenv("PATH", _PATH_STDPATH, 1); … … 270 256 271 257 monitor_networking_state(); 272 273 if (session_type) {274 pid_t pp = getppid();275 276 /* As a per session launchd, we need to exit if our parent dies.277 *278 * Normally, in Unix, SIGHUP would cause us to exit, but we're a279 * daemon, and daemons use SIGHUP to signal the need to reread280 * configuration files. "Weee."281 */282 283 if (pp == 1) {284 exit(EXIT_SUCCESS);285 }286 287 ker = kevent_mod(pp, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqppidexit_callback);288 289 if (ker == -1) {290 exit(launchd_assumes(errno == ESRCH) ? EXIT_SUCCESS : EXIT_FAILURE);291 }292 }293 258 294 259 /* … … 303 268 if (!h && stat(ldconf, &sb) == 0) { 304 269 rlcj = job_dispatch(rlcj, true); 305 }306 307 if (fbj) {308 fbj = job_dispatch(fbj, true);309 270 } 310 271 … … 432 393 433 394 void 434 ppidexit_callback(void)435 {436 syslog(LOG_INFO, "Parent process exited");437 438 launchd_shutdown();439 440 /* Let's just bail for now. We should really try to wait for jobs to exit first. */441 exit(EXIT_SUCCESS);442 }443 444 void445 395 launchd_shutdown(void) 446 396 { -
trunk/launchd/src/launchd.h
r23042 r23045 27 27 #include "launchd_runtime.h" 28 28 29 #define FIRSTBORN_LABEL "com.apple.launchd.firstborn"30 29 #define READCONF_LABEL "com.apple.launchd.readconfig" 31 30 -
trunk/launchd/src/launchd_core_logic.c
r23042 r23045 264 264 time_t min_run_time; 265 265 unsigned int start_interval; 266 unsigned int checkedin:1, firstborn:1, debug:1, inetcompat:1, inetcompat_wait:1,266 unsigned int checkedin:1, anonymous:1, debug:1, inetcompat:1, inetcompat_wait:1, 267 267 ondemand:1, session_create:1, low_pri_io:1, no_init_groups:1, priv_port_has_senders:1, 268 importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload:1, 269 anonymous:1; 268 importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload:1; 270 269 mode_t mask; 271 270 unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1, … … 927 926 j->ondemand = true; 928 927 j->checkedin = true; 929 j->firstborn = (strcmp(label, FIRSTBORN_LABEL) == 0);930 928 931 929 if (prog) { … … 1761 1759 case EVFILT_PROC: 1762 1760 job_reap(j); 1763 1764 if (j->firstborn) { 1765 job_log(j, LOG_DEBUG, "first born died, begin shutdown"); 1766 launchd_shutdown(); 1767 } else { 1768 job_dispatch(j, false); 1769 } 1761 job_dispatch(j, false); 1770 1762 break; 1771 1763 case EVFILT_TIMER: … … 1880 1872 /* wait for our parent to say they've attached a kevent to us */ 1881 1873 read(_fd(execspair[1]), &c, sizeof(c)); 1882 if (j->firstborn) {1883 setpgid(getpid(), getpid());1884 if (isatty(STDIN_FILENO)) {1885 if (tcsetpgrp(STDIN_FILENO, getpid()) == -1) {1886 job_log_error(j, LOG_WARNING, "tcsetpgrp()");1887 }1888 }1889 }1890 1874 1891 1875 if (sipc) {

