[launchd-changes] [23202] trunk/launchd/src
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 4 12:10:17 PDT 2007
Revision: 23202
http://trac.macosforge.org/projects/launchd/changeset/23202
Author: zarzycki at apple.com
Date: 2007-04-04 12:10:17 -0700 (Wed, 04 Apr 2007)
Log Message:
-----------
<rdar://problem/5111723> We need a "HopefullyExitsFirst" key for broken designs like SystemStarter
Modified Paths:
--------------
trunk/launchd/src/com.apple.SystemStarter.plist
trunk/launchd/src/launchd.plist.5
trunk/launchd/src/launchd_core_logic.c
trunk/launchd/src/liblaunch_public.h
Modified: trunk/launchd/src/com.apple.SystemStarter.plist
===================================================================
--- trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-04 15:43:36 UTC (rev 23201)
+++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-04 19:10:17 UTC (rev 23202)
@@ -21,5 +21,7 @@
<string>/Library/StartupItems</string>
<string>/System/Library/StartupItems</string>
</array>
+ <key>HopefullyExitsFirst</key>
+ <true/>
</dict>
</plist>
Modified: trunk/launchd/src/launchd.plist.5
===================================================================
--- trunk/launchd/src/launchd.plist.5 2007-04-04 15:43:36 UTC (rev 23201)
+++ trunk/launchd/src/launchd.plist.5 2007-04-04 19:10:17 UTC (rev 23202)
@@ -273,12 +273,18 @@
This optional key specifies what
.Xr nice 3
value should be applied to the daemon.
+.It Sy HopefullyExitsFirst <boolean>
+This optional key causes programs to exit earlier during system shutdown.
+This key exists because some jobs do more than flush buffers and exit like
+they're supposed to. The use of this key should be considered a
+temporary solution until the software can be changed to only flush dirty buffers
+and then exit.
.It Sy HopefullyExitsLast <boolean>
-This optional key causes programs to exit in a second wave during system
-shutdown. This key exists because some jobs don't reference count their
-clients, and therefore do not know when it is safe to exit. The use of this key
-should be considered a temporary solution until the software can be changed to
-properly reference count clients.
+This optional key causes programs to exit later during system shutdown. This
+key exists because some jobs don't reference count their clients, and therefore
+do not know when it is safe to exit. The use of this key should be considered a
+temporary solution until the software can be changed to properly reference
+count clients.
.It Sy LowPriorityIO <boolean>
This optional key specifies whether the kernel should consider this daemon to be low priority when doing file system I/O.
.It Sy LaunchOnlyOnce <boolean>
Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c 2007-04-04 15:43:36 UTC (rev 23201)
+++ trunk/launchd/src/launchd_core_logic.c 2007-04-04 19:10:17 UTC (rev 23202)
@@ -223,7 +223,9 @@
jobmgr_t parentmgr;
int reboot_flags;
unsigned int global_on_demand_cnt;
- unsigned int sent_stop_to_hopeful_jobs:1, shutting_down:1;
+ unsigned int hopefully_first_cnt;
+ unsigned int normal_active_cnt;
+ unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1;
char name[0];
};
@@ -303,7 +305,7 @@
unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1,
currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1,
wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1,
- per_user:1;
+ per_user:1, hopefully_exits_first:1;
const char label[0];
};
@@ -574,7 +576,7 @@
jobmgr_shutdown(jobmgr_t jm)
{
jobmgr_t jmi, jmn;
- job_t ji, jn;
+ job_t ji;
jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown with flags: %s", reboot_flags_to_C_names(jm->reboot_flags));
@@ -584,11 +586,11 @@
jobmgr_shutdown(jmi);
}
- LIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) {
- if (!job_active(ji)) {
- job_remove(ji);
- } else if (!ji->hopefully_exits_last) {
- job_stop(ji);
+ if (jm->hopefully_first_cnt) {
+ LIST_FOREACH(ji, &jm->jobs, sle) {
+ if (ji->p && ji->hopefully_exits_first) {
+ job_stop(ji);
+ }
}
}
@@ -974,7 +976,7 @@
/* anonymous process reaping is messy */
LIST_INSERT_HEAD(&jm->active_jobs[ACTIVE_JOB_HASH(jr->p)], jr, pid_hash_sle);
job_assumes(jr, kevent_mod(jr->p, EVFILT_PROC, EV_ADD, NOTE_EXEC|NOTE_EXIT, 0, root_jobmgr) != -1);
- if (shutdown_state) {
+ if (shutdown_state && jm->hopefully_first_cnt == 0) {
job_log(jr, LOG_APPLEONLY, "This process showed up to the party while all the guests were leaving. Odds are that it will have a miserable time. Blame PID %u: %s",
kp.kp_eproc.e_ppid, ppid_kp.kp_proc.p_comm);
}
@@ -1152,6 +1154,8 @@
case 'H':
if (strcasecmp(key, LAUNCH_JOBKEY_HOPEFULLYEXITSLAST) == 0) {
j->hopefully_exits_last = value;
+ } else if (strcasecmp(key, LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST) == 0) {
+ j->hopefully_exits_first = value;
}
break;
case 's':
@@ -1805,6 +1809,11 @@
}
}
+ if (j->hopefully_exits_first) {
+ j->mgr->hopefully_first_cnt--;
+ } else if (!j->hopefully_exits_last) {
+ j->mgr->normal_active_cnt--;
+ }
j->last_exit_status = status;
j->sent_sigkill = false;
j->p = 0;
@@ -2146,6 +2155,11 @@
job_assumes(j, runtime_close(oepair[1]) != -1);
}
j->p = c;
+ if (j->hopefully_exits_first) {
+ j->mgr->hopefully_first_cnt++;
+ } else if (!j->hopefully_exits_last) {
+ j->mgr->normal_active_cnt++;
+ }
j->forkfd = _fd(execspair[0]);
job_assumes(j, runtime_close(execspair[1]) == 0);
if (sipc) {
@@ -3236,7 +3250,7 @@
}
SLIST_FOREACH(ms, &j->machservices, sle) {
- if (ms->isActive) {
+ if (ms->recv && ms->isActive) {
return true;
}
}
@@ -3432,7 +3446,7 @@
jobmgr_do_garbage_collection(jobmgr_t jm)
{
jobmgr_t jmi, jmn;
- job_t ji;
+ job_t ji, jn;
SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) {
jobmgr_do_garbage_collection(jmi);
@@ -3450,23 +3464,44 @@
return NULL;
}
- if (jm->sent_stop_to_hopeful_jobs) {
+ if (jm->hopefully_first_cnt) {
return jm;
}
- LIST_FOREACH(ji, &jm->jobs, sle) {
- if (ji->p && !ji->anonymous && !ji->hopefully_exits_last) {
- return jm;
+ if (!jm->sent_stop_to_normal_jobs) {
+ jobmgr_log(jm, LOG_DEBUG, "Asking \"normal\" jobs to exit.");
+
+ LIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) {
+ if (!job_active(ji)) {
+ job_remove(ji);
+ } else if (!ji->hopefully_exits_last) {
+ job_stop(ji);
+ }
}
+
+ jm->sent_stop_to_normal_jobs = true;
+ return jm;
}
- jobmgr_log(jm, LOG_DEBUG, "Asking \"hopeful\" jobs to exit.");
+ if (jm->normal_active_cnt) {
+ return jm;
+ }
+ if (jm->sent_stop_to_hopefully_last_jobs) {
+ return jm;
+ }
+
+ jobmgr_log(jm, LOG_DEBUG, "Asking \"hopefully last\" jobs to exit.");
+
LIST_FOREACH(ji, &jm->jobs, sle) {
- job_stop(ji);
+ if (ji->p && ji->anonymous) {
+ continue;
+ } else if (ji->p && job_assumes(ji, ji->hopefully_exits_last)) {
+ job_stop(ji);
+ }
}
- jm->sent_stop_to_hopeful_jobs = true;
+ jm->sent_stop_to_hopefully_last_jobs = true;
return jm;
}
Modified: trunk/launchd/src/liblaunch_public.h
===================================================================
--- trunk/launchd/src/liblaunch_public.h 2007-04-04 15:43:36 UTC (rev 23201)
+++ trunk/launchd/src/liblaunch_public.h 2007-04-04 19:10:17 UTC (rev 23202)
@@ -78,6 +78,7 @@
#define LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES "UserEnvironmentVariables"
#define LAUNCH_JOBKEY_UMASK "Umask"
#define LAUNCH_JOBKEY_NICE "Nice"
+#define LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST "HopefullyExitsFirst"
#define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast"
#define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO"
#define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/b87052d6/attachment.html
More information about the launchd-changes
mailing list