From: Ryan Bloom Date: Mon, 13 Aug 2001 04:57:35 +0000 (+0000) Subject: Begin to sanitize the MPM configuration directives. Now, all X-Git-Tag: 2.0.24~113 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80061453105e045ebb91d0a78e2b88a50340a910;p=apache Begin to sanitize the MPM configuration directives. Now, all MPMs use the same functions for all common MPM directives. This should make it easier to catch all bugs in these directives once. Everybody should check their favorite MPM to ensure that it still compiles, and that these directives work. This is a big patch, and although it looks good, and things compiled for me, that is no garauntee that it will work on all platforms. :-) Submitted by: Cody Sherr git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90132 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index a7b0e6b8f5..1417ec182f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ Changes with Apache 2.0.24-dev + *) Begin to sanitize the MPM configuration directives. Now, all + MPMs use the same functions for all common MPM directives. This + should make it easier to catch all bugs in these directives once. + [Cody Sherr ] + *) Close a major resource leak. Everytime we had issued a graceful restart, we leaked a socket descriptor. [Ryan Bloom] diff --git a/include/mpm_common.h b/include/mpm_common.h index 4d160de180..7c246d4085 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -208,6 +208,67 @@ AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod); AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num); #endif +/* + * These data members are common to all mpms. Each new mpm + * should either use the appropriate ap_mpm_set_* function + * in their command table or create their own for custom or + * OS specific needs. These should work for most. + */ + +/** + * The maximum number of requests each child thread or + * process handles before dying off + */ +#ifdef AP_MPM_WANT_SET_MAX_REQUESTS +extern int ap_max_requests_per_child; +AP_DECLARE(const char *) ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + +/** + * The filename used to store the process id. + */ +#ifdef AP_MPM_WANT_SET_PIDFILE +extern const char *ap_pid_fname; +AP_DECLARE(const char *) ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + +/** + * The name of lockfile used when Apache needs to lock the accept() call. + */ +#ifdef AP_MPM_WANT_SET_LOCKFILE +extern const char *ap_lock_fname; +AP_DECLARE(const char *) ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + +/** + * The system mutex implementation to use for the accept mutex. + */ +#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH +extern apr_lockmech_e_np accept_lock_mech; +AP_DECLARE(const char *) ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + +/* + * Set the scorboard file. + */ +#ifdef AP_MPM_WANT_SET_SCOREBOARD +AP_DECLARE(const char *) ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + +/* + * The directory that the server changes directory to dump core. + */ +#ifdef AP_MPM_WANT_SET_COREDUMPDIR +extern char ap_coredump_dir[MAX_STRING_LEN]; +AP_DECLARE(const char *) ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + #ifdef __cplusplus } #endif diff --git a/os/unix/unixd.c b/os/unix/unixd.c index 0a9f4ab641..ab1a12dbde 100644 --- a/os/unix/unixd.c +++ b/os/unix/unixd.c @@ -63,6 +63,7 @@ #include "http_main.h" #include "http_log.h" #include "unixd.h" +#include "apr_lock.h" #include "mpm_common.h" #include "os.h" #include "ap_mpm.h" diff --git a/server/core.c b/server/core.c index e0bff5f285..e7cd0fd21b 100644 --- a/server/core.c +++ b/server/core.c @@ -85,7 +85,8 @@ #include "util_filter.h" #include "util_ebcdic.h" #include "mpm.h" - +#include "mpm_common.h" +#include "scoreboard.h" #include "mod_core.h" @@ -2841,6 +2842,36 @@ AP_INIT_ITERATE("SetOutputFilter", add_filter, NULL, ACCESS_CONF, "filters to be run"), AP_INIT_ITERATE("SetInputFilter", add_input_filter, NULL, ACCESS_CONF, "filters to be run on the request body"), + +/* + * These are default configuration directives that mpms can/should + * pay attention to. If an mpm wishes to use these, they should + * #defined them in mpm.h. + */ +#ifdef AP_MPM_WANT_SET_PIDFILE +AP_INIT_TAKE1("PidFile", ap_mpm_set_pidfile, NULL, RSRC_CONF, \ + "A file for logging the server process ID"), +#endif +#ifdef AP_MPM_WANT_SET_SCOREBOARD +AP_INIT_TAKE1("ScoreBoardFile", ap_mpm_set_scoreboard, NULL, RSRC_CONF, \ + "A file for Apache to maintain runtime process management information"), +#endif +#ifdef AP_MPM_WANT_SET_LOCKFILE +AP_INIT_TAKE1("LockFile", ap_mpm_set_lockfile, NULL, RSRC_CONF, \ + "The lockfile used when Apache needs to lock the accept() call"), +#endif +#ifdef AP_MPM_WANT_SET_MAX_REQUESTS +AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF,\ + "Maximum number of requests a particular child serves before dying."), +#endif +#ifdef AP_MPM_WANT_SET_COREDUMPDIR +AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF, \ + "The location of the directory Apache changes to before dumping core"), +#endif +#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH +AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF, \ + "The system mutex implementation to use for the accept mutex"), +#endif { NULL } }; diff --git a/server/listen.c b/server/listen.c index 169c090cac..8225efc9e9 100644 --- a/server/listen.c +++ b/server/listen.c @@ -58,6 +58,7 @@ #include "apr_network_io.h" #include "apr_strings.h" +#include "apr_lock.h" #define APR_WANT_STRFUNC #include "apr_want.h" @@ -71,7 +72,6 @@ #include "mpm.h" #include "mpm_common.h" - ap_listen_rec *ap_listeners; #if APR_HAVE_IPV6 static int default_family = APR_UNSPEC; diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index a3dfd4f7ef..c7ee021d41 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -92,8 +92,6 @@ extern int _kset_fd_limit_(int num); */ int ap_threads_per_child=HARD_THREAD_LIMIT; /* Worker threads per child */ -static int ap_max_requests_per_child=0; -static const char *ap_pid_fname=NULL; static int ap_threads_to_start=0; static int min_spare_threads=0; static int max_spare_threads=0; @@ -126,7 +124,6 @@ static void check_restart(void *data); */ int ap_max_child_assigned = -1; int ap_max_threads_limit = -1; -char ap_coredump_dir[MAX_STRING_LEN]; static apr_socket_t *udp_sock; static apr_sockaddr_t *udp_sa; @@ -984,32 +981,6 @@ static void beos_hooks(apr_pool_t *p) ap_hook_pre_config(beos_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } - -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1107,43 +1078,8 @@ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, const cha return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - static const command_rec beos_cmds[] = { LISTEN_COMMANDS -AP_INIT_TAKE1( "PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1( "ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), AP_INIT_TAKE1( "StartServers", set_daemons_to_start, NULL, RSRC_CONF, "Number of child processes launched at server startup"), AP_INIT_TAKE1( "MinSpareThreads", set_min_spare_threads, NULL, RSRC_CONF, @@ -1154,10 +1090,6 @@ AP_INIT_TAKE1( "MaxClients", set_server_limit, NULL, RSRC_CONF, "Maximum number of children alive at the same time" ), AP_INIT_TAKE1( "ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, "Number of threads each child creates" ), -AP_INIT_TAKE1( "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying." ), -AP_INIT_TAKE1( "CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core" ), { NULL } }; diff --git a/server/mpm/beos/mpm.h b/server/mpm/beos/mpm.h index 3a652f0502..98e31d5b91 100644 --- a/server/mpm/beos/mpm.h +++ b/server/mpm/beos/mpm.h @@ -68,10 +68,13 @@ #define MPM_CHILD_PID(i) (ap_scoreboard_image->servers[0][i].tid) #define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0) -extern int ap_max_child_assigned; +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +extern int ap_max_child_assigned; extern server_rec *ap_server_conf; -extern char ap_coredump_dir[MAX_STRING_LEN]; extern int ap_threads_per_child; #endif /* APACHE_MPM_BEOS_H */ diff --git a/server/mpm/experimental/perchild/mpm.h b/server/mpm/experimental/perchild/mpm.h index d24f8b4aba..cdaa46e372 100644 --- a/server/mpm/experimental/perchild/mpm.h +++ b/server/mpm/experimental/perchild/mpm.h @@ -67,6 +67,13 @@ #define MPM_NAME "Perchild" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + #define AP_MPM_NEEDS_RECLAIM_CHILD_PROCESSES 1 #define MPM_SYNC_CHILD_TABLE() #define MPM_CHILD_PID(i) (ap_child_table[i].pid) @@ -86,6 +93,5 @@ extern int ap_threads_per_child; extern int ap_max_daemons_limit; extern ap_ctable ap_child_table[HARD_SERVER_LIMIT]; extern server_rec *ap_server_conf; -extern char ap_coredump_dir[MAX_STRING_LEN]; #endif /* APACHE_MPM_PERCHILD_H */ diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index 39a89a3207..efb68418ce 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -116,9 +116,8 @@ static int min_spare_threads = 0; static int max_spare_threads = 0; static int max_threads = 0; static int max_requests_per_child = 0; -static const char *ap_pid_fname=NULL; -static int num_daemons=0; -static int curr_child_num=0; +static int num_daemons = 0; +static int curr_child_num = 0; static int workers_may_exit = 0; static int requests_this_child; static int num_listenfds = 0; @@ -161,8 +160,6 @@ struct ap_ctable ap_child_table[HARD_SERVER_LIMIT]; int ap_max_daemons_limit = -1; int ap_threads_per_child = HARD_THREAD_LIMIT; -char ap_coredump_dir[MAX_STRING_LEN]; - module AP_MODULE_DECLARE_DATA mpm_perchild_module; static apr_file_t *pipe_of_death_in = NULL; @@ -214,9 +211,7 @@ static apr_lock_t *idle_thread_count_mutex; #else #define SAFE_ACCEPT(stmt) (stmt) static apr_lock_t *process_accept_mutex; -static apr_lockmech_e_np accept_lock_mech = APR_LOCK_DEFAULT; #endif /* NO_SERIALIZED_ACCEPT */ -static const char *lock_fname; static apr_lock_t *thread_accept_mutex; AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result) @@ -890,8 +885,8 @@ static void child_main(int child_num_arg) /*stuff to do before we switch id's, so we have permissions.*/ - rv = SAFE_ACCEPT(apr_lock_child_init(&process_accept_mutex, lock_fname, - pchild)); + rv = SAFE_ACCEPT(apr_lock_child_init(&process_accept_mutex, ap_lock_fname, + pchild)); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, "Couldn't initialize cross-process lock in child"); @@ -1198,12 +1193,12 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) ap_log_pid(pconf, ap_pid_fname); /* Initialize cross-process accept lock */ - lock_fname = apr_psprintf(_pconf, "%s.%u", - ap_server_root_relative(_pconf, lock_fname), + ap_lock_fname = apr_psprintf(_pconf, "%s.%u", + ap_server_root_relative(_pconf, ap_lock_fname), my_pid); rv = SAFE_ACCEPT(apr_lock_create_np(&process_accept_mutex, APR_MUTEX, APR_CROSS_PROCESS, accept_lock_mech, - lock_fname, _pconf)); + ap_lock_fname, _pconf)); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "Couldn't create cross-process lock"); @@ -1355,7 +1350,7 @@ static void perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *pte max_threads = HARD_THREAD_LIMIT; ap_pid_fname = DEFAULT_PIDLOG; ap_scoreboard_fname = DEFAULT_SCOREBOARD; - lock_fname = DEFAULT_LOCKFILE; + ap_lock_fname = DEFAULT_LOCKFILE; max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; curr_child_num = 0; @@ -1384,7 +1379,7 @@ static int pass_request(request_rec *r) &mpm_perchild_module); char *foo; apr_size_t len; - int zero = 0; + apr_off_t zero = 0; apr_pool_userdata_get((void **)&foo, "PERCHILD_BUFFER", r->connection->pool); len = strlen(foo); @@ -1518,7 +1513,7 @@ static int perchild_post_read(request_rec *r) return OK; } -static apr_status_t perchild_buffer(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_size_t *readbytes) +static apr_status_t perchild_buffer(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes) { apr_bucket *e; apr_status_t rv; @@ -1573,41 +1568,6 @@ static void perchild_hooks(apr_pool_t *p) ap_register_input_filter("PERCHILD_BUFFER", perchild_buffer, AP_FTYPE_CONTENT); } -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - -static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - lock_fname = arg; - return NULL; -} static const char *set_num_daemons (cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1721,38 +1681,6 @@ static const char *set_max_threads(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, - const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - static const char *set_child_per_uid(cmd_parms *cmd, void *dummy, const char *u, const char *g, const char *num) { @@ -1802,65 +1730,9 @@ static const char *assign_childuid(cmd_parms *cmd, void *dummy, const char *uid, return NULL; } -static const char *set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (!strcasecmp(arg, "default")) { - accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - accept_lock_mech = APR_LOCK_FCNTL; - } -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - else if (!strcasecmp(arg, "sysvsem")) { - accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "proc_pthread")) { - accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " - "ones for this platform are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - ", sysvsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", proc_pthread" -#endif - , NULL); - } - return NULL; -} - static const command_rec perchild_cmds[] = { UNIX_DAEMON_COMMANDS LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), -AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), AP_INIT_TAKE1("NumServers", set_num_daemons, NULL, RSRC_CONF, "Number of children alive at the same time"), AP_INIT_TAKE1("StartThreads", set_threads_to_start, NULL, RSRC_CONF, @@ -1871,16 +1743,10 @@ AP_INIT_TAKE1("MaxSpareThreads", set_max_spare_threads, NULL, RSRC_CONF, "Maximum number of idle threads per child"), AP_INIT_TAKE1("MaxThreadsPerChild", set_max_threads, NULL, RSRC_CONF, "Maximum number of threads per child"), -AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying."), -AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core"), AP_INIT_TAKE3("ChildperUserID", set_child_per_uid, NULL, RSRC_CONF, "Specify a User and Group for a specific child process."), AP_INIT_TAKE2("AssignUserID", assign_childuid, NULL, RSRC_CONF, "Tie a virtual host to a specific child process."), -AP_INIT_TAKE1("AcceptMutex", set_accept_lock_mech, NULL, RSRC_CONF, - "The system mutex implementation to use for the accept mutex"), { NULL } }; diff --git a/server/mpm/perchild/mpm.h b/server/mpm/perchild/mpm.h index d24f8b4aba..cdaa46e372 100644 --- a/server/mpm/perchild/mpm.h +++ b/server/mpm/perchild/mpm.h @@ -67,6 +67,13 @@ #define MPM_NAME "Perchild" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + #define AP_MPM_NEEDS_RECLAIM_CHILD_PROCESSES 1 #define MPM_SYNC_CHILD_TABLE() #define MPM_CHILD_PID(i) (ap_child_table[i].pid) @@ -86,6 +93,5 @@ extern int ap_threads_per_child; extern int ap_max_daemons_limit; extern ap_ctable ap_child_table[HARD_SERVER_LIMIT]; extern server_rec *ap_server_conf; -extern char ap_coredump_dir[MAX_STRING_LEN]; #endif /* APACHE_MPM_PERCHILD_H */ diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index 39a89a3207..efb68418ce 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -116,9 +116,8 @@ static int min_spare_threads = 0; static int max_spare_threads = 0; static int max_threads = 0; static int max_requests_per_child = 0; -static const char *ap_pid_fname=NULL; -static int num_daemons=0; -static int curr_child_num=0; +static int num_daemons = 0; +static int curr_child_num = 0; static int workers_may_exit = 0; static int requests_this_child; static int num_listenfds = 0; @@ -161,8 +160,6 @@ struct ap_ctable ap_child_table[HARD_SERVER_LIMIT]; int ap_max_daemons_limit = -1; int ap_threads_per_child = HARD_THREAD_LIMIT; -char ap_coredump_dir[MAX_STRING_LEN]; - module AP_MODULE_DECLARE_DATA mpm_perchild_module; static apr_file_t *pipe_of_death_in = NULL; @@ -214,9 +211,7 @@ static apr_lock_t *idle_thread_count_mutex; #else #define SAFE_ACCEPT(stmt) (stmt) static apr_lock_t *process_accept_mutex; -static apr_lockmech_e_np accept_lock_mech = APR_LOCK_DEFAULT; #endif /* NO_SERIALIZED_ACCEPT */ -static const char *lock_fname; static apr_lock_t *thread_accept_mutex; AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result) @@ -890,8 +885,8 @@ static void child_main(int child_num_arg) /*stuff to do before we switch id's, so we have permissions.*/ - rv = SAFE_ACCEPT(apr_lock_child_init(&process_accept_mutex, lock_fname, - pchild)); + rv = SAFE_ACCEPT(apr_lock_child_init(&process_accept_mutex, ap_lock_fname, + pchild)); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, "Couldn't initialize cross-process lock in child"); @@ -1198,12 +1193,12 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) ap_log_pid(pconf, ap_pid_fname); /* Initialize cross-process accept lock */ - lock_fname = apr_psprintf(_pconf, "%s.%u", - ap_server_root_relative(_pconf, lock_fname), + ap_lock_fname = apr_psprintf(_pconf, "%s.%u", + ap_server_root_relative(_pconf, ap_lock_fname), my_pid); rv = SAFE_ACCEPT(apr_lock_create_np(&process_accept_mutex, APR_MUTEX, APR_CROSS_PROCESS, accept_lock_mech, - lock_fname, _pconf)); + ap_lock_fname, _pconf)); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "Couldn't create cross-process lock"); @@ -1355,7 +1350,7 @@ static void perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *pte max_threads = HARD_THREAD_LIMIT; ap_pid_fname = DEFAULT_PIDLOG; ap_scoreboard_fname = DEFAULT_SCOREBOARD; - lock_fname = DEFAULT_LOCKFILE; + ap_lock_fname = DEFAULT_LOCKFILE; max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; curr_child_num = 0; @@ -1384,7 +1379,7 @@ static int pass_request(request_rec *r) &mpm_perchild_module); char *foo; apr_size_t len; - int zero = 0; + apr_off_t zero = 0; apr_pool_userdata_get((void **)&foo, "PERCHILD_BUFFER", r->connection->pool); len = strlen(foo); @@ -1518,7 +1513,7 @@ static int perchild_post_read(request_rec *r) return OK; } -static apr_status_t perchild_buffer(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_size_t *readbytes) +static apr_status_t perchild_buffer(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes) { apr_bucket *e; apr_status_t rv; @@ -1573,41 +1568,6 @@ static void perchild_hooks(apr_pool_t *p) ap_register_input_filter("PERCHILD_BUFFER", perchild_buffer, AP_FTYPE_CONTENT); } -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - -static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - lock_fname = arg; - return NULL; -} static const char *set_num_daemons (cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1721,38 +1681,6 @@ static const char *set_max_threads(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, - const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - static const char *set_child_per_uid(cmd_parms *cmd, void *dummy, const char *u, const char *g, const char *num) { @@ -1802,65 +1730,9 @@ static const char *assign_childuid(cmd_parms *cmd, void *dummy, const char *uid, return NULL; } -static const char *set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (!strcasecmp(arg, "default")) { - accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - accept_lock_mech = APR_LOCK_FCNTL; - } -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - else if (!strcasecmp(arg, "sysvsem")) { - accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "proc_pthread")) { - accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " - "ones for this platform are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - ", sysvsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", proc_pthread" -#endif - , NULL); - } - return NULL; -} - static const command_rec perchild_cmds[] = { UNIX_DAEMON_COMMANDS LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), -AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), AP_INIT_TAKE1("NumServers", set_num_daemons, NULL, RSRC_CONF, "Number of children alive at the same time"), AP_INIT_TAKE1("StartThreads", set_threads_to_start, NULL, RSRC_CONF, @@ -1871,16 +1743,10 @@ AP_INIT_TAKE1("MaxSpareThreads", set_max_spare_threads, NULL, RSRC_CONF, "Maximum number of idle threads per child"), AP_INIT_TAKE1("MaxThreadsPerChild", set_max_threads, NULL, RSRC_CONF, "Maximum number of threads per child"), -AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying."), -AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core"), AP_INIT_TAKE3("ChildperUserID", set_child_per_uid, NULL, RSRC_CONF, "Specify a User and Group for a specific child process."), AP_INIT_TAKE2("AssignUserID", assign_childuid, NULL, RSRC_CONF, "Tie a virtual host to a specific child process."), -AP_INIT_TAKE1("AcceptMutex", set_accept_lock_mech, NULL, RSRC_CONF, - "The system mutex implementation to use for the accept mutex"), { NULL } }; diff --git a/server/mpm/prefork/mpm.h b/server/mpm/prefork/mpm.h index efad24f9eb..429c61f1cb 100644 --- a/server/mpm/prefork/mpm.h +++ b/server/mpm/prefork/mpm.h @@ -68,6 +68,13 @@ #define MPM_NAME "Prefork" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + #define AP_MPM_USES_POD 1 #define AP_MPM_NEEDS_RECLAIM_CHILD_PROCESSES 1 #define MPM_SYNC_CHILD_TABLE() (ap_sync_scoreboard_image()) @@ -77,5 +84,4 @@ extern int ap_threads_per_child; extern int ap_max_daemons_limit; extern server_rec *ap_server_conf; -extern char ap_coredump_dir[MAX_STRING_LEN]; #endif /* APACHE_MPM_PREFORK_H */ diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index fda1f03601..c83077d7cf 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -134,11 +134,7 @@ /* config globals */ int ap_threads_per_child=0; /* Worker threads per child */ -static int ap_max_requests_per_child=0; -static const char *ap_pid_fname=NULL; static apr_lock_t *accept_lock; -static const char *ap_lock_fname; -static apr_lockmech_e_np accept_lock_mech = APR_LOCK_DEFAULT; static int ap_daemons_to_start=0; static int ap_daemons_min_free=0; static int ap_daemons_max_free=0; @@ -154,8 +150,6 @@ static ap_pod_t *pod; int ap_max_daemons_limit = -1; server_rec *ap_server_conf; -char ap_coredump_dir[MAX_STRING_LEN]; - /* *Non*-shared http_main globals... */ static apr_socket_t *sd; @@ -1348,42 +1342,6 @@ static void prefork_hooks(apr_pool_t *p) ap_hook_pre_config(prefork_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - -static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_lock_fname = arg; - return NULL; -} - static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1455,96 +1413,9 @@ static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *ar return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - -static const char *set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (!strcasecmp(arg, "default")) { - accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - accept_lock_mech = APR_LOCK_FCNTL; - } -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - else if (!strcasecmp(arg, "sysvsem")) { - accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "proc_pthread")) { - accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " - "ones for this platform are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - ", sysvsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", proc_pthread" -#endif - , NULL); - } - return NULL; -} - static const command_rec prefork_cmds[] = { UNIX_DAEMON_COMMANDS LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), -AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF, "Number of child processes launched at server startup"), AP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF, @@ -1553,12 +1424,6 @@ AP_INIT_TAKE1("MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF, "Maximum number of idle children"), AP_INIT_TAKE1("MaxClients", set_server_limit, NULL, RSRC_CONF, "Maximum number of children alive at the same time"), -AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying."), -AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core"), -AP_INIT_TAKE1("AcceptMutex", set_accept_lock_mech, NULL, RSRC_CONF, - "The system mutex implementation to use for the accept mutex"), { NULL } }; diff --git a/server/mpm/spmt_os2/mpm.h b/server/mpm/spmt_os2/mpm.h index 96062ed7d6..26c65cbced 100644 --- a/server/mpm/spmt_os2/mpm.h +++ b/server/mpm/spmt_os2/mpm.h @@ -67,7 +67,10 @@ #define MPM_NAME "SPMT_OS2" -extern char ap_coredump_dir[MAX_STRING_LEN]; +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR + extern server_rec *ap_server_conf; extern int ap_threads_per_child; diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index f8b9c859db..e9f60b513b 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -84,8 +84,6 @@ /* config globals */ -static int ap_max_requests_per_child=0; -static const char *ap_pid_fname=NULL; static int ap_daemons_to_start=0; static int ap_daemons_min_free=0; static int ap_daemons_max_free=0; @@ -149,8 +147,6 @@ static void clean_child_exit(int code) _endthread(); } - - static apr_lock_t *accept_mutex = NULL; static apr_status_t accept_mutex_child_cleanup(void *foo) @@ -1177,20 +1173,6 @@ static void spmt_os2_hooks(apr_pool_t *p) ap_hook_pre_config(spmt_os2_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1262,37 +1244,6 @@ static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *ar return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - /* Stub functions until this MPM supports the connection status API */ AP_DECLARE(void) ap_update_connection_status(long conn_id, const char *key, \ @@ -1308,8 +1259,6 @@ AP_DECLARE(void) ap_reset_connection_status(long conn_id) static const command_rec spmt_os2_cmds[] = { LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), AP_INIT_TAKE1( "StartServers", set_daemons_to_start, NULL, RSRC_CONF, "Number of child processes launched at server startup" ), AP_INIT_TAKE1( "MinSpareServers", set_min_free_servers, NULL, RSRC_CONF, @@ -1318,10 +1267,6 @@ AP_INIT_TAKE1( "MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF, "Maximum number of idle children" ), AP_INIT_TAKE1( "MaxClients", set_server_limit, NULL, RSRC_CONF, "Maximum number of children alive at the same time" ), -AP_INIT_TAKE1( "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying." ), -AP_INIT_TAKE1( "CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core" ), { NULL } }; diff --git a/server/mpm/threaded/mpm.h b/server/mpm/threaded/mpm.h index 51a3965ce3..3c58c70836 100644 --- a/server/mpm/threaded/mpm.h +++ b/server/mpm/threaded/mpm.h @@ -65,6 +65,13 @@ #define MPM_NAME "Threaded" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + #define AP_MPM_NEEDS_RECLAIM_CHILD_PROCESSES 1 #define MPM_SYNC_CHILD_TABLE() (ap_sync_scoreboard_image()) #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) @@ -73,6 +80,5 @@ extern int ap_threads_per_child; extern int ap_max_daemons_limit; extern server_rec *ap_server_conf; -extern char ap_coredump_dir[MAX_STRING_LEN]; #endif /* APACHE_MPM_THREADED_H */ diff --git a/server/mpm/threaded/threaded.c b/server/mpm/threaded/threaded.c index 50bfc5d596..a35dfb636b 100644 --- a/server/mpm/threaded/threaded.c +++ b/server/mpm/threaded/threaded.c @@ -105,8 +105,6 @@ */ int ap_threads_per_child=0; /* Worker threads per child */ -static int ap_max_requests_per_child=0; -static const char *ap_pid_fname=NULL; static int ap_daemons_to_start=0; static int min_spare_threads=0; static int max_spare_threads=0; @@ -141,8 +139,6 @@ typedef struct { */ int ap_max_daemons_limit = -1; -char ap_coredump_dir[MAX_STRING_LEN]; - static apr_file_t *pipe_of_death_in = NULL; static apr_file_t *pipe_of_death_out = NULL; static apr_lock_t *pipe_of_death_mutex; /* insures that a child process only @@ -181,8 +177,6 @@ static apr_lock_t *worker_thread_count_mutex; /* Locks for accept serialization */ static apr_lock_t *accept_mutex; -static apr_lockmech_e_np accept_lock_mech = APR_LOCK_DEFAULT; -static const char *lock_fname; #ifdef NO_SERIALIZED_ACCEPT #define SAFE_ACCEPT(stmt) APR_SUCCESS @@ -1387,44 +1381,6 @@ static void threaded_hooks(apr_pool_t *p) ap_hook_pre_config(threaded_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } - -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, - const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - -static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - lock_fname = arg; - return NULL; -} - static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg) { @@ -1529,98 +1485,9 @@ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, - const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, - const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - -static const char *set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (!strcasecmp(arg, "default")) { - accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - accept_lock_mech = APR_LOCK_FCNTL; - } -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - else if (!strcasecmp(arg, "sysvsem")) { - accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "proc_pthread")) { - accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " - "ones for this platform are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - ", sysvsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", proc_pthread" -#endif - , NULL); - } - return NULL; -} - static const command_rec threaded_cmds[] = { UNIX_DAEMON_COMMANDS LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), -AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF, "Number of child processes launched at server startup"), AP_INIT_TAKE1("MinSpareThreads", set_min_spare_threads, NULL, RSRC_CONF, @@ -1631,12 +1498,6 @@ AP_INIT_TAKE1("MaxClients", set_server_limit, NULL, RSRC_CONF, "Maximum number of children alive at the same time"), AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, "Number of threads each child creates"), -AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying."), -AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core"), -AP_INIT_TAKE1("AcceptMutex", set_accept_lock_mech, NULL, RSRC_CONF, - "The system mutex implementation to use for the accept mutex"), { NULL } }; diff --git a/server/mpm/winnt/mpm.h b/server/mpm/winnt/mpm.h index 9d8bb4ef33..82e944f4f6 100644 --- a/server/mpm/winnt/mpm.h +++ b/server/mpm/winnt/mpm.h @@ -68,6 +68,13 @@ #define MPM_NAME "WinNT" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + extern int ap_threads_per_child; #endif /* APACHE_MPM_H */ diff --git a/server/mpm/worker/mpm.h b/server/mpm/worker/mpm.h index 23ed27c1ea..8611da0912 100644 --- a/server/mpm/worker/mpm.h +++ b/server/mpm/worker/mpm.h @@ -65,6 +65,13 @@ #define MPM_NAME "Worker" +#define AP_MPM_WANT_SET_PIDFILE +#define AP_MPM_WANT_SET_SCOREBOARD +#define AP_MPM_WANT_SET_LOCKFILE +#define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH + #define AP_MPM_NEEDS_RECLAIM_CHILD_PROCESSES 1 #define MPM_SYNC_CHILD_TABLE() (ap_sync_scoreboard_image()) #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 6f6211068e..b1a4bdbc6c 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -1425,44 +1425,6 @@ static void worker_hooks(apr_pool_t *p) ap_hook_pre_config(worker_pre_config, NULL, NULL, APR_HOOK_MIDDLE); } - -static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (cmd->server->is_virtual) { - return "PidFile directive not allowed in "; - } - ap_pid_fname = arg; - return NULL; -} - -static const char *set_scoreboard(cmd_parms *cmd, void *dummy, - const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_scoreboard_fname = arg; - return NULL; -} - -static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - lock_fname = arg; - return NULL; -} - static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg) { @@ -1567,98 +1529,9 @@ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, return NULL; } -static const char *set_max_requests(cmd_parms *cmd, void *dummy, - const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - ap_max_requests_per_child = atoi(arg); - - return NULL; -} - -static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, - const char *arg) -{ - apr_finfo_t finfo; - const char *fname; - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - fname = ap_server_root_relative(cmd->pool, arg); - if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) - || (finfo.filetype != APR_DIR)) { - return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, - " does not exist or is not a directory", NULL); - } - apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); - return NULL; -} - -static const char *set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - if (!strcasecmp(arg, "default")) { - accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - accept_lock_mech = APR_LOCK_FCNTL; - } -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - else if (!strcasecmp(arg, "sysvsem")) { - accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "proc_pthread")) { - accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " - "ones for this platform are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE - ", sysvsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", proc_pthread" -#endif - , NULL); - } - return NULL; -} - static const command_rec worker_cmds[] = { UNIX_DAEMON_COMMANDS LISTEN_COMMANDS -AP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF, - "A file for logging the server process ID"), -AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, - "A file for Apache to maintain runtime process management information"), -AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF, "Number of child processes launched at server startup"), AP_INIT_TAKE1("MinSpareThreads", set_min_spare_threads, NULL, RSRC_CONF, @@ -1669,12 +1542,6 @@ AP_INIT_TAKE1("MaxClients", set_server_limit, NULL, RSRC_CONF, "Maximum number of children alive at the same time"), AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, "Number of threads each child creates"), -AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, - "Maximum number of requests a particular child serves before dying."), -AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, - "The location of the directory Apache changes to before dumping core"), -AP_INIT_TAKE1("AcceptMutex", set_accept_lock_mech, NULL, RSRC_CONF, - "The system mutex implementation to use for the accept mutex"), { NULL } }; diff --git a/server/mpm_common.c b/server/mpm_common.c index e077ed0164..d8222060c7 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -70,6 +70,8 @@ #include "apr.h" #include "apr_thread_proc.h" #include "apr_signal.h" +#include "apr_strings.h" +#include "apr_lock.h" #include "httpd.h" #include "http_config.h" @@ -80,6 +82,10 @@ #include "ap_mpm.h" #include "ap_listen.h" +#ifdef AP_MPM_WANT_SET_SCOREBOARD +#include "scoreboard.h" +#endif + #ifdef HAVE_PWD_H #include #endif @@ -455,7 +461,7 @@ AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod) return APR_SUCCESS; } -AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num) +void ap_mpm_pod_killpg(ap_pod_t *pod, int num) { int i; apr_status_t rv = APR_SUCCESS; @@ -464,4 +470,147 @@ AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num) rv = ap_mpm_pod_signal(pod); } } +#endif /* #ifdef AP_MPM_USES_POD */ + +/* standard mpm configuration handling */ +#ifdef AP_MPM_WANT_SET_PIDFILE +const char *ap_pid_fname = NULL; + +AP_DECLARE(const char *)ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + if (cmd->server->is_virtual) { + return "PidFile directive not allowed in "; + } + ap_pid_fname = arg; + return NULL; +} +#endif + +#ifdef AP_MPM_WANT_SET_SCOREBOARD +AP_DECLARE(const char *) ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + ap_scoreboard_fname = arg; + return NULL; +} +#endif + +#ifdef AP_MPM_WANT_SET_LOCKFILE +const char *ap_lock_fname = NULL; +AP_DECLARE(const char *) ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + ap_lock_fname = arg; + return NULL; +} +#endif + +#ifdef AP_MPM_WANT_SET_MAX_REQUESTS +int ap_max_requests_per_child = 0; +AP_DECLARE(const char *) ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + ap_max_requests_per_child = atoi(arg); + + return NULL; +} +#endif + +#ifdef AP_MPM_WANT_SET_COREDUMPDIR +char ap_coredump_dir[MAX_STRING_LEN]; +AP_DECLARE(const char *) ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, + const char *arg) +{ + apr_finfo_t finfo; + const char *fname; + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + fname = ap_server_root_relative(cmd->pool, arg); + if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS) + || (finfo.filetype != APR_DIR)) { + return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, + " does not exist or is not a directory", NULL); + } + apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir)); + return NULL; +} +#endif + +#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH +apr_lockmech_e_np accept_lock_mech = APR_LOCK_DEFAULT; +AP_DECLARE(const char *) ap_mpm_set_accept_lock_mech(cmd_parms *cmd, + void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + if (!strcasecmp(arg, "default")) { + accept_lock_mech = APR_LOCK_DEFAULT; + } +#if APR_HAS_FLOCK_SERIALIZE + else if (!strcasecmp(arg, "flock")) { + accept_lock_mech = APR_LOCK_FLOCK; + } +#endif +#if APR_HAS_FCNTL_SERIALIZE + else if (!strcasecmp(arg, "fcntl")) { + accept_lock_mech = APR_LOCK_FCNTL; + } +#endif +#if APR_HAS_SYSVSEM_SERIALIZE + else if (!strcasecmp(arg, "sysvsem")) { + accept_lock_mech = APR_LOCK_SYSVSEM; + } +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + else if (!strcasecmp(arg, "proc_pthread")) { + accept_lock_mech = APR_LOCK_PROC_PTHREAD; + } +#endif + else { + return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; valid " + "ones for this platform are: default" +#if APR_HAS_FLOCK_SERIALIZE + ", flock" +#endif +#if APR_HAS_FCNTL_SERIALIZE + ", fcntl" +#endif +#if APR_HAS_SYSVSEM_SERIALIZE + ", sysvsem" +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + ", proc_pthread" +#endif + , NULL); + } + return NULL; +} #endif