Changeset 23481
- Timestamp:
- 01/11/08 09:12:59 (11 months ago)
- Location:
- trunk/launchd/src
- Files:
-
- 5 modified
-
launchd.c (modified) (3 diffs)
-
launchd_core_logic.c (modified) (22 diffs)
-
launchd_runtime.c (modified) (4 diffs)
-
launchd_runtime.h (modified) (1 diff)
-
launchd_unix_ipc.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchd.c
r23480 r23481 135 135 } 136 136 137 if ( getpid() == 1) {137 if (pid1_magic) { 138 138 pid1_magic_init(); 139 139 } else { … … 143 143 monitor_networking_state(); 144 144 145 if ( getpid() == 1) {145 if (pid1_magic) { 146 146 handle_pid1_crashes_separately(); 147 147 } … … 254 254 shutdown_in_progress = true; 255 255 256 if ( getpid() == 1) {256 if (pid1_magic) { 257 257 /* 258 258 * When this changes to a more sustainable API, update this: -
trunk/launchd/src/launchd_core_logic.c
r23480 r23481 715 715 } 716 716 717 if (do_apple_internal_logging() && jm->parentmgr == NULL && getpid() == 1) {717 if (do_apple_internal_logging() && jm->parentmgr == NULL && pid1_magic) { 718 718 runtime_set_timeout(still_alive_with_check, 5); 719 719 } … … 757 757 runtime_del_ref(); 758 758 SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); 759 } else if ( getpid() == 1) {759 } else if (pid1_magic) { 760 760 jobmgr_log(jm, LOG_DEBUG, "About to call: sync()"); 761 761 sync(); /* We're are going to rely on log timestamps to benchmark this call */ … … 1121 1121 break; 1122 1122 case 1: 1123 if ( getpid() != 1) {1123 if (!pid1_magic) { 1124 1124 /* we cannot possibly find a parent job_t that is useful in this function */ 1125 1125 break; … … 2525 2525 runtime_closelog(); /* HACK -- force 'start' time to be set */ 2526 2526 2527 if ( getpid() == 1) {2527 if (pid1_magic) { 2528 2528 int64_t now = runtime_get_wall_time(); 2529 2529 … … 4205 4205 job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, exc_port, 4206 4206 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); 4207 } else if ( getpid() == 1&& the_exception_server) {4207 } else if (pid1_magic && the_exception_server) { 4208 4208 mach_port_t mhp = mach_host_self(); 4209 4209 job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, … … 4255 4255 break; 4256 4256 } 4257 } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT) == 0 && getpid() == 1) {4257 } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT) == 0 && pid1_magic) { 4258 4258 if (which_port > HOST_MAX_SPECIAL_KERNEL_PORT) { 4259 4259 job_assumes(ms->job, (errno = host_set_special_port(mhp, which_port, ms->port)) == KERN_SUCCESS); … … 4388 4388 struct kinfo_proc *kp; 4389 4389 4390 if (likely(jm->parentmgr || getpid() != 1)) {4390 if (likely(jm->parentmgr || !pid1_magic)) { 4391 4391 return; 4392 4392 } … … 4484 4484 jobmgr_assumes(jmr, jm != NULL); 4485 4485 jmr->jm_port = transfer_port; 4486 } else if (!jm && getpid() != 1) {4486 } else if (!jm && !pid1_magic) { 4487 4487 char *trusted_fd = getenv(LAUNCHD_TRUSTED_FD_ENV); 4488 4488 name_t service_buf; … … 5277 5277 /* XXX - This code should go away once the per session launchd is integrated with the rest of the system */ 5278 5278 #ifdef LET_MERE_MORTALS_ADD_SERVERS_TO_PID1 5279 if ( getpid() == 1) {5279 if (pid1_magic) { 5280 5280 if (unlikely(ldc.euid && server_uid && (ldc.euid != server_uid))) { 5281 5281 job_log(j, LOG_WARNING, "Server create: \"%s\": Will run as UID %d, not UID %d as they told us to", … … 5663 5663 } 5664 5664 5665 if (unlikely( getpid() != 1)) {5665 if (unlikely(!pid1_magic)) { 5666 5666 return BOOTSTRAP_NOT_PRIVILEGED; 5667 5667 } … … 5732 5732 ensure_root_bkgd_setup(void) 5733 5733 { 5734 if (likely(background_jobmgr) || getpid() != 1) {5734 if (likely(background_jobmgr) || !pid1_magic) { 5735 5735 return; 5736 5736 } … … 5758 5758 runtime_get_caller_creds(&ldc); 5759 5759 5760 if (unlikely( getpid() != 1)) {5760 if (unlikely(!pid1_magic)) { 5761 5761 job_log(j, LOG_ERR, "Only PID 1 supports per user launchd lookups."); 5762 5762 return BOOTSTRAP_NOT_PRIVILEGED; … … 5897 5897 */ 5898 5898 if (unlikely(j->anonymous && job_get_bs(j)->parentmgr == NULL && ldc.uid != 0 && ldc.uid != getuid() && ldc.uid != 92)) { 5899 if ( getpid() == 1) {5899 if (pid1_magic) { 5900 5900 return VPROC_ERR_TRY_PER_USER; 5901 5901 } else { … … 5942 5942 runtime_get_caller_creds(&ldc); 5943 5943 5944 if (unlikely( getpid() == 1&& j->anonymous && job_get_bs(j)->parentmgr == NULL && ldc.uid != 0 && ldc.euid != 0)) {5944 if (unlikely(pid1_magic && j->anonymous && job_get_bs(j)->parentmgr == NULL && ldc.uid != 0 && ldc.euid != 0)) { 5945 5945 return VPROC_ERR_TRY_PER_USER; 5946 5946 } … … 5982 5982 /* The previous routine moved the reply port, we're forced to return MIG_NO_REPLY now */ 5983 5983 return MIG_NO_REPLY; 5984 } else if ( getpid() == 1&& j->anonymous && ldc.euid >= 500 && strcasecmp(job_get_bs(j)->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) {5984 } else if (pid1_magic && j->anonymous && ldc.euid >= 500 && strcasecmp(job_get_bs(j)->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) { 5985 5985 /* 5986 5986 * 5240036 Should start background session when a lookup of CCacheServer occurs … … 6114 6114 } else if (strcasecmp(jmi->name, where) == 0) { 6115 6115 goto jm_found; 6116 } else if (strcasecmp(jmi->name, VPROCMGR_SESSION_BACKGROUND) == 0 && getpid() == 1) {6116 } else if (strcasecmp(jmi->name, VPROCMGR_SESSION_BACKGROUND) == 0 && pid1_magic) { 6117 6117 SLIST_FOREACH(jmi2, &jmi->submgrs, sle) { 6118 6118 if (strcasecmp(jmi2->name, where) == 0) { … … 6163 6163 6164 6164 if (j->mgr->session_initialized) { 6165 if (ldc.uid == 0 && getpid() == 1) {6165 if (ldc.uid == 0 && pid1_magic) { 6166 6166 if (strcmp(j->mgr->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) { 6167 6167 job_t ji, jn; … … 6201 6201 goto out; 6202 6202 } 6203 } else if (ldc.uid == 0 && getpid() == 1&& strcmp(session_type, VPROCMGR_SESSION_STANDARDIO) == 0) {6203 } else if (ldc.uid == 0 && pid1_magic && strcmp(session_type, VPROCMGR_SESSION_STANDARDIO) == 0) { 6204 6204 ensure_root_bkgd_setup(); 6205 6205 … … 6335 6335 jm = j->mgr; 6336 6336 6337 if (unlikely( getpid() != 1)) {6337 if (unlikely(!pid1_magic)) { 6338 6338 job_log(j, LOG_ERR, "Only the system launchd will transfer Mach sub-bootstraps."); 6339 6339 return BOOTSTRAP_NOT_PRIVILEGED; … … 6607 6607 } 6608 6608 6609 if (unlikely( getpid() == 1&& ldc.euid && ldc.uid)) {6609 if (unlikely(pid1_magic && ldc.euid && ldc.uid)) { 6610 6610 job_log(j, LOG_DEBUG, "Punting spawn to per-user-context"); 6611 6611 return VPROC_ERR_TRY_PER_USER; … … 6633 6633 job_reparent_hack(jr, NULL); 6634 6634 6635 if ( getpid() == 1) {6635 if (pid1_magic) { 6636 6636 jr->mach_uid = ldc.uid; 6637 6637 } … … 6671 6671 jobmgr_init(bool sflag) 6672 6672 { 6673 const char *root_session_type = getpid() == 1? VPROCMGR_SESSION_SYSTEM : VPROCMGR_SESSION_BACKGROUND;6673 const char *root_session_type = pid1_magic ? VPROCMGR_SESSION_SYSTEM : VPROCMGR_SESSION_BACKGROUND; 6674 6674 6675 6675 launchd_assert((root_jobmgr = jobmgr_new(NULL, MACH_PORT_NULL, MACH_PORT_NULL, sflag, root_session_type)) != NULL); -
trunk/launchd/src/launchd_runtime.c
r23479 r23481 121 121 static sigset_t sigign_set; 122 122 static FILE *ourlogfile; 123 123 bool pid1_magic; 124 124 125 125 INTERNAL_ABI mach_port_t … … 1159 1159 struct runtime_syslog_attr attr = { 1160 1160 "com.apple.launchd", "com.apple.launchd", 1161 getpid() == 1? "System" : "Background",1161 pid1_magic ? "System" : "Background", 1162 1162 pri, getuid(), getpid(), getpid() 1163 1163 }; … … 1327 1327 launchd_assumes(STAILQ_EMPTY(&logmsg_queue)); 1328 1328 return; 1329 } else if ( getpid() != 1) {1329 } else if (!pid1_magic) { 1330 1330 if (runtime_log_pack(&outval, &outvalCnt) == 0) { 1331 1331 launchd_assumes(_vprocmgr_log_forward(inherited_bootstrap_port, (void *)outval, outvalCnt) == NULL); … … 1606 1606 tbi_float_val = tbi.numer; 1607 1607 tbi_float_val /= tbi.denom; 1608 } 1608 1609 if (getpid() == 1) { 1610 pid1_magic = true; 1611 } 1612 } -
trunk/launchd/src/launchd_runtime.h
r23480 r23481 104 104 typedef INTERNAL_ABI void (*timeout_callback)(void); 105 105 106 extern bool pid1_magic; 107 106 108 INTERNAL_ABI mach_port_t runtime_get_kernel_port(void); 107 109 -
trunk/launchd/src/launchd_unix_ipc.c
r23480 r23481 103 103 sun.sun_family = AF_UNIX; 104 104 105 if ( getpid() == 1) {105 if (pid1_magic) { 106 106 strcpy(ourdir, LAUNCHD_SOCK_PREFIX); 107 107 strncpy(sun.sun_path, LAUNCHD_SOCK_PREFIX "/sock", sizeof(sun.sun_path)); … … 459 459 } 460 460 461 if (/* XXX readcfg_pid && */ getpid() == 1&& (i == RLIMIT_NOFILE || i == RLIMIT_NPROC)) {461 if (/* XXX readcfg_pid && */ pid1_magic && (i == RLIMIT_NOFILE || i == RLIMIT_NPROC)) { 462 462 int gmib[] = { CTL_KERN, KERN_MAXPROC }; 463 463 int pmib[] = { CTL_KERN, KERN_MAXPROCPERUID };

