]> granicus.if.org Git - apache/commitdiff
Well this was thought provoking.
authorBen Hyde <bhyde@apache.org>
Thu, 7 Oct 1999 20:48:26 +0000 (20:48 +0000)
committerBen Hyde <bhyde@apache.org>
Thu, 7 Oct 1999 20:48:26 +0000 (20:48 +0000)
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
include/http_config.h
server/config.c
server/listen.c
server/main.c
server/mpm/dexter/dexter.c
server/mpm/mpmt_pthread/mpmt_pthread.c
server/mpm/prefork/prefork.c
server/mpm/spmt_os2/spmt_os2.c
server/mpm/winnt/mpm_winnt.c

index 229aaf4a3519275446b1e9e58d257d47375594f4..868c9f57ef3b793f29aa98279f174c661a888866 100644 (file)
@@ -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);
index 89801e1ac9561c0f571ecc3e8878471c22cd7c34..93317635b4926549a966f9f6eaf36036a665f6c2 100644 (file)
@@ -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);
index b6753d855769f15146557df105cf779f09957eeb..fb28322f2a79fcb85175879760949f5ac5bfe269 100644 (file)
@@ -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");
index aa24b0d2b6d674e2a4fa0c99c681a1e3ecdb2bb1..18811a3c41b39a8319ca2cfe5138d791d8211abf 100644 (file)
@@ -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;
index 907bd08aaa108b24760960c49888fc106fc0d933..5def25f3227b8fc4235bd9c30d39bd8745d83120 100644 (file)
@@ -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) {
index 9b6d32d01581bd403dba99555f75f3be1e05b1c2..d2f71151c42f55aacc6f0952e72fc5299c4a3ccd 100644 (file)
@@ -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");
index 1a7edfbe0b1cb1ae67588cc8ed0f32f1ab133374..afa841578f4f7970f2395a7a9934a9c9609a8c26 100644 (file)
@@ -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");
index ef27132e291e224e197eee22c25bd8dae7952d42..001283bd041c12d8c6f1fc0268a203b4a03e8226 100644 (file)
@@ -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;
index a38b03847da28b23d91c577dc4757609efc42ea4..fab6592946618daf5a6353f34e8d31f8aea33993 100644 (file)
@@ -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;
     }
index 1d7a69ffe85558cf00db26c77b1974eea63ea639..5eaa6a4519ab357de32738b1ecbd01b1e1d6b10e 100644 (file)
@@ -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