00001 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef AP_MPM_H 00018 #define AP_MPM_H 00019 00020 #include "apr_thread_proc.h" 00021 00022 /** 00023 * @package Multi-Processing Module library 00024 */ 00025 00026 /* 00027 The MPM, "multi-processing model" provides an abstraction of the 00028 interface with the OS for distributing incoming connections to 00029 threads/process for processing. http_main invokes the MPM, and 00030 the MPM runs until a shutdown/restart has been indicated. 00031 The MPM calls out to the apache core via the ap_process_connection 00032 function when a connection arrives. 00033 00034 The MPM may or may not be multithreaded. In the event that it is 00035 multithreaded, at any instant it guarantees a 1:1 mapping of threads 00036 ap_process_connection invocations. 00037 00038 Note: In the future it will be possible for ap_process_connection 00039 to return to the MPM prior to finishing the entire connection; and 00040 the MPM will proceed with asynchronous handling for the connection; 00041 in the future the MPM may call ap_process_connection again -- but 00042 does not guarantee it will occur on the same thread as the first call. 00043 00044 The MPM further guarantees that no asynchronous behaviour such as 00045 longjmps and signals will interfere with the user code that is 00046 invoked through ap_process_connection. The MPM may reserve some 00047 signals for its use (i.e. SIGUSR1), but guarantees that these signals 00048 are ignored when executing outside the MPM code itself. (This 00049 allows broken user code that does not handle EINTR to function 00050 properly.) 00051 00052 The suggested server restart and stop behaviour will be "graceful". 00053 However the MPM may choose to terminate processes when the user 00054 requests a non-graceful restart/stop. When this occurs, the MPM kills 00055 all threads with extreme prejudice, and destroys the pchild pool. 00056 User cleanups registered in the pchild apr_pool_t will be invoked at 00057 this point. (This can pose some complications, the user cleanups 00058 are asynchronous behaviour not unlike longjmp/signal... but if the 00059 admin is asking for a non-graceful shutdown, how much effort should 00060 we put into doing it in a nice way?) 00061 00062 unix/posix notes: 00063 - The MPM does not set a SIGALRM handler, user code may use SIGALRM. 00064 But the preferred method of handling timeouts is to use the 00065 timeouts provided by the BUFF abstraction. 00066 - The proper setting for SIGPIPE is SIG_IGN, if user code changes it 00067 for any of their own processing, it must be restored to SIG_IGN 00068 prior to executing or returning to any apache code. 00069 TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN 00070 */ 00071 00072 /** 00073 * This is the function that MPMs must create. This function is responsible 00074 * for controlling the parent and child processes. It will run until a 00075 * restart/shutdown is indicated. 00076 * @param pconf the configuration pool, reset before the config file is read 00077 * @param plog the log pool, reset after the config file is read 00078 * @param server_conf the global server config. 00079 * @return 1 for shutdown 0 otherwise. 00080 * @deffunc int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf) 00081 */ 00082 AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf); 00083 00084 /** 00085 * predicate indicating if a graceful stop has been requested ... 00086 * used by the connection loop 00087 * @return 1 if a graceful stop has been requested, 0 otherwise 00088 * @deffunc int ap_graceful_stop_signalled(*void) 00089 */ 00090 AP_DECLARE(int) ap_graceful_stop_signalled(void); 00091 00092 /** 00093 * Spawn a process with privileges that another module has requested 00094 * @param r The request_rec of the current request 00095 * @param newproc The resulting process handle. 00096 * @param progname The program to run 00097 * @param const_args the arguments to pass to the new program. The first 00098 * one should be the program name. 00099 * @param env The new environment apr_table_t for the new process. This 00100 * should be a list of NULL-terminated strings. 00101 * @param attr the procattr we should use to determine how to create the new 00102 * process 00103 * @param p The pool to use. 00104 */ 00105 AP_DECLARE(apr_status_t) ap_os_create_privileged_process( 00106 const request_rec *r, 00107 apr_proc_t *newproc, 00108 const char *progname, 00109 const char * const *args, 00110 const char * const *env, 00111 apr_procattr_t *attr, 00112 apr_pool_t *p); 00113 00114 /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED */ 00115 #define AP_MPMQ_NOT_SUPPORTED 0 /* This value specifies whether */ 00116 /* an MPM is capable of */ 00117 /* threading or forking. */ 00118 #define AP_MPMQ_STATIC 1 /* This value specifies whether */ 00119 /* an MPM is using a static # */ 00120 /* threads or daemons. */ 00121 #define AP_MPMQ_DYNAMIC 2 /* This value specifies whether */ 00122 /* an MPM is using a dynamic # */ 00123 /* threads or daemons. */ 00124 00125 /* Values returned for AP_MPMQ_MPM_STATE */ 00126 #define AP_MPMQ_STARTING 0 00127 #define AP_MPMQ_RUNNING 1 00128 #define AP_MPMQ_STOPPING 2 00129 00130 #define AP_MPMQ_MAX_DAEMON_USED 1 /* Max # of daemons used so far */ 00131 #define AP_MPMQ_IS_THREADED 2 /* MPM can do threading */ 00132 #define AP_MPMQ_IS_FORKED 3 /* MPM can do forking */ 00133 #define AP_MPMQ_HARD_LIMIT_DAEMONS 4 /* The compiled max # daemons */ 00134 #define AP_MPMQ_HARD_LIMIT_THREADS 5 /* The compiled max # threads */ 00135 #define AP_MPMQ_MAX_THREADS 6 /* # of threads/child by config */ 00136 #define AP_MPMQ_MIN_SPARE_DAEMONS 7 /* Min # of spare daemons */ 00137 #define AP_MPMQ_MIN_SPARE_THREADS 8 /* Min # of spare threads */ 00138 #define AP_MPMQ_MAX_SPARE_DAEMONS 9 /* Max # of spare daemons */ 00139 #define AP_MPMQ_MAX_SPARE_THREADS 10 /* Max # of spare threads */ 00140 #define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */ 00141 #define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */ 00142 #define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */ 00143 00144 /** 00145 * Query a property of the current MPM. 00146 * @param query_code One of APM_MPMQ_* 00147 * @param result A location to place the result of the query 00148 * @return APR_SUCCESS or APR_ENOTIMPL 00149 * @deffunc int ap_mpm_query(int query_code, int *result) 00150 */ 00151 AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result); 00152 00153 /* Defining GPROF when compiling uses the moncontrol() function to 00154 * disable gprof profiling in the parent, and enable it only for 00155 * request processing in children (or in one_process mode). It's 00156 * absolutely required to get useful gprof results under linux 00157 * because the profile itimers and such are disabled across a 00158 * fork(). It's probably useful elsewhere as well. 00159 */ 00160 #ifdef GPROF 00161 extern void moncontrol(int); 00162 #define AP_MONCONTROL(x) moncontrol(x) 00163 #else 00164 #define AP_MONCONTROL(x) 00165 #endif 00166 00167 #if AP_ENABLE_EXCEPTION_HOOK 00168 typedef struct ap_exception_info_t { 00169 int sig; 00170 pid_t pid; 00171 } ap_exception_info_t; 00172 00173 AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei)) 00174 #endif /*AP_ENABLE_EXCEPTION_HOOK*/ 00175 00176 #endif