]> granicus.if.org Git - apache/commitdiff
Add process_rec to the top of {server,connection,request}_rec
authorBen Hyde <bhyde@apache.org>
Thu, 7 Oct 1999 18:13:17 +0000 (18:13 +0000)
committerBen Hyde <bhyde@apache.org>
Thu, 7 Oct 1999 18:13:17 +0000 (18:13 +0000)
hierarchy of structs that abstract server activities.  Store some
stuff in process_rec (finally a place to have nearly guiltless
globals) for example the global and configuration pools.  Put some
operations on process_rec in http_main, in particular the
destroy_and_exit operation, and the use it to do all the exit calls.
Change ap_read_config to operation on this "object" rather than on the
configuration pool.  Modify server_rec to point to the process, so you
can get at it most all the time which should finally allow most of the
server's malloc calls to be eliminated.

There are no locks in the process struct as yet, put them in as needed.
Some of the hooks should take this rather than conf. pool.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83942 13f79535-47bb-0310-9956-ffa450edef68

include/http_config.h
include/httpd.h
server/config.c
server/main.c

index ba2c0c37b079cca1d76bef7bebfd09896f0af86e..89801e1ac9561c0f571ecc3e8878471c22cd7c34 100644 (file)
@@ -326,7 +326,7 @@ void ap_single_module_configure(ap_context_t *p, server_rec *s, module *m);
 void ap_setup_prelinked_modules(void);
 void ap_show_directives(void);
 void ap_show_modules(void);
-server_rec *ap_read_config(ap_context_t *conf_pool, ap_context_t *temp_pool, const char *config_name);
+server_rec *ap_read_config(process_rec *process, ap_context_t *temp_pool, const char *config_name);
 void ap_post_config_hook(ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s);
 void ap_child_init_hook(ap_context_t *pchild, server_rec *s);
 
index 9cfe705ac53bc9c86c1584b73faaec7a8651e1ca..35740a2083f8bac3df78f551d22522056311383a 100644 (file)
@@ -616,12 +616,28 @@ struct htaccess_result {
     const struct htaccess_result *next;
 };
 
-typedef struct conn_rec conn_rec;
+/* The following four types define a hierarchy of activities, so that
+ * given a request_rec r you can write r->connection->server->process
+ * to get to the process_rec.  While this reduces substantially the
+ * number of arguments that various hooks require beware that in
+ * threaded versions of the server you must consider multiplexing
+ * issues.  */
+
+typedef struct process_rec process_rec;
 typedef struct server_rec server_rec;
+typedef struct conn_rec conn_rec;
 typedef struct request_rec request_rec;
 
 #include "util_uri.h"
 
+struct process_rec {
+    ap_context_t *pool;  /* Global pool. Please try to cleared on _all_ exits */
+    ap_context_t *pconf; /* aka configuration pool, cleared on restarts */
+    int argc;
+    const char **argv;
+    const char *short_name;
+};
+
 struct request_rec {
 
     ap_context_t *pool;
@@ -838,7 +854,7 @@ struct server_addr_rec {
 };
 
 struct server_rec {
-
+    process_rec *process;
     server_rec *next;
 
     /* description of where the definition came from */
index bb10036579cd1736c77dc41bd68c0cfd0fd51ff1..b6753d855769f15146557df105cf779f09957eeb 100644 (file)
@@ -1154,6 +1154,7 @@ CORE_EXPORT(const char *) ap_init_virtual_host(ap_context_t *p, const char *host
 #endif
 
     /* TODO: this crap belongs in http_core */
+    s->process = main_server->process;
     s->server_admin = NULL;
     s->server_hostname = NULL;
     s->error_fname = NULL;
@@ -1242,11 +1243,12 @@ static void init_config_globals(ap_context_t *p)
     ap_init_vhost_config(p);
 }
 
-static server_rec *init_server_config(ap_context_t *p)
+static server_rec *init_server_config(process_rec *process, ap_context_t *p)
 {
     int errfile = STDERR_FILENO;
     server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
 
+    s->process = process;
     s->port = 0;
     s->server_admin = DEFAULT_ADMIN;
     s->server_hostname = NULL;
@@ -1278,9 +1280,10 @@ static server_rec *init_server_config(ap_context_t *p)
 }
 
 
-server_rec *ap_read_config(ap_context_t *p, ap_context_t *ptemp, const char *confname)
+server_rec *ap_read_config(process_rec *process, ap_context_t *ptemp, const char *confname)
 {
-    server_rec *s = init_server_config(p);
+    ap_context_t *p = process->pconf;
+    server_rec *s = init_server_config(process, p);
 
     init_config_globals(p);
 
index b5553540d6f455840b274fe04ce491b2c70080aa..907bd08aaa108b24760960c49888fc106fc0d933 100644 (file)
@@ -195,8 +195,39 @@ static void show_compile_settings(void)
 #endif
 }
 
-static void usage(char *bin)
+static void destroy_and_exit_process(process_rec *process, int process_exit_value)
 {
+    ap_destroy_pool(process->pool); /* and destroy all descendent pools */
+    exit(process_exit_value);
+}
+
+#define PATHSEPARATOR '/'  /* Belongs in some apr os include file */
+
+static process_rec *create_process(int argc, const char **argv)
+{
+    process_rec *process;
+    
+    {
+       ap_context_t *cntx;
+
+       ap_create_context(&cntx, NULL);
+       process = ap_palloc(cntx, sizeof(process_rec));
+       process->pool = cntx;
+    }
+    ap_create_context(&process->pconf, process->pool);
+    process->argc = argc;
+    process->argv = argv;
+    {
+        char *s = strrchr(argv[0], PATHSEPARATOR);
+
+       process->short_name = s ? ++s : argv[0];
+    }
+    return process;
+}
+
+static void usage(process_rec *process)
+{
+    const char *bin = process->argv[0];
     char pad[MAX_STRING_LEN];
     unsigned i;
 
@@ -229,9 +260,13 @@ static void usage(char *bin)
     fprintf(stderr, "  -t               : run syntax check for config files (with docroot check)\n");
     fprintf(stderr, "  -T               : run syntax check for config files (without docroot check)\n");
     /* TODOC: -X goes away, expect MPMs to use -D options */
-    exit(1);
+    destroy_and_exit_process(process, 1);
 }
 
+
+
+
+
 ap_context_t *g_pHookPool;
 
 extern char *optarg;
@@ -244,28 +279,18 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
 {
     int c;
     int configtestonly = 0;
-    char *s;
     const char *confname = SERVER_CONFIG_FILE;
     const char *def_server_root = HTTPD_ROOT;
+    process_rec *process = create_process(argc, (const char **)argv);
     server_rec *server_conf;
-    ap_context_t *pglobal;             /* Global pool */
-    ap_context_t *pconf;               /* Pool for config stuff */
+    ap_context_t *pglobal = process->pool;
+    ap_context_t *pconf = process->pconf;
     ap_context_t *plog;                        /* Pool for error-logging files */
-    ap_context_t *ptemp;               /* Pool for temporart config stuff */
+    ap_context_t *ptemp;               /* Pool for temporary config stuff */
     ap_context_t *pcommands;           /* Pool for -C and -c switches */
 
-    /* TODO: PATHSEPARATOR should be one of the os defines */
-#define PATHSEPARATOR '/'
-    if ((s = strrchr(argv[0], PATHSEPARATOR)) != NULL) {
-       ap_server_argv0 = ++s;
-    }
-    else {
-       ap_server_argv0 = argv[0];
-    }
-
     ap_util_uri_init();
 
-    ap_create_context(&pglobal, NULL);
     g_pHookPool=pglobal;
 
     ap_create_context(&pcommands, pglobal);
@@ -295,27 +320,26 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
        case 'v':
            printf("Server version: %s\n", ap_get_server_version());
            printf("Server built:   %s\n", ap_get_server_built());
-           exit(0);
+           destroy_and_exit_process(process, 0);
        case 'V':
            show_compile_settings();
-           exit(0);
+           destroy_and_exit_process(process, 0);
        case 'l':
            ap_show_modules();
-           exit(0);
+           destroy_and_exit_process(process, 0);
        case 'L':
            ap_show_directives();
-           exit(0);
+           destroy_and_exit_process(process, 0);
        case 't':
            configtestonly = 1;
            break;
        case 'h':
-           usage(argv[0]);
+           usage(process);
        case '?':
-           usage(argv[0]);
+           usage(process);
        }
     }
 
-    ap_create_context(&pconf, pglobal);
     ap_create_context(&plog, pglobal);
     ap_create_context(&ptemp, pconf);
 
@@ -324,11 +348,11 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
 
     ap_server_root = def_server_root;
     ap_run_pre_config(pconf, plog, ptemp);
-    server_conf = ap_read_config(pconf, ptemp, confname);
+    server_conf = ap_read_config(process, ptemp, confname);
 
     if (configtestonly) {
        fprintf(stderr, "Syntax OK\n");
-       exit(0);
+       destroy_and_exit_process(process, 0);
     }
 
     ap_clear_pool(plog);
@@ -341,7 +365,7 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
        ap_create_context(&ptemp, pconf);
        ap_server_root = def_server_root;
        ap_run_pre_config(pconf, plog, ptemp);
-       server_conf = ap_read_config(pconf, ptemp, confname);
+       server_conf = ap_read_config(process, ptemp, confname);
        ap_clear_pool(plog);
        ap_run_open_logs(pconf, plog, ptemp, server_conf);
        ap_post_config_hook(pconf, plog, ptemp, server_conf);
@@ -349,8 +373,8 @@ API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
 
        if (ap_mpm_run(pconf, plog, server_conf)) break;
     }
-    ap_destroy_pool(pglobal); /* and destroy all descendent pools */
-    exit(0);
+    destroy_and_exit_process(process, 0);
+    return 0; /* Supress compiler warning. */
 }
 
 /* force Expat to be linked into the server executable */