From: Jim Jagielski Date: Thu, 5 Mar 2015 14:35:37 +0000 (+0000) Subject: Move to traditional C header X-Git-Tag: 2.5.0-alpha~3410 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=227e6962283317cf1fc7bf8650cb7814de1ea61a;p=apache Move to traditional C header git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1664357 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/motorz/motorz.c b/server/mpm/motorz/motorz.c index 87df98ffa0..abe0a87b05 100644 --- a/server/mpm/motorz/motorz.c +++ b/server/mpm/motorz/motorz.c @@ -14,208 +14,9 @@ * limitations under the License. */ -#include "apr.h" -#include "apr_portable.h" -#include "apr_strings.h" -#include "apr_thread_proc.h" -#include "apr_signal.h" - -#define APR_WANT_STDIO -#define APR_WANT_STRFUNC -#include "apr_want.h" - -#if APR_HAVE_UNISTD_H -#include -#endif -#if APR_HAVE_SYS_TYPES_H -#include -#endif - -#include "ap_config.h" -#include "httpd.h" -#include "mpm_default.h" -#include "http_main.h" -#include "http_log.h" -#include "http_config.h" -#include "http_core.h" /* for get_remote_host */ -#include "http_connection.h" -#include "scoreboard.h" -#include "ap_mpm.h" -#include "util_mutex.h" -#include "unixd.h" -#include "http_vhost.h" -#include "mpm_common.h" -#include "ap_listen.h" -#include "ap_mmn.h" -#include "apr_poll.h" -#include "apr_skiplist.h" -#include "apr_thread_pool.h" -#include "util_time.h" - -#include - -#ifdef HAVE_TIME_H -#include -#endif -#ifdef HAVE_SYS_PROCESSOR_H -#include /* for bindprocessor() */ -#endif - -#include -#include - -/* Limit on the total --- clients will be locked out if more servers than - * this are needed. It is intended solely to keep the server from crashing - * when things get out of hand. - * - * We keep a hard maximum number of servers, for two reasons --- first off, - * in case something goes seriously wrong, we want to stop the fork bomb - * short of actually crashing the machine we're running on by filling some - * kernel table. Secondly, it keeps the size of the scoreboard file small - * enough that we can read the whole thing without worrying too much about - * the overhead. - */ -#ifndef DEFAULT_SERVER_LIMIT -#define DEFAULT_SERVER_LIMIT 256 -#endif - -/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want - * some sort of compile-time limit to help catch typos. - */ -#ifndef MAX_SERVER_LIMIT -#define MAX_SERVER_LIMIT 200000 -#endif - -/* Limit on the threads per process. Clients will be locked out if more than - * this are needed. - * - * We keep this for one reason it keeps the size of the scoreboard file small - * enough that we can read the whole thing without worrying too much about - * the overhead. - */ -#ifndef DEFAULT_THREAD_LIMIT -#define DEFAULT_THREAD_LIMIT 64 -#endif - -/* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT. We want - * some sort of compile-time limit to help catch typos. - */ -#ifndef MAX_THREAD_LIMIT -#define MAX_THREAD_LIMIT 100000 -#endif - -/* config globals */ - -static int threads_per_child = 0; -static int ap_num_kids=0; -static int ap_daemons_min_free=0; -static int ap_daemons_max_free=0; -static int ap_daemons_limit=0; /* MaxRequestWorkers */ -static int server_limit = 0; -static int mpm_state = AP_MPMQ_STARTING; - -/* data retained by prefork across load/unload of the module - * allocated on first call to pre-config hook; located on - * subsequent calls to pre-config hook - */ -typedef struct motorz_core_t { - int first_server_limit; - int module_loads; - ap_generation_t my_generation; - int volatile is_graceful; /* set from signal handler */ - int maxclients_reported; - /* - * The max child slot ever assigned, preserved across restarts. Necessary - * to deal with MaxRequestWorkers changes across AP_SIG_GRACEFUL restarts. We - * use this value to optimize routines that have to scan the entire scoreboard. - */ - int max_daemons_limit; - apr_pool_t *pool; - apr_thread_mutex_t *mtx; - apr_pollcb_t *pollcb; - apr_skiplist *timer_ring; - apr_thread_pool_t *workers; -} motorz_core_t; -static motorz_core_t *g_motorz_core; - -typedef struct motorz_child_bucket { - ap_pod_t *pod; - ap_listen_rec *listeners; - apr_proc_mutex_t *mutex; -} motorz_child_bucket; -static int num_buckets; /* Number of listeners buckets */ -static motorz_child_bucket *all_buckets, /* All listeners buckets */ - *my_bucket; /* Current child bucket */ - -typedef enum -{ - PT_CSD, - PT_ACCEPT, - PT_USER -} motorz_poll_type_e; - -typedef struct motorz_sb_t motorz_sb_t; -struct motorz_sb_t -{ - motorz_poll_type_e type; - void *baton; -}; - -typedef void (*motorz_timer_cb) (motorz_core_t *mz, void *baton); -typedef void (*motorz_io_sock_cb) (motorz_core_t *mz, apr_socket_t *sock, - int flags, void *baton); -typedef void (*motorz_io_file_cb) (motorz_core_t *mz, apr_socket_t *sock, - int flags, void *baton); - - -typedef struct motorz_timer_t motorz_timer_t; -struct motorz_timer_t -{ - apr_time_t expires; - motorz_timer_cb cb; - void *baton; - apr_pool_t *pool; - motorz_core_t *mz; -}; - -typedef struct motorz_conn_t motorz_conn_t; -struct motorz_conn_t -{ - apr_pool_t *pool; - motorz_core_t *mz; - apr_socket_t *sock; - apr_bucket_alloc_t *ba; - conn_rec *c; - /** poll file descriptor information */ - apr_pollfd_t pfd; - /** public parts of the connection state */ - conn_state_t cs; -}; +#include "motorz.h" static apr_status_t motorz_io_process(motorz_conn_t *scon); - -#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) - -/* one_process --- debugging mode variable; can be set from the command line - * with the -X flag. If set, this gets you the child_main loop running - * in the process which originally started up (no detach, no make_child), - * which is a pretty nice debugging environment. (You'll get a SIGHUP - * early in standalone_main; just continue through. This is the server - * trying to kill off any child processes which it might have lying - * around --- Apache doesn't keep track of their pids, it just sends - * SIGHUP to the process group, ignoring it in the root process. - * Continue through and you'll be fine.). - */ - -static int one_process = 0; - -static apr_pool_t *pconf; /* Pool for config stuff */ -static apr_pool_t *pchild; /* Pool for httpd child stuff */ - -static pid_t ap_my_pid; /* it seems silly to call getpid all the time */ -static pid_t parent_pid; -static int my_child_num; - static void clean_child_exit(int code) __attribute__ ((noreturn)); static motorz_core_t *motorz_core_get() diff --git a/server/mpm/motorz/motorz.h b/server/mpm/motorz/motorz.h new file mode 100644 index 0000000000..7612427e71 --- /dev/null +++ b/server/mpm/motorz/motorz.h @@ -0,0 +1,225 @@ +/* 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_portable.h" +#include "apr_strings.h" +#include "apr_thread_proc.h" +#include "apr_signal.h" + +#define APR_WANT_STDIO +#define APR_WANT_STRFUNC +#include "apr_want.h" + +#if APR_HAVE_UNISTD_H +#include +#endif +#if APR_HAVE_SYS_TYPES_H +#include +#endif + +#include "ap_config.h" +#include "httpd.h" +#include "mpm_default.h" +#include "http_main.h" +#include "http_log.h" +#include "http_config.h" +#include "http_core.h" /* for get_remote_host */ +#include "http_connection.h" +#include "scoreboard.h" +#include "ap_mpm.h" +#include "util_mutex.h" +#include "unixd.h" +#include "http_vhost.h" +#include "mpm_common.h" +#include "ap_listen.h" +#include "ap_mmn.h" +#include "apr_poll.h" +#include "apr_skiplist.h" +#include "apr_thread_pool.h" +#include "util_time.h" + +#include + +#ifdef HAVE_TIME_H +#include +#endif +#ifdef HAVE_SYS_PROCESSOR_H +#include /* for bindprocessor() */ +#endif + +#include +#include + +/* Limit on the total --- clients will be locked out if more servers than + * this are needed. It is intended solely to keep the server from crashing + * when things get out of hand. + * + * We keep a hard maximum number of servers, for two reasons --- first off, + * in case something goes seriously wrong, we want to stop the fork bomb + * short of actually crashing the machine we're running on by filling some + * kernel table. Secondly, it keeps the size of the scoreboard file small + * enough that we can read the whole thing without worrying too much about + * the overhead. + */ +#ifndef DEFAULT_SERVER_LIMIT +#define DEFAULT_SERVER_LIMIT 256 +#endif + +/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want + * some sort of compile-time limit to help catch typos. + */ +#ifndef MAX_SERVER_LIMIT +#define MAX_SERVER_LIMIT 200000 +#endif + +/* Limit on the threads per process. Clients will be locked out if more than + * this are needed. + * + * We keep this for one reason it keeps the size of the scoreboard file small + * enough that we can read the whole thing without worrying too much about + * the overhead. + */ +#ifndef DEFAULT_THREAD_LIMIT +#define DEFAULT_THREAD_LIMIT 64 +#endif + +/* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT. We want + * some sort of compile-time limit to help catch typos. + */ +#ifndef MAX_THREAD_LIMIT +#define MAX_THREAD_LIMIT 100000 +#endif + +#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) + +/** + * typedefs + */ +/* data retained by prefork across load/unload of the module + * allocated on first call to pre-config hook; located on + * subsequent calls to pre-config hook + */ +typedef struct motorz_core_t motorz_core_t; +struct motorz_core_t { + int first_server_limit; + int module_loads; + ap_generation_t my_generation; + int volatile is_graceful; /* set from signal handler */ + int maxclients_reported; + /* + * The max child slot ever assigned, preserved across restarts. Necessary + * to deal with MaxRequestWorkers changes across AP_SIG_GRACEFUL restarts. We + * use this value to optimize routines that have to scan the entire scoreboard. + */ + int max_daemons_limit; + apr_pool_t *pool; + apr_thread_mutex_t *mtx; + apr_pollcb_t *pollcb; + apr_skiplist *timer_ring; + apr_thread_pool_t *workers; +}; +static motorz_core_t *g_motorz_core; + +typedef struct motorz_child_bucket motorz_child_bucket; +struct motorz_child_bucket { + ap_pod_t *pod; + ap_listen_rec *listeners; + apr_proc_mutex_t *mutex; +}; + +typedef enum +{ + PT_CSD, + PT_ACCEPT, + PT_USER +} motorz_poll_type_e; + +typedef struct motorz_sb_t motorz_sb_t; +struct motorz_sb_t +{ + motorz_poll_type_e type; + void *baton; +}; + +typedef void (*motorz_timer_cb) (motorz_core_t *mz, void *baton); +typedef void (*motorz_io_sock_cb) (motorz_core_t *mz, apr_socket_t *sock, + int flags, void *baton); +typedef void (*motorz_io_file_cb) (motorz_core_t *mz, apr_socket_t *sock, + int flags, void *baton); + + +typedef struct motorz_timer_t motorz_timer_t; +struct motorz_timer_t +{ + apr_time_t expires; + motorz_timer_cb cb; + void *baton; + apr_pool_t *pool; + motorz_core_t *mz; +}; + +typedef struct motorz_conn_t motorz_conn_t; +struct motorz_conn_t +{ + apr_pool_t *pool; + motorz_core_t *mz; + apr_socket_t *sock; + apr_bucket_alloc_t *ba; + conn_rec *c; + /** poll file descriptor information */ + apr_pollfd_t pfd; + /** public parts of the connection state */ + conn_state_t cs; +}; + + +/** + * config globals + */ + +static int threads_per_child = 0; +static int ap_num_kids=0; +static int ap_daemons_min_free=0; +static int ap_daemons_max_free=0; +static int ap_daemons_limit=0; /* MaxRequestWorkers */ +static int server_limit = 0; +static int mpm_state = AP_MPMQ_STARTING; + +/* one_process --- debugging mode variable; can be set from the command line + * with the -X flag. If set, this gets you the child_main loop running + * in the process which originally started up (no detach, no make_child), + * which is a pretty nice debugging environment. (You'll get a SIGHUP + * early in standalone_main; just continue through. This is the server + * trying to kill off any child processes which it might have lying + * around --- Apache doesn't keep track of their pids, it just sends + * SIGHUP to the process group, ignoring it in the root process. + * Continue through and you'll be fine.). + */ +static int one_process = 0; + +static apr_pool_t *pconf; /* Pool for config stuff */ +static apr_pool_t *pchild; /* Pool for httpd child stuff */ + +static pid_t ap_my_pid; /* it seems silly to call getpid all the time */ +static pid_t parent_pid; +static int my_child_num; +static int num_buckets; /* Number of listeners buckets */ +static motorz_child_bucket *all_buckets, /* All listeners buckets */ + *my_bucket; /* Current child bucket */ + +static void clean_child_exit(int code) __attribute__ ((noreturn)); +