From cd06de1ce37c053f288ba65e5c101e7be3c1e18c Mon Sep 17 00:00:00 2001 From: Ben Hyde Date: Thu, 7 Oct 1999 20:48:26 +0000 Subject: [PATCH] Well this was thought provoking. Drive out the use of malloc in two places. In listen.c, using the global process pool instead. That changes the API into listen so that a process is passed in rather than the config pool. That's all was easy. The pain is propogating a change into all N of the mpm, they are all similar but different in their use of listen.c There is a lot to dislike about similar but code scattered code. I changed the N setup_listener routines, they now take only the server since they can dig the config and global pool out of there. Free today: ap_setup_prelinked_modules now takes the process so it can allocate it's table in the process's pool rathern than use malloc. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83943 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_listen.h | 2 +- include/http_config.h | 2 +- server/config.c | 4 ++-- server/listen.c | 13 +++++++------ server/main.c | 4 ++-- server/mpm/dexter/dexter.c | 4 ++-- server/mpm/mpmt_pthread/mpmt_pthread.c | 6 +++--- server/mpm/prefork/prefork.c | 2 +- server/mpm/spmt_os2/spmt_os2.c | 6 +++--- server/mpm/winnt/mpm_winnt.c | 8 ++++---- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/ap_listen.h b/include/ap_listen.h index 229aaf4a351..868c9f57ef3 100644 --- a/include/ap_listen.h +++ b/include/ap_listen.h @@ -71,7 +71,7 @@ struct ap_listen_rec { ap_listen_rec *ap_listeners; void ap_listen_pre_config(void); -int ap_listen_open(ap_context_t *pconf, unsigned port); +int ap_listen_open(process_rec *process, unsigned port); const char *ap_set_listenbacklog(cmd_parms *cmd, void *dummy, char *arg); const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips); const char *ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg); diff --git a/include/http_config.h b/include/http_config.h index 89801e1ac95..93317635b49 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -323,7 +323,7 @@ void ap_single_module_configure(ap_context_t *p, server_rec *s, module *m); /* For http_main.c... */ -void ap_setup_prelinked_modules(void); +void ap_setup_prelinked_modules(process_rec *process); void ap_show_directives(void); void ap_show_modules(void); server_rec *ap_read_config(process_rec *process, ap_context_t *temp_pool, const char *config_name); diff --git a/server/config.c b/server/config.c index b6753d85576..fb28322f2a7 100644 --- a/server/config.c +++ b/server/config.c @@ -526,7 +526,7 @@ API_EXPORT(void) ap_remove_loaded_module(module *mod) *m = NULL; } -void ap_setup_prelinked_modules() +void ap_setup_prelinked_modules(process_rec *process) { module **m; module **m2; @@ -541,7 +541,7 @@ void ap_setup_prelinked_modules() /* * Initialise list of loaded modules */ - ap_loaded_modules = (module **)malloc( + ap_loaded_modules = (module **)ap_palloc(process->pool, sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1)); if (ap_loaded_modules == NULL) { fprintf(stderr, "Ouch! Out of memory in ap_setup_prelinked_modules()!\n"); diff --git a/server/listen.c b/server/listen.c index aa24b0d2b6d..18811a3c41b 100644 --- a/server/listen.c +++ b/server/listen.c @@ -151,7 +151,7 @@ static ap_status_t close_listeners_on_exec(void *v) } -static void alloc_listener(char *addr, unsigned int port) +static void alloc_listener(process_rec *process, char *addr, unsigned int port) { ap_listen_rec **walk; ap_listen_rec *new; @@ -174,7 +174,7 @@ static void alloc_listener(char *addr, unsigned int port) /* this has to survive restarts */ /* XXX - We need to deal with freeing this structure properly. */ - new = malloc(sizeof(ap_listen_rec)); + new = ap_palloc(process->pool, sizeof(ap_listen_rec)); new->active = 0; if (ap_create_tcp_socket(&new->sd, NULL) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, @@ -188,15 +188,16 @@ static void alloc_listener(char *addr, unsigned int port) } -int ap_listen_open(ap_context_t *pconf, unsigned port) +int ap_listen_open(process_rec *process, unsigned port) { + ap_context_t *pconf = process->pconf; ap_listen_rec *lr; ap_listen_rec *next; int num_open; /* allocate a default listener if necessary */ if (ap_listeners == NULL) { - alloc_listener(APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT); + alloc_listener(process, APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT); } num_open = 0; @@ -265,11 +266,11 @@ const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips) } if (ports == ips) { /* no address */ - alloc_listener(APR_ANYADDR, port); + alloc_listener(cmd->server->process, APR_ANYADDR, port); } else { ips[(ports - ips) - 1] = '\0'; - alloc_listener(ips, port); + alloc_listener(cmd->server->process, ips, port); } return NULL; diff --git a/server/main.c b/server/main.c index 907bd08aaa1..5def25f3227 100644 --- a/server/main.c +++ b/server/main.c @@ -293,13 +293,13 @@ API_EXPORT_NONSTD(int) main(int argc, char *argv[]) g_pHookPool=pglobal; + ap_setup_prelinked_modules(process); + ap_create_context(&pcommands, pglobal); ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *)); ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *)); ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *)); - ap_setup_prelinked_modules(); - while ((c = getopt(argc, argv, "C:c:d:f:vVlLth")) != -1) { char **new; switch (c) { diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 9b6d32d0158..d2f71151c42 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -686,7 +686,7 @@ static int setup_listeners(ap_context_t *p, server_rec *s) ap_listen_rec *lr; int num_listeners = 0; - if (ap_listen_open(p, s->port)) { + if (ap_listen_open(s->process, s->port)) { return 0; } for (lr = ap_listeners; lr; lr = lr->next) { @@ -1293,7 +1293,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s) exit(1); } server_conf = s; - if ((num_listenfds = setup_listeners(pconf, server_conf)) < 1) { + if ((num_listenfds = setup_listeners(server_conf)) < 1) { /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s, "no listening sockets available, shutting down"); diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 1a7edfbe0b1..afa841578f4 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -674,11 +674,11 @@ static void process_child_status(int pid, ap_wait_t status) } } -static int setup_listeners(ap_context_t *pconf, server_rec *s) +static int setup_listeners(server_rec *s) { ap_listen_rec *lr; int num_listeners = 0; - if (ap_listen_open(pconf, s->port)) { + if (ap_listen_open(s->process, s->port)) { return 0; } for (lr = ap_listeners; lr; lr = lr->next) { @@ -1303,7 +1303,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s) exit(1); } server_conf = s; - if ((num_listenfds = setup_listeners(pconf, server_conf)) < 1) { + if ((num_listenfds = setup_listeners(server_conf)) < 1) { /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s, "no listening sockets available, shutting down"); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index ef27132e291..001283bd041 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -2535,7 +2535,7 @@ static int setup_listeners(ap_context_t *p, server_rec *s) ap_listen_rec *lr; int sockdes; - if (ap_listen_open(p, s->port)) { + if (ap_listen_open(s->process, s->port)) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s, "no listening sockets available, shutting down"); return -1; diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index a38b03847da..fab65929466 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -1378,11 +1378,11 @@ static void process_child_status(int tid, ap_wait_t status) } -static int setup_listeners(ap_context_t *pconf, server_rec *s) +static int setup_listeners(server_rec *s) { ap_listen_rec *lr; - if (ap_listen_open(pconf, s->port)) { + if (ap_listen_open(s->process, s->port)) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s, "no listening sockets available, shutting down"); return -1; @@ -1413,7 +1413,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s) server_conf = s; ap_log_pid(pconf, ap_pid_fname); - if (setup_listeners(pconf, s)) { + if (setup_listeners(s)) { /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */ return 1; } diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 1d7a69ffe85..5eaa6a4519a 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -363,7 +363,7 @@ static ap_inline ap_listen_rec *find_ready_listener(fd_set * main_fds) } return NULL; } -static int setup_listeners(ap_context_t *pconf, server_rec *s) +static int setup_listeners(server_rec *s) { ap_listen_rec *lr; int num_listeners = 0; @@ -372,7 +372,7 @@ static int setup_listeners(ap_context_t *pconf, server_rec *s) /* Setup the listeners */ FD_ZERO(&listenfds); - if (ap_listen_open(pconf, s->port)) { + if (ap_listen_open(s->process, s->port)) { return 0; } for (lr = ap_listeners; lr; lr = lr->next) { @@ -1028,7 +1028,7 @@ static void worker_main() /* start_mutex obtained, continue into the select() loop */ if (one_process) { - setup_listeners(pconf, server_conf); + setup_listeners(server_conf); } else { /* Get listeners from the parent process */ setup_inherited_listeners(pconf, server_conf); @@ -1343,7 +1343,7 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even HANDLE process_handles[MAX_PROCESSES]; HANDLE process_kill_events[MAX_PROCESSES]; - setup_listeners(pconf, s); + setup_listeners(s); /* Create child process * Should only be one in this version of Apache for WIN32 -- 2.47.2