static int requests_this_child;
static int num_listensocks = 0;
static int resource_shortage = 0;
+static int mpm_state = AP_MPMQ_STARTING;
typedef struct worker_wakeup_info worker_wakeup_info;
return;
}
terminate_mode = mode;
+ mpm_state = AP_MPMQ_STOPPING;
workers_may_exit = 1;
worker_stack_term(idle_worker_stack);
case AP_MPMQ_MAX_DAEMONS:
*result = ap_daemons_limit;
return APR_SUCCESS;
+ case AP_MPMQ_MPM_STATE:
+ *result = mpm_state;
+ return APR_SUCCESS;
}
return APR_ENOTIMPL;
}
static void clean_child_exit(int code) __attribute__ ((noreturn));
static void clean_child_exit(int code)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (pchild) {
apr_pool_destroy(pchild);
}
static void ap_start_shutdown(void)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending == 1) {
/* Um, is this _probably_ not an error, if the user has
* tried to do a shutdown twice quickly, so we won't
/* do a graceful restart if graceful == 1 */
static void ap_start_restart(int graceful)
{
-
+ mpm_state = AP_MPMQ_STOPPING;
if (restart_pending == 1) {
/* Probably not an error - don't bother reporting it */
return;
apr_threadattr_t *thread_attr;
apr_thread_t *start_thread_id;
+ mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
+ * child initializes
+ */
+
ap_my_pid = getpid();
ap_fatal_signal_child_setup(ap_server_conf);
apr_pool_create(&pchild, pconf);
clean_child_exit(APEXIT_CHILDFATAL);
}
+ mpm_state = AP_MPMQ_RUNNING;
+
/* If we are only running in one_process mode, we will want to
* still handle signals. */
if (one_process) {
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't create accept lock");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't set permissions on cross-process lock; "
"check User and Group directives");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
}
if (!is_graceful) {
if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
/* fix the generation number in the global score; we just got a new,
apr_proc_mutex_defname());
#endif
restart_pending = shutdown_pending = 0;
+ mpm_state = AP_MPMQ_RUNNING;
server_main_loop(remaining_children_to_start);
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending) {
/* Time to gracefully shut down:
ap_directive_t *max_clients = NULL;
apr_status_t rv;
+ mpm_state = AP_MPMQ_STARTING;
+
/* make sure that "ThreadsPerChild" gets set before "MaxClients" */
for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
one_process = 0;
ap_hook_open_logs(leader_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
- ap_hook_pre_config(leader_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+ /* we need to set the MPM state before other pre-config hooks use MPM query
+ * to retrieve it, so register as REALLY_FIRST
+ */
+ ap_hook_pre_config(leader_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
}
static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
static int requests_this_child;
static int num_listensocks = 0;
static int resource_shortage = 0;
+static int mpm_state = AP_MPMQ_STARTING;
/* The structure used to pass unique initialization info to each thread */
typedef struct {
return;
}
terminate_mode = mode;
+ mpm_state = AP_MPMQ_STOPPING;
/* in case we weren't called from the listener thread, wake up the
* listener thread
case AP_MPMQ_MAX_DAEMONS:
*result = ap_daemons_limit;
return APR_SUCCESS;
+ case AP_MPMQ_MPM_STATE:
+ *result = mpm_state;
+ return APR_SUCCESS;
}
return APR_ENOTIMPL;
}
static void clean_child_exit(int code) __attribute__ ((noreturn));
static void clean_child_exit(int code)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (pchild) {
apr_pool_destroy(pchild);
}
static void ap_start_shutdown(void)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending == 1) {
/* Um, is this _probably_ not an error, if the user has
* tried to do a shutdown twice quickly, so we won't
/* do a graceful restart if graceful == 1 */
static void ap_start_restart(int graceful)
{
-
+ mpm_state = AP_MPMQ_STOPPING;
if (restart_pending == 1) {
/* Probably not an error - don't bother reporting it */
return;
apr_threadattr_t *thread_attr;
apr_thread_t *start_thread_id;
+ mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
+ * child initializes
+ */
ap_my_pid = getpid();
ap_fatal_signal_child_setup(ap_server_conf);
apr_pool_create(&pchild, pconf);
clean_child_exit(APEXIT_CHILDFATAL);
}
+ mpm_state = AP_MPMQ_RUNNING;
+
/* If we are only running in one_process mode, we will want to
* still handle signals. */
if (one_process) {
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't create accept lock");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't set permissions on cross-process lock; "
"check User and Group directives");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
}
if (!is_graceful) {
if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
/* fix the generation number in the global score; we just got a new,
apr_proc_mutex_defname());
#endif
restart_pending = shutdown_pending = 0;
+ mpm_state = AP_MPMQ_RUNNING;
server_main_loop(remaining_children_to_start);
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending) {
/* Time to gracefully shut down:
ap_directive_t *max_clients = NULL;
apr_status_t rv;
+ mpm_state = AP_MPMQ_STARTING;
+
/* make sure that "ThreadsPerChild" gets set before "MaxClients" */
for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
one_process = 0;
ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
- ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+ /* we need to set the MPM state before other pre-config hooks use MPM query
+ * to retrieve it, so register as REALLY_FIRST
+ */
+ ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
}
static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
static int resource_shortage = 0;
static fd_queue_t *worker_queue;
static fd_queue_info_t *worker_queue_info;
+static int mpm_state = AP_MPMQ_STARTING;
/* The structure used to pass unique initialization info to each thread */
typedef struct {
return;
}
terminate_mode = mode;
+ mpm_state = AP_MPMQ_STOPPING;
/* in case we weren't called from the listener thread, wake up the
* listener thread
case AP_MPMQ_MAX_DAEMONS:
*result = ap_daemons_limit;
return APR_SUCCESS;
+ case AP_MPMQ_MPM_STATE:
+ *result = mpm_state;
+ return APR_SUCCESS;
}
return APR_ENOTIMPL;
}
static void clean_child_exit(int code) __attribute__ ((noreturn));
static void clean_child_exit(int code)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (pchild) {
apr_pool_destroy(pchild);
}
static void ap_start_shutdown(void)
{
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending == 1) {
/* Um, is this _probably_ not an error, if the user has
* tried to do a shutdown twice quickly, so we won't
/* do a graceful restart if graceful == 1 */
static void ap_start_restart(int graceful)
{
-
+ mpm_state = AP_MPMQ_STOPPING;
if (restart_pending == 1) {
/* Probably not an error - don't bother reporting it */
return;
continue;
}
- /* apr_poll() will only return errors in catastrophic
+ /* apr_pollset_poll() will only return errors in catastrophic
* circumstances. Let's try exiting gracefully, for now. */
ap_log_error(APLOG_MARK, APLOG_ERR, rv,
(const server_rec *) ap_server_conf,
* "life_status" is almost right, but it's in the worker's structure, and
* the name could be clearer. gla
*/
+/*
+ while (1) {
+ apr_sleep(apr_time_from_sec(10));
+ }
+*/
apr_thread_exit(thd, APR_SUCCESS);
return NULL;
}
apr_threadattr_t *thread_attr;
apr_thread_t *start_thread_id;
+ mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
+ * child initializes
+ */
ap_my_pid = getpid();
ap_fatal_signal_child_setup(ap_server_conf);
apr_pool_create(&pchild, pconf);
clean_child_exit(APEXIT_CHILDFATAL);
}
+ mpm_state = AP_MPMQ_RUNNING;
+
/* If we are only running in one_process mode, we will want to
* still handle signals. */
if (one_process) {
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't create accept lock");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
"Couldn't set permissions on cross-process lock; "
"check User and Group directives");
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
}
if (!is_graceful) {
if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
+ mpm_state = AP_MPMQ_STOPPING;
return 1;
}
/* fix the generation number in the global score; we just got a new,
apr_proc_mutex_defname());
#endif
restart_pending = shutdown_pending = 0;
-
+ mpm_state = AP_MPMQ_RUNNING;
+
server_main_loop(remaining_children_to_start);
+ mpm_state = AP_MPMQ_STOPPING;
if (shutdown_pending) {
/* Time to gracefully shut down:
ap_directive_t *max_clients = NULL;
apr_status_t rv;
+ mpm_state = AP_MPMQ_STARTING;
+
/* make sure that "ThreadsPerChild" gets set before "MaxClients" */
for (pdir = ap_conftree; pdir != NULL; pdir = pdir->next) {
if (strncasecmp(pdir->directive, "ThreadsPerChild", 15) == 0) {
one_process = 0;
ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);
- ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+ /* we need to set the MPM state before other pre-config hooks use MPM query
+ * to retrieve it, so register as REALLY_FIRST
+ */
+ ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
}
static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,