APR_RING_ENTRY(mpm_gen_info_t) link;
int gen; /* which gen? */
int active; /* number of active processes */
+ int done; /* gen finished? (whether or not active processes) */
} mpm_gen_info_t;
APR_RING_HEAD(mpm_gen_info_head_t, mpm_gen_info_t);
return rv;
}
+static void end_gen(mpm_gen_info_t *gi)
+{
+ ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, ap_server_conf,
+ "end of generation %d", gi->gen);
+ ap_run_end_generation(ap_server_conf, gi->gen);
+ APR_RING_REMOVE(gi, link);
+ APR_RING_INSERT_HEAD(unused_geninfo, gi, mpm_gen_info_t, link);
+}
+
+apr_status_t ap_mpm_end_gen_helper(void *unused) /* cleanup on pconf */
+{
+ int gen = ap_config_generation - 1; /* differs from MPM generation */
+ mpm_gen_info_t *cur;
+
+ if (geninfo == NULL) {
+ /* initial pconf teardown, MPM hasn't run */
+ return APR_SUCCESS;
+ }
+
+ cur = APR_RING_FIRST(geninfo);
+ while (cur != APR_RING_SENTINEL(geninfo, mpm_gen_info_t, link) &&
+ cur->gen != gen) {
+ cur = APR_RING_NEXT(cur, link);
+ }
+
+ if (cur == APR_RING_SENTINEL(geninfo, mpm_gen_info_t, link)) {
+ /* last child of generation already exited */
+ ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, ap_server_conf,
+ "no record of generation %d", gen);
+ }
+ else {
+ cur->done = 1;
+ if (cur->active == 0) {
+ end_gen(cur);
+ }
+ }
+
+ return APR_SUCCESS;
+}
+
/* core's child-status hook
* tracks number of remaining children per generation and
- * runs the end-generation hook when a generation finishes
+ * runs the end-generation hook when the last child of
+ * a generation exits
*/
void ap_core_child_status(server_rec *s, pid_t pid,
ap_generation_t gen, int slot,
if (!APR_RING_EMPTY(unused_geninfo, mpm_gen_info_t, link)) {
cur = APR_RING_FIRST(unused_geninfo);
APR_RING_REMOVE(cur, link);
+ cur->active = cur->done = 0;
}
else {
cur = apr_pcalloc(s->process->pool, sizeof *cur);
}
else {
--cur->active;
- if (!cur->active) {
- ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, ap_server_conf,
- "end of generation %d", gen);
- ap_run_end_generation(ap_server_conf, gen);
- APR_RING_REMOVE(cur, link);
- APR_RING_INSERT_HEAD(unused_geninfo, cur, mpm_gen_info_t, link);
+ if (!cur->active && cur->done) { /* no children, server has stopped/restarted */
+ end_gen(cur);
}
}
break;