From: Rainer Jung Date: Sat, 12 Nov 2011 07:15:45 +0000 (+0000) Subject: Pre GA removal of components that will not be included: X-Git-Tag: 2.3.16~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc4b704ff0d55104859f612947750c4729bf0f99;p=apache Pre GA removal of components that will not be included: Part 3: Remote MPM simple. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1201214 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 2acf4c0f14..cbc0d53dcd 100644 --- a/CHANGES +++ b/CHANGES @@ -2,8 +2,9 @@ Changes with Apache 2.4.0 *) Pre GA removal ob components that will not be included: - - mod_noloris was superseded by mod_reqtimeout. + - mod_noloris was superseded by mod_reqtimeout - mod_serf + - mpm_simple [Rainer Jung] *) core: Set MaxMemFree 2048 by default. [Stefan Fritsch] diff --git a/STATUS b/STATUS index b67673626b..07fdfb8fd5 100644 --- a/STATUS +++ b/STATUS @@ -81,13 +81,8 @@ RELEASE SHOWSTOPPERS: * Modules that are not ready for production use must be removed. The same for modules without documentation. - These modulese will be removed after branching 2.4.x from trunk. - If anyone disagrees, please comment. - - - MPM simple (unfinished; buggy) - See https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x/docs/STATUS - under 'modules docs' for a more comprehensive list of undocumented modules. + under 'modules docs' for a comprehensive list of undocumented modules. * The mod_session* modules need to be checked that their hooks respect the returning of int (HTTP status codes) and apr_status_t as appropriate, diff --git a/docs/STATUS b/docs/STATUS index 855aae71b2..1389906914 100644 --- a/docs/STATUS +++ b/docs/STATUS @@ -64,7 +64,6 @@ To Do List - mod_socache_dbm - mod_socache_memcache - mod_socache_shmcb - - mpm_simple the list may be incomplete maybe some of the modules will not be included in 2.4 - mod_suexec: very little documentation diff --git a/docs/conf/extra/httpd-mpm.conf.in b/docs/conf/extra/httpd-mpm.conf.in index 4286ded333..b64da4ef90 100644 --- a/docs/conf/extra/httpd-mpm.conf.in +++ b/docs/conf/extra/httpd-mpm.conf.in @@ -18,14 +18,6 @@ # active mpm. # -# Simple MPM -# SimpleProcCount: Number of child processes launched at server startup -# SimpleThreadCount: Set the number of Worker Threads Per-Process - - SimpleProcCount 5 - SimpleThreadCount 5 - - # prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare diff --git a/modules/arch/unix/config5.m4 b/modules/arch/unix/config5.m4 index 01c6e6938e..1bf73dd581 100644 --- a/modules/arch/unix/config5.m4 +++ b/modules/arch/unix/config5.m4 @@ -1,8 +1,7 @@ APACHE_MODPATH_INIT(arch/unix) -if ap_mpm_is_enabled "simple" \ - || ap_mpm_is_enabled "worker" \ +if || ap_mpm_is_enabled "worker" \ || ap_mpm_is_enabled "event" \ || ap_mpm_is_enabled "prefork"; then unixd_mods_enable=yes diff --git a/server/mpm/MPM.NAMING b/server/mpm/MPM.NAMING index 1cc0c7c4ff..c07884d475 100644 --- a/server/mpm/MPM.NAMING +++ b/server/mpm/MPM.NAMING @@ -1,14 +1,14 @@ The following MPMs currently exist: - simple ........ Single or Multi Process, with Preforking or Threading, - depending on configuration and operating systems. Should - be able to run on all modern operating systems. prefork ....... Multi Process Model with Preforking (Apache 1.3) mpmt_os2 ...... Multi Process Model with Threading on OS/2 Constant number of processes, variable number of threads. One acceptor thread per process, multiple workers threads. winnt ......... Single Process Model with Threading on Windows NT + event ......... Multi Process model with threads. One acceptor thread, + multiple worker threads, separate poller threads for idle + connections and asynchoneous write completion. worker ........ Multi Process model with threads. One acceptor thread, multiple worker threads. netware ....... Multi-threaded MPM for Netware diff --git a/server/mpm/config2.m4 b/server/mpm/config2.m4 index 3482d3f414..d7e73ec05e 100644 --- a/server/mpm/config2.m4 +++ b/server/mpm/config2.m4 @@ -1,7 +1,7 @@ AC_MSG_CHECKING(which MPM to use by default) AC_ARG_WITH(mpm, APACHE_HELP_STRING(--with-mpm=MPM,Choose the process model for Apache to use by default. - MPM={simple|event|worker|prefork|winnt} + MPM={event|worker|prefork|winnt} This will be statically linked as the only available MPM unless --enable-mpms-shared is also specified. ),[ diff --git a/server/mpm/simple/Makefile.in b/server/mpm/simple/Makefile.in deleted file mode 100644 index f34af9cbd6..0000000000 --- a/server/mpm/simple/Makefile.in +++ /dev/null @@ -1 +0,0 @@ -include $(top_srcdir)/build/special.mk diff --git a/server/mpm/simple/SIMPLE.README b/server/mpm/simple/SIMPLE.README deleted file mode 100644 index 0d6d7edfee..0000000000 --- a/server/mpm/simple/SIMPLE.README +++ /dev/null @@ -1,6 +0,0 @@ -The Simple MPM aims to create a single MPM, that runs on all modern -Unix and Win32 platforms, by using APR as much as possible. - -The Simple MPM core run loop revovles around a Poll CB event system, with -timers being built in. When an event, either an IO or Timer is ready to run, -it is dispatched to any available threads in the current process. diff --git a/server/mpm/simple/config.m4 b/server/mpm/simple/config.m4 deleted file mode 100644 index 82500d278a..0000000000 --- a/server/mpm/simple/config.m4 +++ /dev/null @@ -1,13 +0,0 @@ -AC_MSG_CHECKING(if simple MPM supports this platform) -if test $forking_mpms_supported != yes; then - AC_MSG_RESULT(no - This is not a forking platform) -elif test $ac_cv_define_APR_HAS_THREADS != yes; then - AC_MSG_RESULT(no - APR does not support threads) -elif test $have_threaded_sig_graceful != yes; then - AC_MSG_RESULT(no - SIG_GRACEFUL cannot be used with a threaded MPM) -elif test $ac_cv_have_threadsafe_pollset != yes; then - AC_MSG_RESULT(no - APR_POLLSET_THREADSAFE is not supported) -else - AC_MSG_RESULT(yes) - APACHE_MPM_SUPPORTED(simple, yes, yes) -fi diff --git a/server/mpm/simple/config3.m4 b/server/mpm/simple/config3.m4 deleted file mode 100644 index e518119518..0000000000 --- a/server/mpm/simple/config3.m4 +++ /dev/null @@ -1,3 +0,0 @@ -simple_objects="simple_api.lo simple_children.lo simple_core.lo \ -simple_event.lo simple_run.lo simple_io.lo" -APACHE_MPM_MODULE(simple, $enable_mpm_simple, $simple_objects) diff --git a/server/mpm/simple/simple_api.c b/server/mpm/simple/simple_api.c deleted file mode 100644 index 6de5226a6b..0000000000 --- a/server/mpm/simple/simple_api.c +++ /dev/null @@ -1,277 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ap_mpm.h" -#include "httpd.h" -#include "http_config.h" -#include "mpm_common.h" -#include "http_log.h" -#include "scoreboard.h" -#include "ap_listen.h" -#include "simple_types.h" -#include "simple_run.h" -#include "http_core.h" - -/* This file contains the absolute minimal MPM API, to interface with httpd. */ - -static int simple_run(apr_pool_t * pconf, apr_pool_t * plog, server_rec * s) -{ - simple_core_t *sc = simple_core_get(); - - sc->mpm_state = AP_MPMQ_RUNNING; - - if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { - sc->mpm_state = AP_MPMQ_STOPPING; - return DONE; - } - - return simple_main_loop(sc); -} - -static int simple_query(int query_code, int *result, apr_status_t *rv) -{ - simple_core_t *sc = simple_core_get(); - - *rv = APR_SUCCESS; - switch (query_code) { - case AP_MPMQ_IS_THREADED: - *result = AP_MPMQ_STATIC; - break; - case AP_MPMQ_IS_FORKED: - *result = AP_MPMQ_DYNAMIC; - break; - case AP_MPMQ_IS_ASYNC: - *result = 1; - break; - case AP_MPMQ_MAX_DAEMON_USED: - *result = sc->procmgr.proc_count; - break; - case AP_MPMQ_HARD_LIMIT_DAEMONS: - *result = sc->procmgr.proc_count; - break; - case AP_MPMQ_HARD_LIMIT_THREADS: - *result = sc->procmgr.thread_count; - break; - case AP_MPMQ_MAX_THREADS: - *result = sc->procmgr.thread_count; - break; - case AP_MPMQ_MAX_SPARE_DAEMONS: - *result = sc->procmgr.proc_count; - break; - case AP_MPMQ_MIN_SPARE_DAEMONS: - *result = sc->procmgr.proc_count; - break; - case AP_MPMQ_MIN_SPARE_THREADS: - case AP_MPMQ_MAX_SPARE_THREADS: - *result = sc->procmgr.thread_count; - break; - case AP_MPMQ_MAX_REQUESTS_DAEMON: - *result = sc->procmgr.max_requests_per_child; - break; - case AP_MPMQ_MAX_DAEMONS: - *result = sc->procmgr.proc_count; - break; - case AP_MPMQ_MPM_STATE: - *result = sc->mpm_state; - break; - case AP_MPMQ_GENERATION: - *result = 0; - break; - default: - *rv = APR_ENOTIMPL; - break; - } - return OK; -} - -static const char * -simple_get_name(void) -{ - return "simple"; -} - -static int -simple_open_logs(apr_pool_t * p, - apr_pool_t * plog, apr_pool_t * ptemp, server_rec * s) -{ - int nsock; - - nsock = ap_setup_listeners(s); - - if (nsock < 1) { - ap_log_error(APLOG_MARK, APLOG_ALERT, 0, - s, - "simple_open_logs: no listening sockets available, shutting down"); - return DONE; - } - - return OK; -} - -static int -simple_pre_config(apr_pool_t * pconf, apr_pool_t * plog, apr_pool_t * ptemp) -{ - int run_debug; - apr_status_t rv; - simple_core_t *sc; - - /* this is our first 'real' entry point, so setup everything here. */ - rv = simple_core_init_once(); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_core_init_once: Fatal Error Encountered"); - return HTTP_INTERNAL_SERVER_ERROR; - } - - sc = simple_core_get(); - - sc->restart_num++; - - run_debug = ap_exists_config_define("DEBUG"); - - if (run_debug) { - sc->run_foreground = 1; - sc->run_single_process = 1; - } - else { - sc->run_foreground = ap_exists_config_define("FOREGROUND"); - } - - if (sc->restart_num == 2) { - - if (sc->run_foreground) { - rv = apr_proc_detach(APR_PROC_DETACH_FOREGROUND); - } - else { - rv = apr_proc_detach(APR_PROC_DETACH_DAEMONIZE); - } - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_pre_config: apr_proc_detach(%s) failed", - sc->run_foreground ? "FOREGROUND" : "DAEMONIZE"); - return HTTP_INTERNAL_SERVER_ERROR; - } - } - - return OK; -} - -static int -simple_check_config(apr_pool_t * p, apr_pool_t * plog, - apr_pool_t * ptemp, server_rec * s) -{ - simple_core_t *sc = simple_core_get(); - - if (sc->procmgr.proc_count > SIMPLE_MAX_PROC) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, - "simple_check_config: SimpleProcCount must be at most %d", - SIMPLE_MAX_PROC); - return !OK; - } - - if (sc->procmgr.proc_count < SIMPLE_MIN_PROC) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, - "simple_check_config: SimpleProcCount must be at least %d", - SIMPLE_MIN_PROC); - return !OK; - } - - if (sc->procmgr.thread_count > SIMPLE_MAX_THREADS) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, - "simple_check_config: SimpleThreadCount must be at most %d", - SIMPLE_MAX_THREADS); - return !OK; - } - - if (sc->procmgr.thread_count < SIMPLE_MIN_THREADS) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, - "simple_check_config: SimpleThreadCount must be at least %d", - SIMPLE_MIN_THREADS); - return !OK; - } - - return OK; -} - -static void simple_hooks(apr_pool_t * p) -{ - static const char *const aszSucc[] = { "core.c", NULL }; - - ap_hook_open_logs(simple_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); - - ap_hook_pre_config(simple_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST); - - ap_hook_check_config(simple_check_config, NULL, NULL, APR_HOOK_MIDDLE); - - ap_hook_mpm(simple_run, NULL, NULL, APR_HOOK_MIDDLE); - - ap_hook_mpm_query(simple_query, NULL, NULL, APR_HOOK_MIDDLE); - - ap_hook_mpm_get_name(simple_get_name, NULL, NULL, APR_HOOK_MIDDLE); -} - -static const char *set_proccount(cmd_parms * cmd, void *baton, - const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - - simple_core_get()->procmgr.proc_count = atoi(arg); - return NULL; -} - - -static const char *set_threadcount(cmd_parms * cmd, void *baton, - const char *arg) -{ - simple_core_t *sc = simple_core_get(); - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - - if (err != NULL) { - return err; - } - - sc->procmgr.thread_count = atoi(arg); - - return NULL; -} - -static const command_rec simple_cmds[] = { - AP_INIT_TAKE1("SimpleProcCount", set_proccount, NULL, RSRC_CONF, - "Number of child processes launched at server startup"), - AP_INIT_TAKE1("SimpleThreadCount", set_threadcount, NULL, RSRC_CONF, - "Set the number of Worker Threads Per-Process"), - /* pqXXXXXXXXX: These do NOT belong in the MPM configuration commands. */ - LISTEN_COMMANDS, - {NULL} -}; - - - -AP_DECLARE_MODULE(mpm_simple) = { - MPM20_MODULE_STUFF, - NULL, /* hook to run before apache parses args */ - NULL, /* create per-directory config structure */ - NULL, /* merge per-directory config structures */ - NULL, /* create per-server config structure */ - NULL, /* merge per-server config structures */ - simple_cmds, /* command apr_table_t */ - simple_hooks /* register_hooks */ -}; diff --git a/server/mpm/simple/simple_children.c b/server/mpm/simple/simple_children.c deleted file mode 100644 index 0476f59caf..0000000000 --- a/server/mpm/simple/simple_children.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "httpd.h" -#include "http_config.h" -#include "simple_types.h" -#include "simple_event.h" -#include "simple_run.h" -#include "http_log.h" -#include "simple_children.h" -#include "apr_hash.h" - -#include /* For fork() */ - -#define SPAWN_CHILDREN_INTERVAL (apr_time_from_sec(5)) - -APLOG_USE_MODULE(mpm_simple); - -static void simple_kill_random_child(simple_core_t * sc) -{ - /* See comment in simple_spawn_child for why we check here. */ - if (!sc->run_single_process) { - apr_hash_index_t *hi; - simple_child_t *child = NULL; - - apr_thread_mutex_lock(sc->mtx); - hi = apr_hash_first(sc->pool, sc->children); - if (hi != NULL) { - apr_hash_this(hi, NULL, NULL, (void **)&child); - apr_hash_set(sc->children, &child->pid, sizeof(child->pid), NULL); - } - apr_thread_mutex_unlock(sc->mtx); - - if (child != NULL) { - kill(child->pid, 9); - /* TODO: recycle child object */ - } - } -} - -static void clean_child_exit(int code) __attribute__ ((noreturn)); -static void clean_child_exit(int code) -{ - /* TODO: Pool cleanups.... sigh. */ - exit(code); -} - -static int simple_spawn_child(simple_core_t * sc) -{ - pid_t pid = 0; - int rv = 0; - /* Although we could cut this off 'earlier', and not even invoke this - * function, I would like to keep the functions invoked when in debug mode - * to be as close as possible to those when not in debug... So, we just skip - * the actual spawn itself, but go through all of the motions... - */ - if (!sc->run_single_process) { - if (sc->spawn_via == SIMPLE_SPAWN_FORK) { - - pid = fork(); - if (pid == -1) { - rv = errno; - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_spawn_child: Unable to fork new process"); - return rv; - } - - if (pid == 0) { - /* this is the child process */ - - rv = simple_child_loop(sc); - - if (rv) { - clean_child_exit(APEXIT_CHILDFATAL); - } - else { - clean_child_exit(0); - } - } - } - else { - /* TODO: SIMPLE_SPAWN_EXEC */ - abort(); - } - } - - if (pid != 0) { - simple_child_t *child; - - apr_thread_mutex_lock(sc->mtx); - - child = apr_palloc(sc->pool, sizeof(simple_child_t)); - child->pid = pid; - apr_hash_set(sc->children, &child->pid, sizeof(child->pid), child); - - apr_thread_mutex_unlock(sc->mtx); - } - - return 0; -} - -void simple_check_children_size(simple_core_t * sc, void *baton) -{ - unsigned int count; - int wanted; - int i; - - simple_register_timer(sc, - simple_check_children_size, - NULL, SPAWN_CHILDREN_INTERVAL, - sc->pool); - - if (sc->run_single_process && sc->restart_num == 2) { - static int run = 0; - /* This is kinda of hack, but rather than spawning a child process, - * we register the normal IO handlers in the main event loop.... - */ - if (run == 0) { - simple_single_process_hack(sc); - run++; - } - } - - { - apr_thread_mutex_lock(sc->mtx); - count = apr_hash_count(sc->children); - wanted = sc->procmgr.proc_count; - apr_thread_mutex_unlock(sc->mtx); - } - - if (count > wanted) { - /* kill some kids */ - int to_kill = count - wanted; - for (i = 0; i < to_kill; i++) { - simple_kill_random_child(sc); - } - } - else if (count < wanted) { - int rv = 0; - /* spawn some kids */ - int to_spawn = wanted - count; - for (i = 0; rv == 0 && i < to_spawn; i++) { - rv = simple_spawn_child(sc); - } - } - else { - /* juuuuust right. */ - } -} diff --git a/server/mpm/simple/simple_children.h b/server/mpm/simple/simple_children.h deleted file mode 100644 index e43f8bbb47..0000000000 --- a/server/mpm/simple/simple_children.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "simple_types.h" - -#ifndef APACHE_MPM_SIMPLE_CHILDREN_H -#define APACHE_MPM_SIMPLE_CHILDREN_H - -void simple_check_children_size(simple_core_t * sc, void *baton); - -void simple_check_children_status(simple_core_t * sc, void *baton); - - -#endif /* APACHE_MPM_SIMPLE_CHILDREN_H */ diff --git a/server/mpm/simple/simple_core.c b/server/mpm/simple/simple_core.c deleted file mode 100644 index aa682110d9..0000000000 --- a/server/mpm/simple/simple_core.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Simple Core utility methods. - */ - -#include "simple_types.h" -#include "ap_mpm.h" -#include "httpd.h" -#include "http_log.h" -#include "http_config.h" -#include "http_main.h" - -static simple_core_t *g_simple_core; - -APLOG_USE_MODULE(mpm_simple); - -simple_core_t *simple_core_get() -{ - return g_simple_core; -} - -apr_status_t simple_core_init_once(void) -{ - apr_status_t rv; - const char *userdata_key = "mpm_simple_module"; - simple_core_t *sc; - - g_simple_core = ap_retained_data_get(userdata_key); - if (g_simple_core) { - return APR_SUCCESS; - } - - sc = g_simple_core = ap_retained_data_create(userdata_key, sizeof(*g_simple_core)); - - apr_pool_create(&sc->pool, ap_pglobal); - - apr_pool_tag(sc->pool, "simple-mpm-core"); - - sc->mpm_state = AP_MPMQ_STARTING; - sc->procmgr.proc_count = SIMPLE_DEF_PROC; - sc->procmgr.thread_count = SIMPLE_DEF_THREADS; - sc->procmgr.max_requests_per_child = 0; /* unlimited */ - - sc->children = apr_hash_make(sc->pool); - /* TODO: configurable spawning mech */ - sc->spawn_via = SIMPLE_SPAWN_FORK; - - APR_RING_INIT(&sc->timer_ring, simple_timer_t, link); - - rv = apr_thread_mutex_create(&sc->mtx, 0, sc->pool); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_core_init_once: apr_thread_mutex_create failed."); - return rv; - } - - return APR_SUCCESS; -} diff --git a/server/mpm/simple/simple_event.c b/server/mpm/simple/simple_event.c deleted file mode 100644 index 6157c03441..0000000000 --- a/server/mpm/simple/simple_event.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* #define APR_RING_DEBUG 1 */ - -#include "simple_types.h" -#include "simple_event.h" - -static apr_status_t -simple_timer_pool_cleanup(void *baton) -{ - simple_timer_t *elem = (simple_timer_t *)baton; - simple_core_t *sc = elem->sc; - - apr_thread_mutex_lock(sc->mtx); - APR_RING_REMOVE(elem, link); - apr_thread_mutex_unlock(sc->mtx); - - return APR_SUCCESS; -} - - -void -simple_register_timer(simple_core_t * sc, - simple_timer_cb cb, - void *baton, apr_time_t relative_time, - apr_pool_t *shutdown_pool) -{ - simple_timer_t *elem = NULL; - simple_timer_t *ep = NULL; - int inserted = 0; - apr_time_t t = apr_time_now() + relative_time; - - apr_thread_mutex_lock(sc->mtx); - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - elem = (simple_timer_t *) apr_pcalloc(shutdown_pool, sizeof(simple_timer_t)); - - APR_RING_ELEM_INIT(elem, link); - elem->expires = t; - elem->cb = cb; - elem->baton = baton; - elem->pool = shutdown_pool; - elem->sc = sc; - apr_pool_cleanup_register(elem->pool, elem, simple_timer_pool_cleanup, apr_pool_cleanup_null); - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - /* pqXXXXXX: skiplist would be a nice optimization here. */ - if (!APR_RING_EMPTY(&sc->timer_ring, simple_timer_t, link)) { - ep = APR_RING_FIRST(&sc->timer_ring); - while (inserted == 0 && - ep != APR_RING_SENTINEL(&sc->timer_ring, simple_timer_t, link)) - { - if (ep->expires < elem->expires) { - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, - link); - APR_RING_INSERT_BEFORE(ep, elem, link); - inserted = 1; - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, - link); - } - ep = APR_RING_NEXT(ep, link); - } - } - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - if (!inserted) { - APR_RING_INSERT_TAIL(&sc->timer_ring, elem, simple_timer_t, link); - } - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - apr_thread_mutex_unlock(sc->mtx); -} - - -void -simple_timer_run(simple_timer_t *ep) -{ - apr_pool_cleanup_kill(ep->pool, ep, simple_timer_pool_cleanup); - - ep->cb(ep->sc, ep->baton); -} - - diff --git a/server/mpm/simple/simple_event.h b/server/mpm/simple/simple_event.h deleted file mode 100644 index ebc54c6a77..0000000000 --- a/server/mpm/simple/simple_event.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "apr.h" -#include "apr_pools.h" -#include "apr_poll.h" - -#ifndef APACHE_MPM_SIMPLE_EVENT_H -#define APACHE_MPM_SIMPLE_EVENT_H - -/* pqXXXXXX: Pool based cleanups - */ - -void -simple_register_timer(simple_core_t * sc, - simple_timer_cb cb, - void *baton, - apr_time_t relative_time, - apr_pool_t *shutdown_pool); - -void -simple_timer_run(simple_timer_t *ep); - -#if THESE_ARE_JUST_IDEAS_PATCHES_WELCOME -/** - * @see apr_poll.h for watch_for values - */ -void -simple_register_sock_io(simple_core_t * sc, - simple_io_sock_cb cb, - void *baton, - apr_socket_t * sock, - int watch_for, apr_time_t relative_timeout); - -/** - * @see apr_poll.h for watch_for values - */ -void -simple_register_file_io(simple_core_t * sc, - simple_io_file_cb cb, - void *baton, - apr_file_t * file, - int watch_for, apr_time_t relative_timeout); - -#endif - -#endif /* APACHE_MPM_SIMPLE_EVENT_H */ diff --git a/server/mpm/simple/simple_io.c b/server/mpm/simple/simple_io.c deleted file mode 100644 index 50e2d6ad27..0000000000 --- a/server/mpm/simple/simple_io.c +++ /dev/null @@ -1,301 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "httpd.h" -#include "http_log.h" -#include "ap_listen.h" -#include "simple_types.h" -#include "simple_io.h" -#include "simple_event.h" - -#include "http_connection.h" -#include "util_filter.h" -#include "http_main.h" -#include "scoreboard.h" -#include "http_vhost.h" - -APLOG_USE_MODULE(mpm_simple); - -static void simple_io_timeout_cb(simple_core_t * sc, void *baton) -{ -/* Code disabled because it does nothing yet but causes a compiler warning */ -#if 0 - simple_conn_t *scon = (simple_conn_t *) baton; - /* pqXXXXX: handle timeouts. */ - conn_rec *c = scon->c; - conn_state_t *cs = c->cs; - - cs = NULL; -#endif - - ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf, - "io timeout hit (?)"); -} - -static apr_status_t simple_io_process(simple_conn_t * scon) -{ - apr_status_t rv; - simple_core_t *sc; - conn_rec *c; - conn_state_t *cs; - - if (scon->c->clogging_input_filters && !scon->c->aborted) { - /* Since we have an input filter which 'cloggs' the input stream, - * like mod_ssl, lets just do the normal read from input filters, - * like the Worker MPM does. - */ - ap_run_process_connection(scon->c); - if (scon->c->cs->state != CONN_STATE_SUSPENDED) { - scon->c->cs->state = CONN_STATE_LINGER; - } - } - - sc = scon->sc; - c = scon->c; - cs = c->cs; - - while (!c->aborted) { - - if (cs->pfd.reqevents != 0) { - rv = apr_pollcb_remove(sc->pollcb, &cs->pfd); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, - "simple_io_process: apr_pollcb_remove failure"); - /*AP_DEBUG_ASSERT(rv == APR_SUCCESS);*/ - } - cs->pfd.reqevents = 0; - } - - if (cs->state == CONN_STATE_READ_REQUEST_LINE) { - if (!c->aborted) { - ap_run_process_connection(c); - /* state will be updated upon return - * fall thru to either wait for readability/timeout or - * do lingering close - */ - } - else { - cs->state = CONN_STATE_LINGER; - } - } - - if (cs->state == CONN_STATE_WRITE_COMPLETION) { - ap_filter_t *output_filter = c->output_filters; - while (output_filter->next != NULL) { - output_filter = output_filter->next; - } - - rv = output_filter->frec->filter_func.out_func(output_filter, - NULL); - - if (rv != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf, - "network write failure in core output filter"); - cs->state = CONN_STATE_LINGER; - } - else if (c->data_in_output_filters) { - /* Still in WRITE_COMPLETION_STATE: - * Set a write timeout for this connection, and let the - * event thread poll for writeability. - */ - - simple_register_timer(scon->sc, - simple_io_timeout_cb, - scon, - scon->c->base_server != - NULL ? scon->c->base_server-> - timeout : ap_server_conf->timeout, - scon->pool); - - cs->pfd.reqevents = APR_POLLOUT | APR_POLLHUP | APR_POLLERR; - - rv = apr_pollcb_add(sc->pollcb, &cs->pfd); - - if (rv != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_WARNING, rv, - ap_server_conf, - "apr_pollcb_add: failed in write completion"); - AP_DEBUG_ASSERT(rv == APR_SUCCESS); - } - return APR_SUCCESS; - } - else if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted) { - c->cs->state = CONN_STATE_LINGER; - } - else if (c->data_in_input_filters) { - cs->state = CONN_STATE_READ_REQUEST_LINE; - } - else { - cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE; - } - } - - if (cs->state == CONN_STATE_LINGER) { - ap_lingering_close(c); - apr_pool_destroy(scon->pool); - return APR_SUCCESS; - } - - if (cs->state == CONN_STATE_CHECK_REQUEST_LINE_READABLE) { - simple_register_timer(scon->sc, - simple_io_timeout_cb, - scon, - scon->c->base_server != - NULL ? scon->c->base_server-> - timeout : ap_server_conf->timeout, - scon->pool); - - cs->pfd.reqevents = APR_POLLIN; - - rv = apr_pollcb_add(sc->pollcb, &cs->pfd); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, - "process_socket: apr_pollcb_add failure in read request line"); - AP_DEBUG_ASSERT(rv == APR_SUCCESS); - } - - return APR_SUCCESS; - } - } - - ap_lingering_close(c); - apr_pool_destroy(scon->pool); - return APR_SUCCESS; -} - -static void *simple_io_invoke(apr_thread_t * thread, void *baton) -{ - simple_sb_t *sb = (simple_sb_t *) baton; - simple_conn_t *scon = (simple_conn_t *) sb->baton; - apr_status_t rv; - - scon->c->current_thread = thread; - - rv = simple_io_process(scon); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf, - "simple_io_invoke: simple_io_process failed (?)"); - } - - return NULL; -} - -static void *simple_io_setup_conn(apr_thread_t * thread, void *baton) -{ - apr_status_t rv; - ap_sb_handle_t *sbh; - conn_state_t *cs; - long conn_id = 0; - simple_sb_t *sb; - simple_conn_t *scon = (simple_conn_t *) baton; - - /* pqXXXXX: remove this. */ - ap_create_sb_handle(&sbh, scon->pool, 0, 0); - - scon->ba = apr_bucket_alloc_create(scon->pool); - - scon->c = ap_run_create_connection(scon->pool, ap_server_conf, scon->sock, - conn_id, sbh, scon->ba); - /* XXX: handle failure */ - - scon->c->cs = apr_pcalloc(scon->pool, sizeof(conn_state_t)); - cs = scon->c->cs; - sb = apr_pcalloc(scon->pool, sizeof(simple_sb_t)); - - scon->c->current_thread = thread; - - cs->pfd.p = scon->pool; - cs->pfd.desc_type = APR_POLL_SOCKET; - cs->pfd.desc.s = scon->sock; - cs->pfd.reqevents = APR_POLLIN; - - sb->type = SIMPLE_PT_CORE_IO; - sb->baton = scon; - cs->pfd.client_data = sb; - - ap_update_vhost_given_ip(scon->c); - - rv = ap_run_pre_connection(scon->c, scon->sock); - if (rv != OK && rv != DONE) { - ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, - "simple_io_setup_conn: connection aborted"); - scon->c->aborted = 1; - } - - scon->c->cs->state = CONN_STATE_READ_REQUEST_LINE; - - rv = simple_io_process(scon); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, ap_server_conf, - "simple_io_setup_conn: simple_io_process failed (?)"); - } - - return NULL; -} - -apr_status_t simple_io_accept(simple_core_t * sc, simple_sb_t * sb) -{ - apr_status_t rv; - apr_pool_t *ptrans; - apr_socket_t *socket; - ap_listen_rec *lr = (ap_listen_rec *) sb->baton; - - /* pqXXXXXX: Consider doing pool recycling like the event/worker MPMs do. */ - apr_pool_create(&ptrans, NULL); - - apr_pool_tag(ptrans, "transaction"); - - rv = apr_socket_accept(&socket, lr->sd, ptrans); - if (rv) { - /* pqXXXXXX: unixd.c has _tons_ of custom handling on return values - * from accept, but it seems really crazy, it either worked, or didn't, - * but taking this approach of swallowing the error it is possible we have a - * fatal error on our listening socket, but we don't notice. - * - * Need to discuss this on dev@ - */ - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_io_accept: apr_socket_accept failed"); - return APR_SUCCESS; - } - else { - simple_conn_t *scon = apr_pcalloc(ptrans, sizeof(simple_conn_t)); - scon->pool = ptrans; - scon->sock = socket; - scon->sc = sc; - - return apr_thread_pool_push(sc->workers, - simple_io_setup_conn, - scon, - APR_THREAD_TASK_PRIORITY_NORMAL, NULL); - } - - return APR_SUCCESS; -} - -apr_status_t simple_io_event_process(simple_core_t * sc, simple_sb_t * sb) -{ - /* pqXXXXX: In theory, if we have non-blocking operations on the connection - * we can do them here, before pushing to another thread, thats just - * not implemented right now. - */ - return apr_thread_pool_push(sc->workers, - simple_io_invoke, - sb, APR_THREAD_TASK_PRIORITY_NORMAL, NULL); -} diff --git a/server/mpm/simple/simple_io.h b/server/mpm/simple/simple_io.h deleted file mode 100644 index a1c8dbdfbb..0000000000 --- a/server/mpm/simple/simple_io.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "simple_types.h" - -#ifndef APACHE_MPM_SIMPLE_IO_H -#define APACHE_MPM_SIMPLE_IO_H - -apr_status_t simple_io_accept(simple_core_t * sc, simple_sb_t * sb); - -apr_status_t simple_io_event_process(simple_core_t * sc, simple_sb_t * sb); - -#endif diff --git a/server/mpm/simple/simple_run.c b/server/mpm/simple/simple_run.c deleted file mode 100644 index 86ba246776..0000000000 --- a/server/mpm/simple/simple_run.c +++ /dev/null @@ -1,342 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* #define APR_RING_DEBUG 1 */ - -#include "httpd.h" -#include "http_log.h" -#include "http_main.h" -#include "simple_types.h" -#include "simple_event.h" -#include "simple_children.h" -#include "simple_run.h" -#include "simple_io.h" -#include "ap_mpm.h" -#include "scoreboard.h" - -#include "ap_listen.h" -#include "mpm_common.h" -#include "apr_version.h" - -#if !APR_VERSION_AT_LEAST(1,4,0) -#define apr_time_from_msec(msec) ((apr_time_t)(msec) * 1000) -#endif - -APLOG_USE_MODULE(mpm_simple); - -/** - * Create Timers. - */ -static apr_status_t simple_main_setup_timers(simple_core_t * sc) -{ - simple_register_timer(sc, simple_check_children_size, NULL, 0, sc->pool); - - return APR_SUCCESS; -} - -/** - * Create worker thread pool. - */ -static apr_status_t simple_setup_workers(simple_core_t * sc) -{ - apr_status_t rv; - - rv = apr_thread_pool_create(&sc->workers, - sc->procmgr.thread_count, - sc->procmgr.thread_count, sc->pool); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_setup_workers: apr_thread_pool_create with %d threads failed", - sc->procmgr.thread_count); - return rv; - } - - return APR_SUCCESS; -} - -static apr_status_t simple_setup_listeners(simple_core_t * sc) -{ - ap_listen_rec *lr; - apr_status_t rv; - - for (lr = ap_listeners; lr != NULL; lr = lr->next) { - apr_pollfd_t *pfd = apr_palloc(sc->pool, sizeof(apr_pollfd_t)); - simple_sb_t *sb = apr_pcalloc(sc->pool, sizeof(simple_sb_t)); - - pfd->p = sc->pool; - pfd->desc_type = APR_POLL_SOCKET; - pfd->desc.s = lr->sd; - pfd->reqevents = APR_POLLIN; - - sb->type = SIMPLE_PT_CORE_ACCEPT; - sb->baton = lr; - - pfd->client_data = sb; - - rv = apr_socket_opt_set(pfd->desc.s, APR_SO_NONBLOCK, 1); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_setup_workers: apr_socket_opt_set(APR_SO_NONBLOCK = 1) failed on %pI", - lr->bind_addr); - return rv; - } - - rv = apr_pollcb_add(sc->pollcb, pfd); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_setup_workers: apr_pollcb_add failed on %pI", - lr->bind_addr); - return rv; - } - } - - return APR_SUCCESS; -} - - - -static apr_status_t simple_io_callback(void *baton, apr_pollfd_t * pfd) -{ - apr_status_t rv = APR_SUCCESS; - simple_core_t *sc = (simple_core_t *) baton; - simple_sb_t *sb = pfd->client_data; - - - if (sb->type == SIMPLE_PT_CORE_ACCEPT) { - rv = simple_io_accept(sc, sb); - } - else if (sb->type == SIMPLE_PT_CORE_IO) { - rv = simple_io_event_process(sc, sb); - } - else if (sb->type == SIMPLE_PT_USER) { - /* TODO: */ - abort(); - } - else { - abort(); - } - - return rv; -} - -static void *simple_timer_invoke(apr_thread_t * thread, void *baton) -{ - simple_timer_t *ep = (simple_timer_t *) baton; - - simple_timer_run(ep); - - return NULL; -} - -static int simple_run_loop(simple_core_t * sc) -{ - apr_status_t rv; - simple_timer_t *ep = NULL; - - while (sc->mpm_state == AP_MPMQ_RUNNING) { - apr_time_t tnow = apr_time_now(); - simple_timer_t *head; - apr_interval_time_t timeout = apr_time_from_msec(500); - APR_RING_HEAD(simple_temp_timer_ring_t, simple_timer_t) tmp_ring; - - apr_thread_mutex_lock(sc->mtx); - head = APR_RING_FIRST(&sc->timer_ring); - - if (head != APR_RING_SENTINEL(&sc->timer_ring, simple_timer_t, link)) { - if (tnow < head->expires) { - timeout = (head->expires - tnow); - if (timeout > apr_time_from_msec(500)) { - /* pqXXXXX: I'm 95% sure that the Linux Powertop guys will slap me for this. */ - timeout = apr_time_from_msec(500); - } - } - else { - /* We have already expired timers in the queue. */ - timeout = 0; - } - } - apr_thread_mutex_unlock(sc->mtx); - - rv = apr_pollcb_poll(sc->pollcb, timeout, simple_io_callback, sc); - - tnow = apr_time_now(); - - if (rv) { - if (!APR_STATUS_IS_EINTR(rv) && !APR_STATUS_IS_TIMEUP(rv)) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_main_loop: apr_pollcb_poll failed"); - return DONE; - } - } - - APR_RING_INIT(&tmp_ring, simple_timer_t, link); - - apr_thread_mutex_lock(sc->mtx); - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - /* now iterate any timers */ - if (!APR_RING_EMPTY(&sc->timer_ring, simple_timer_t, link)) { - for (ep = APR_RING_FIRST(&sc->timer_ring); - ep != APR_RING_SENTINEL(&sc->timer_ring, - simple_timer_t, link); - ep = APR_RING_NEXT(ep, link)) { - if (ep->expires < tnow) { - simple_timer_t *next = APR_RING_PREV(ep, link); - /* push this task */ - APR_RING_REMOVE(ep, link); - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, - simple_timer_t, link); - APR_RING_INSERT_TAIL(&tmp_ring, ep, simple_timer_t, link); - ep = next; - } - else { - break; - } - } - } - - APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link); - - apr_thread_mutex_unlock(sc->mtx); - - if (!APR_RING_EMPTY(&tmp_ring, simple_timer_t, link)) { - for (ep = APR_RING_FIRST(&tmp_ring); - ep != APR_RING_SENTINEL(&tmp_ring, - simple_timer_t, link); - ep = APR_RING_NEXT(ep, link)) { - apr_thread_pool_push(sc->workers, - simple_timer_invoke, - ep, - APR_THREAD_TASK_PRIORITY_NORMAL, NULL); - } - } - } - - return OK; -} - -void simple_single_process_hack(simple_core_t * sc) -{ - apr_status_t rv; - /* Normally this is only ran in the child processes, but we want to do it here too... */ - rv = simple_setup_listeners(sc); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_single_child_hack: simple_setup_listeners failed"); - } -} - -static int simple_setup_privs(simple_core_t * sc) -{ - int rv = ap_run_drop_privileges(sc->pool, ap_server_conf); - - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_setup_privs: ap_run_drop_privileges failed"); - return rv; - } - - return 0; -} - -static int simple_setup_pollcb(simple_core_t * sc) -{ - int i; - apr_status_t rv; - int good_methods[] = {APR_POLLSET_KQUEUE, APR_POLLSET_PORT, APR_POLLSET_EPOLL}; - - for (i = 0; i < sizeof(good_methods) / sizeof(void*); i++) { - /* pqXXXXX: make size of pollcb configrable or dynamic */ - rv = apr_pollcb_create_ex(&sc->pollcb, 512, - sc->pool, APR_POLLSET_NODEFAULT, good_methods[i]); - if (!rv) { - break; - } - } - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_setup_pollcb: apr_pollcb_create failed for all possible backends!"); - return rv; - } - return rv; -} - -int simple_child_loop(simple_core_t * sc) -{ - apr_status_t rv; - - rv = simple_setup_pollcb(sc); - if (rv) { - return rv; - } - - /* XXXXX: Hack. Reseting parts of the simple core needs to be more - * thought out than this. - */ - APR_RING_INIT(&sc->timer_ring, simple_timer_t, link); - - rv = simple_setup_workers(sc); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_child_loop: simple_setup_workers failed"); - return !OK; - } - - rv = simple_setup_listeners(sc); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_child_loop: simple_setup_sockets failed"); - return !OK; - } - - rv = simple_setup_privs(sc); - if (rv) { - /* simple_setup_privs already logged error */ - return !OK; - } - - ap_run_child_init(sc->pool, ap_server_conf); - - return simple_run_loop(sc); -} - -int simple_main_loop(simple_core_t * sc) -{ - apr_status_t rv; - - rv = simple_setup_pollcb(sc); - if (rv) { - return rv; - } - - rv = simple_setup_workers(sc); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_main_loop: simple_setup_workers failed"); - return !OK; - } - - rv = simple_main_setup_timers(sc); - if (rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, - "simple_main_loop: simple_setup_timers failed"); - return !OK; - } - - return simple_run_loop(sc); -} diff --git a/server/mpm/simple/simple_run.h b/server/mpm/simple/simple_run.h deleted file mode 100644 index fa917e7a88..0000000000 --- a/server/mpm/simple/simple_run.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "simple_types.h" - -#ifndef APACHE_MPM_SIMPLE_RUN_H -#define APACHE_MPM_SIMPLE_RUN_H - -void simple_single_process_hack(simple_core_t * sc); - -int simple_child_loop(simple_core_t * sc); - -int simple_main_loop(simple_core_t * sc); - - -#endif diff --git a/server/mpm/simple/simple_types.h b/server/mpm/simple/simple_types.h deleted file mode 100644 index a71691f5f7..0000000000 --- a/server/mpm/simple/simple_types.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "apr.h" -#include "apr_pools.h" -#include "apr_poll.h" -#include "apr_hash.h" -#include "apr_ring.h" -#include "apr_thread_pool.h" -#include "apr_buckets.h" -#include "httpd.h" - -#ifndef APACHE_MPM_SIMPLE_TYPES_H -#define APACHE_MPM_SIMPLE_TYPES_H - -typedef struct simple_core_t simple_core_t; - -typedef struct -{ - int proc_count; - int thread_count; - int max_requests_per_child; -} simple_proc_mgr_t; - -#define SIMPLE_MAX_PROC (500000) -#define SIMPLE_DEF_PROC (5) -#define SIMPLE_MIN_PROC (1) -#define SIMPLE_MAX_THREADS (500000) -#define SIMPLE_DEF_THREADS (5) -#define SIMPLE_MIN_THREADS (1) - -typedef void (*simple_timer_cb) (simple_core_t * sc, void *baton); -typedef void (*simple_io_sock_cb) (simple_core_t * sc, apr_socket_t * sock, - int flags, void *baton); -typedef void (*simple_io_file_cb) (simple_core_t * sc, apr_socket_t * sock, - int flags, void *baton); - -typedef struct simple_sb_t simple_sb_t; - -typedef enum -{ - SIMPLE_PT_CORE_ACCEPT, - SIMPLE_PT_CORE_IO, - /* pqXXXXXX: User IO not defined yet. */ - SIMPLE_PT_USER -} simple_poll_type_e; - -typedef enum -{ - SIMPLE_SPAWN_FORK, - SIMPLE_SPAWN_EXEC, -} simple_spawn_type_e; - -struct simple_sb_t -{ - simple_poll_type_e type; - void *baton; -}; - -typedef struct simple_timer_t simple_timer_t; -struct simple_timer_t -{ - APR_RING_ENTRY(simple_timer_t) link; - apr_time_t expires; - simple_timer_cb cb; - void *baton; - apr_pool_t *pool; - simple_core_t *sc; -}; - -typedef struct simple_child_t simple_child_t; -struct simple_child_t -{ - /* TODO: More is needed here. */ - pid_t pid; -}; - -struct simple_core_t -{ - apr_pool_t *pool; - apr_thread_mutex_t *mtx; - - int mpm_state; - int restart_num; - - int run_single_process; - int run_foreground; - simple_spawn_type_e spawn_via; - - simple_proc_mgr_t procmgr; - - /* PID -> simple_child_t map */ - apr_hash_t *children; - - apr_pollcb_t *pollcb; - - /* List of upcoming timers, sorted by nearest first. - */ - APR_RING_HEAD(simple_timer_ring_t, simple_timer_t) timer_ring; - - apr_thread_pool_t *workers; -}; - -typedef struct simple_conn_t simple_conn_t; -struct simple_conn_t -{ - apr_pool_t *pool; - simple_core_t *sc; - apr_socket_t *sock; - apr_bucket_alloc_t *ba; - conn_rec *c; -}; - -simple_core_t *simple_core_get(void); - -/* Allocates/initializes data retained over the life of the process */ -apr_status_t simple_core_init_once(void); - -#endif /* APACHE_MPM_SIMPLE_TYPES_H */