Main Page | Modules | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

leader.c File Reference

#include "apr.h"
#include "apr_portable.h"
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_thread_proc.h"
#include "apr_signal.h"
#include "apr_thread_cond.h"
#include "apr_thread_mutex.h"
#include "apr_proc_mutex.h"
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_config.h"
#include "http_core.h"
#include "http_connection.h"
#include "ap_mpm.h"
#include "mpm_common.h"
#include "ap_listen.h"
#include "scoreboard.h"
#include "mpm_default.h"
#include "apr_poll.h"
#include <signal.h>
#include <limits.h>
#include "apr_atomic.h"

Include dependency graph for leader.c:

Go to the source code of this file.

Data Structures

struct  proc_info

Defines

#define APR_WANT_STRFUNC
#define CORE_PRIVATE
#define DEFAULT_SERVER_LIMIT   16
#define MAX_SERVER_LIMIT   20000
#define DEFAULT_THREAD_LIMIT   64
#define MAX_THREAD_LIMIT   20000
#define ID_FROM_CHILD_THREAD(c, t)   ((c * thread_limit) + t)
#define SAFE_ACCEPT(stmt)   (stmt)
#define STACK_FIRST   0xffff
#define STACK_LIST_END   0xffff
#define STACK_TERMINATED   0x10000
#define STACK_NO_LISTENER   0x20000
#define ST_INIT   0
#define ST_GRACEFUL   1
#define ST_UNGRACEFUL   2
#define MAX_SPAWN_RATE   (32)

Typedefs

typedef worker_wakeup_info worker_wakeup_info

Functions

static worker_wakeup_infoworker_wakeup_create (apr_pool_t *pool)
static worker_stackworker_stack_create (apr_pool_t *pool, apr_size_t max)
static apr_status_t worker_stack_wait (worker_stack *stack, apr_uint32_t worker_id)
static apr_status_t worker_stack_awaken_next (worker_stack *stack)
static apr_status_t worker_stack_term (worker_stack *stack)
static void signal_threads (int mode)
 AP_DECLARE (apr_status_t)
static void clean_child_exit (int code) __attribute__((noreturn))
static void just_die (int sig)
static void ap_start_shutdown (void)
static void ap_start_restart (int graceful)
static void sig_term (int sig)
static void restart (int sig)
static void set_signals (void)
int ap_graceful_stop_signalled (void)
static void process_socket (apr_pool_t *p, apr_socket_t *sock, int my_child_num, int my_thread_num, apr_bucket_alloc_t *bucket_alloc)
static void check_infinite_requests (void)
static void unblock_signal (int sig)
static void * worker_thread (apr_thread_t *thd, void *dummy)
static int check_signal (int signum)
static void *APR_THREAD_FUNC start_threads (apr_thread_t *thd, void *dummy)
static void join_workers (apr_thread_t **threads)
static void join_start_thread (apr_thread_t *start_thread_id)
static void child_main (int child_num_arg)
static int make_child (server_rec *s, int slot)
static void startup_children (int number_to_start)
static void perform_idle_server_maintenance (void)
static void server_main_loop (int remaining_children_to_start)
int ap_mpm_run (apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
static int leader_open_logs (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
static int leader_pre_config (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
static void leader_hooks (apr_pool_t *p)
static const char * set_daemons_to_start (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_min_spare_threads (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_max_spare_threads (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_threads_per_child (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
static const char * set_thread_limit (cmd_parms *cmd, void *dummy, const char *arg)

Variables

int ap_threads_per_child = 0
static int ap_daemons_to_start = 0
static int min_spare_threads = 0
static int max_spare_threads = 0
static int ap_daemons_limit = 0
static int server_limit = DEFAULT_SERVER_LIMIT
static int first_server_limit
static int thread_limit = DEFAULT_THREAD_LIMIT
static int first_thread_limit
static int changed_limit_at_restart
static int dying = 0
static int workers_may_exit = 0
static int start_thread_may_exit = 0
static int requests_this_child
static int num_listensocks = 0
static int resource_shortage = 0
static int mpm_state = AP_MPMQ_STARTING
int ap_max_daemons_limit = -1
static ap_pod_tpod
server_recap_server_conf
static int one_process = 0
static apr_pool_tpconf
static apr_pool_tpchild
static pid_t ap_my_pid
static pid_t parent_pid
static apr_proc_mutex_taccept_mutex
static worker_wakeup_info ** worker_wakeups = NULL
static worker_stackidle_worker_stack
static int terminate_mode = ST_INIT
static int volatile shutdown_pending
static int volatile restart_pending
static int volatile is_graceful
static volatile int child_fatal
ap_generation_t volatile ap_my_generation
static int idle_spawn_rate = 1
static int hold_off_on_exponential_spawning
static const command_rec leader_cmds []
module AP_MODULE_DECLARE_DATA mpm_leader_module


Define Documentation

#define APR_WANT_STRFUNC
 

Definition at line 26 of file leader.c.

#define CORE_PRIVATE
 

Definition at line 46 of file leader.c.

#define DEFAULT_SERVER_LIMIT   16
 

Definition at line 79 of file leader.c.

Referenced by perchild_pre_config().

#define DEFAULT_THREAD_LIMIT   64
 

Definition at line 97 of file leader.c.

Referenced by perchild_pre_config().

#define ID_FROM_CHILD_THREAD c,
t   )     ((c * thread_limit) + t)
 

Definition at line 148 of file leader.c.

Referenced by process_socket(), and worker_main().

#define MAX_SERVER_LIMIT   20000
 

Definition at line 86 of file leader.c.

Referenced by perchild_pre_config(), and set_server_limit().

#define MAX_SPAWN_RATE   (32)
 

Definition at line 1201 of file leader.c.

#define MAX_THREAD_LIMIT   20000
 

Definition at line 104 of file leader.c.

Referenced by perchild_pre_config(), and set_thread_limit().

#define SAFE_ACCEPT stmt   )     (stmt)
 

Definition at line 196 of file leader.c.

Referenced by ap_mpm_run(), child_main(), listener_thread(), and worker_thread().

#define ST_GRACEFUL   1
 

Definition at line 351 of file leader.c.

Referenced by check_infinite_requests(), child_main(), listener_thread(), sig_term(), and worker_thread().

#define ST_INIT   0
 

Definition at line 350 of file leader.c.

#define ST_UNGRACEFUL   2
 

Definition at line 352 of file leader.c.

Referenced by child_main(), and signal_threads().

#define STACK_FIRST   0xffff
 

Definition at line 245 of file leader.c.

Referenced by worker_stack_awaken_next().

#define STACK_LIST_END   0xffff
 

Definition at line 246 of file leader.c.

Referenced by worker_stack_awaken_next(), worker_stack_create(), and worker_stack_wait().

#define STACK_NO_LISTENER   0x20000
 

Definition at line 248 of file leader.c.

Referenced by worker_stack_awaken_next(), worker_stack_create(), and worker_stack_wait().

#define STACK_TERMINATED   0x10000
 

Definition at line 247 of file leader.c.

Referenced by worker_stack_term(), and worker_stack_wait().


Typedef Documentation

typedef struct worker_wakeup_info worker_wakeup_info
 

Definition at line 129 of file leader.c.


Function Documentation

AP_DECLARE apr_status_t   ) 
 

convert a recent time to its human readable components in local timezone

Parameters:
tm the exploded time
t the time to explode: MUST be within the last AP_TIME_RECENT_THRESHOLD seconds
Note:
This is a faster alternative to apr_explode_localtime that uses a cache of pre-exploded time structures. It is useful for things that need to explode the current time multiple times per second, like loggers.
Returns:
APR_SUCCESS iff successful

Definition at line 368 of file leader.c.

References ap_daemons_limit, AP_DECLARE, ap_max_daemons_limit, ap_max_requests_per_child, AP_MPMQ_DYNAMIC, AP_MPMQ_HARD_LIMIT_DAEMONS, AP_MPMQ_HARD_LIMIT_THREADS, AP_MPMQ_IS_FORKED, AP_MPMQ_IS_THREADED, AP_MPMQ_MAX_DAEMON_USED, AP_MPMQ_MAX_DAEMONS, AP_MPMQ_MAX_REQUESTS_DAEMON, AP_MPMQ_MAX_SPARE_DAEMONS, AP_MPMQ_MAX_SPARE_THREADS, AP_MPMQ_MAX_THREADS, AP_MPMQ_MIN_SPARE_DAEMONS, AP_MPMQ_MIN_SPARE_THREADS, AP_MPMQ_MPM_STATE, AP_MPMQ_STATIC, ap_threads_per_child, APR_ENOTIMPL, APR_SUCCESS, max_spare_threads, min_spare_threads, mpm_state, server_limit, and thread_limit.

int ap_graceful_stop_signalled void   ) 
 

Definition at line 582 of file leader.c.

References workers_may_exit.

int ap_mpm_run apr_pool_t _pconf,
apr_pool_t plog,
server_rec s
 

Definition at line 1424 of file leader.c.

References ap_daemons_limit, ap_daemons_to_start, AP_MPMQ_RUNNING, AP_MPMQ_STOPPING, ap_my_pid, ap_pid_fname, ap_scoreboard_image, ap_threads_per_child, APLOG_DEBUG, APLOG_EMERG, APLOG_INFO, APLOG_MARK, APLOG_NOTICE, APLOG_WARNING, APR_LOCK_DEFAULT, APR_LOCK_SYSVSEM, apr_signal, APR_SUCCESS, changed_limit_at_restart, first_server_limit, first_thread_limit, getpid, scoreboard::global, max_spare_threads, min_spare_threads, mpm_state, NULL, OK, one_process, process_rec::pool, server_rec::process, global_score::running_generation, SB_SHARED, server_limit, server_main_loop(), set_signals(), startup_children(), thread_limit, and unixd_killpg.

Here is the call graph for this function:

static void ap_start_restart int  graceful  )  [static]
 

Definition at line 475 of file leader.c.

References AP_MPMQ_STOPPING, and mpm_state.

static void ap_start_shutdown void   )  [static]
 

Definition at line 461 of file leader.c.

References AP_MPMQ_STOPPING, and mpm_state.

static void check_infinite_requests void   )  [static]
 

Definition at line 616 of file leader.c.

References ap_max_requests_per_child, requests_this_child, signal_threads(), and ST_GRACEFUL.

Referenced by listener_thread(), and worker_thread().

Here is the call graph for this function:

static int check_signal int  signum  )  [static]
 

Definition at line 837 of file leader.c.

Referenced by child_main().

static void child_main int  child_num_arg  )  [static]
 

Definition at line 988 of file leader.c.

References ap_max_requests_per_child, AP_MPMQ_RUNNING, AP_MPMQ_STARTING, ap_my_pid, ap_reopen_scoreboard(), ap_threads_per_child, APEXIT_CHILDFATAL, APEXIT_CHILDSICK, APLOG_ALERT, APLOG_EMERG, APLOG_MARK, apr_pool_create, APR_SUCCESS, apr_thread_create(), apr_threadattr_create(), apr_threadattr_detach_set(), APR_USEC_PER_SEC, check_signal(), clean_child_exit(), getpid, join_start_thread(), join_workers(), mpm_state, NULL, one_process, requests_this_child, resource_shortage, SAFE_ACCEPT, signal_threads(), ST_UNGRACEFUL, start_threads(), and unblock_signal().

Referenced by make_child().

Here is the call graph for this function:

static void clean_child_exit int  code  )  [static]
 

static void join_start_thread apr_thread_t start_thread_id  )  [static]
 

Definition at line 972 of file leader.c.

References APLOG_CRIT, APLOG_MARK, APR_SUCCESS, apr_thread_join(), and start_thread_may_exit.

Referenced by child_main().

Here is the call graph for this function:

static void join_workers apr_thread_t **  threads  )  [static]
 

Definition at line 954 of file leader.c.

References ap_threads_per_child, APLOG_CRIT, APLOG_MARK, APR_SUCCESS, and apr_thread_join().

Referenced by child_main().

Here is the call graph for this function:

static void just_die int  sig  )  [static]
 

Definition at line 426 of file leader.c.

References clean_child_exit().

Referenced by check_signal(), and make_child().

Here is the call graph for this function:

static void leader_hooks apr_pool_t p  )  [static]
 

Definition at line 1715 of file leader.c.

References APR_HOOK_MIDDLE, APR_HOOK_REALLY_FIRST, aszSucc, leader_open_logs(), leader_pre_config(), NULL, and one_process.

Here is the call graph for this function:

static int leader_open_logs apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec s
[static]
 

Definition at line 1597 of file leader.c.

References ap_setup_listeners(), APLOG_ALERT, APLOG_CRIT, APLOG_MARK, APLOG_STARTUP, DONE, NULL, num_listensocks, OK, and one_process.

Referenced by leader_hooks().

Here is the call graph for this function:

static int leader_pre_config apr_pool_t pconf,
apr_pool_t plog,
apr_pool_t ptemp
[static]
 

Definition at line 1620 of file leader.c.

References ap_conftree, ap_coredump_dir, ap_daemons_limit, ap_daemons_to_start, ap_extended_status, ap_listen_pre_config(), ap_max_requests_per_child, AP_MPMQ_STARTING, ap_my_pid, ap_pid_fname, ap_server_root, ap_threads_per_child, APLOG_CRIT, APLOG_MARK, APR_ALLOCATOR_MAX_FREE_UNLIMITED, apr_proc_detach(), APR_PROC_DETACH_DAEMONIZE, APR_PROC_DETACH_FOREGROUND, APR_SUCCESS, ap_directive_t::args, debug, DEFAULT_LOCKFILE, DEFAULT_MAX_FREE_DAEMON, DEFAULT_MAX_REQUESTS_PER_CHILD, DEFAULT_MIN_FREE_DAEMON, DEFAULT_PIDLOG, DEFAULT_START_DAEMON, DEFAULT_THREADS_PER_CHILD, ap_directive_t::directive, ap_directive_t::filename, getpid, HTTP_INTERNAL_SERVER_ERROR, ap_directive_t::line_num, max_spare_threads, min_spare_threads, mpm_state, ap_directive_t::next, NULL, OK, one_process, parent_pid, server_limit, and strncasecmp().

Referenced by leader_hooks().

Here is the call graph for this function:

static int make_child server_rec s,
int  slot
[static]
 

Definition at line 1120 of file leader.c.

References ap_max_daemons_limit, ap_scoreboard_image, APLOG_ERR, APLOG_MARK, APLOG_WARNING, apr_signal, APR_USEC_PER_SEC, child_main(), clean_child_exit(), fork(), getpid, just_die(), NULL, OK, one_process, scoreboard::parent, process_score::pid, process_score::quiescing, RAISE_SIGSTOP, SERVER_DEAD, set_signals(), and status.

Referenced by ap_mpm_run(), perform_child_maintenance(), perform_idle_server_maintenance(), server_main_loop(), startup_children(), startup_workers(), and test_exclusive().

Here is the call graph for this function:

static void perform_idle_server_maintenance void   )  [static]
 

Definition at line 1205 of file leader.c.

References ap_daemons_limit, ap_max_daemons_limit, ap_scoreboard_image, ap_threads_per_child, APLOG_ERR, APLOG_INFO, APLOG_MARK, process_score::generation, idle_thread_count, make_child(), max_spare_threads, MAX_SPAWN_RATE, min_spare_threads, scoreboard::parent, process_score::pid, process_score::quiescing, SERVER_DEAD, SERVER_GRACEFUL, SERVER_READY, scoreboard::servers, worker_score::status, and status.

Here is the call graph for this function:

static void process_socket apr_pool_t p,
apr_socket_t sock,
int  my_child_num,
int  my_thread_num,
apr_bucket_alloc_t bucket_alloc
[static]
 

Definition at line 594 of file leader.c.

References apr_os_sock_get(), and ID_FROM_CHILD_THREAD.

Here is the call graph for this function:

static void restart int  sig  )  [static]
 

Definition at line 496 of file leader.c.

References ap_start_restart().

Here is the call graph for this function:

static void server_main_loop int  remaining_children_to_start  )  [static]
 

Definition at line 1345 of file leader.c.

References ap_daemons_limit, ap_scoreboard_image, ap_threads_per_child, APEXIT_CHILDFATAL, APEXIT_CHILDSICK, APLOG_MARK, APLOG_WARNING, child_slot, exitwhy, make_child(), NULL, scoreboard::parent, perform_idle_server_maintenance(), process_score::pid, apr_proc_t::pid, process_score::quiescing, SERVER_DEAD, startup_children(), and status.

Here is the call graph for this function:

static const char* set_daemons_to_start cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1731 of file leader.c.

References ap_daemons_to_start, err, GLOBAL_ONLY, and NULL.

static const char* set_max_clients cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1777 of file leader.c.

References ap_daemons_limit, ap_threads_per_child, APLOG_MARK, APLOG_STARTUP, err, GLOBAL_ONLY, NULL, and server_limit.

static const char* set_max_spare_threads cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1765 of file leader.c.

References err, GLOBAL_ONLY, max_spare_threads, and NULL.

static const char* set_min_spare_threads cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1743 of file leader.c.

References APLOG_MARK, APLOG_STARTUP, err, GLOBAL_ONLY, min_spare_threads, and NULL.

static const char* set_server_limit cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1866 of file leader.c.

References APLOG_MARK, APLOG_STARTUP, changed_limit_at_restart, err, first_server_limit, GLOBAL_ONLY, MAX_SERVER_LIMIT, NULL, and server_limit.

static void set_signals void   )  [static]
 

Definition at line 501 of file leader.c.

References APLOG_MARK, APLOG_WARNING, apr_signal, NULL, one_process, restart(), and sig_term().

Here is the call graph for this function:

static const char* set_thread_limit cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1906 of file leader.c.

References APLOG_MARK, APLOG_STARTUP, changed_limit_at_restart, err, first_thread_limit, GLOBAL_ONLY, MAX_THREAD_LIMIT, NULL, and thread_limit.

static const char* set_threads_per_child cmd_parms cmd,
void *  dummy,
const char *  arg
[static]
 

Definition at line 1837 of file leader.c.

References ap_threads_per_child, APLOG_MARK, APLOG_STARTUP, err, GLOBAL_ONLY, NULL, and thread_limit.

static void sig_term int  sig  )  [static]
 

Definition at line 486 of file leader.c.

References ap_my_pid, ap_start_shutdown(), parent_pid, signal_threads(), and ST_GRACEFUL.

Here is the call graph for this function:

static void signal_threads int  mode  )  [static]
 

Definition at line 356 of file leader.c.

References AP_MPMQ_STOPPING, mpm_state, terminate_mode, worker_stack_term(), and workers_may_exit.

Referenced by check_infinite_requests(), child_main(), listener_thread(), sig_term(), and worker_thread().

Here is the call graph for this function:

static void* APR_THREAD_FUNC start_threads apr_thread_t thd,
void *  dummy
[static]
 

Definition at line 852 of file leader.c.

References ap_my_pid, ap_scoreboard_image, ap_threads_per_child, APEXIT_CHILDFATAL, APLOG_ALERT, APLOG_DEBUG, APLOG_MARK, APLOG_NOERRNO, APR_SUCCESS, apr_thread_create(), apr_thread_exit(), APR_USEC_PER_SEC, thread_starter::child_num_arg, clean_child_exit(), my_child_num, NULL, proc_info::pid, proc_info::sd, SERVER_DEAD, SERVER_GRACEFUL, SERVER_STARTING, scoreboard::servers, start_thread_may_exit, worker_score::status, status, thread_starter::threadattr, thread_starter::threads, proc_info::tid, worker_stack_create(), worker_thread(), and worker_wakeup_create().

Referenced by child_main().

Here is the call graph for this function:

static void startup_children int