httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralf S. Engelschall" <...@engelschall.com>
Subject Re: [PATCH] httpd.conf-dist
Date Thu, 16 Apr 1998 17:37:33 GMT

In article <19980416171607.A9408@engelschall.com> you wrote:

> In article <XFMail.980416140333.sfx@unix-ag.org> you wrote:
>> According to Ralf S. Engelschall:

>> [...]
>>>  when all three modules are compiled statically into the httpd. Hmmmm...  a
>>>  totally unresolvable problem as long as we don't provide module priorities
>>>  which could be used inside the module structure of each module and which
>>>  force
>>>  a special sorting of the internal module list structures.
>>>  
>>>  Or did I miss something and we really don't have this problem?

>> No, this *is* a problem.
>> Hmmm... we could do something like this:

>>  LoadModule mod_proxy
>>  LoadModule mod_foo
>>  ...
>>  ClearModuleList
>>  ...
>>  AddModule mod_foo
>>  AddModule mod_alias
>>  AddModule mod_proxy
>>  AddModule mod_rewrite
>>  ...

>> In other words, if there is a least one DSO the install script
>> should add ClearModuleList/AddModule directives with the
>> correct order of the used modules to httpd.conf...

>> It looks ugly and confuses the users, but works (IMHO).

> No, sorry, it doesn't work, because AddModule calls ap_add_named_module()
> which itself uses the ap_preloaded_modules structure for initialisation. But
> the LoadModule command doesn't update it. And because ap_preloaded_modules is
> not a dynamically allocated array, mod_so cannot even cannot update it.

> As I see the problem the only solution is this:

> 1. We change the few references to ap_preloaded_modules in http_config.c
>    with ap_loaded_modules. This is a useful change independend of our
>    problem because the name preloaded is bogus because it is used
>    to find all loaded modules.
>    
> 2. We initialise the dynamically allocated ap_loaded_modules
>    list from ap_preloaded_modules to import the information
>    from modules.c.

> 3. We create an ap_remember_loaded_module() and an ap_forget_loaded_module()
>    function which can be used by mod_so to insert and remove run-time loaded
>    modules to the ap_loaded_modules list.
>    
> 4. We let the "make install" step create the above configuration snippet

I've now created a first cut for such a patch. It fixes the problem, your
suggestion with ClearModuleList+AddModule commands now works as expected.
I append it below. Please try it out yourself, too.

                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: modules/standard/mod_so.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/standard/mod_so.c,v
retrieving revision 1.22
diff -u -r1.22 mod_so.c
--- mod_so.c	1998/04/14 10:58:24	1.22
+++ mod_so.c	1998/04/16 15:33:14
@@ -192,7 +192,7 @@
         return;
 
     /* remove the module pointer from the core structure */
-    ap_remove_module(modi->modp);
+    ap_remove_loaded_module(modi->modp);
 
     /* unload the module space itself */
     ap_os_dso_unload((ap_os_dso_handle_t)modi->modp->dynamic_load_handle);
@@ -273,7 +273,7 @@
     /* 
      * Add this module to the Apache core structures
      */
-    ap_add_module(modp);
+    ap_add_loaded_module(modp);
 
     /* 
      * Register a cleanup in the config pool (normally pconf). When
Index: main/http_config.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/http_config.c,v
retrieving revision 1.114
diff -u -r1.114 http_config.c
--- http_config.c	1998/04/13 18:05:10	1.114
+++ http_config.c	1998/04/16 15:57:08
@@ -99,6 +99,7 @@
  */
 static int dynamic_modules = 0;
 API_VAR_EXPORT module *top_module = NULL;
+API_VAR_EXPORT module **ap_loaded_modules;
 
 typedef int (*handler_func) (request_rec *);
 typedef void *(*dir_maker_func) (pool *, char *);
@@ -517,6 +518,37 @@
     return NOT_IMPLEMENTED;
 }
 
+API_EXPORT(void) ap_add_loaded_module(module *mod)
+{
+	int n;
+	module **m;
+
+    for (n = 0, m = ap_loaded_modules; *m; m++, n++) 
+		;
+    ap_loaded_modules = (module **)realloc(ap_loaded_modules,
+			                               sizeof(module *)*(n+2));
+	ap_loaded_modules[n++] = mod;
+	ap_loaded_modules[n] = NULL;
+	ap_add_module(mod);
+}
+
+API_EXPORT(void) ap_remove_loaded_module(module *mod)
+{
+	int n;
+	module **m;
+	module **m2;
+
+    for (n = 0, m = ap_loaded_modules; *m; m++, n++) 
+		;
+    for (m = m2 = ap_loaded_modules; *m2; m2++)
+        if (*m2 != mod)
+            *m++ = *m2;
+    *m = NULL;
+    ap_loaded_modules = (module **)realloc(ap_loaded_modules,
+			                               sizeof(module *)*n);
+    ap_remove_module(mod);
+}
+
 /* One-time setup for precompiled modules --- NOT to be done on restart */
 
 API_EXPORT(void) ap_add_module(module *m)
@@ -620,16 +652,30 @@
 void ap_setup_prelinked_modules()
 {
     module **m;
+    module **m2;
 
-    /* First, set all module indices, and init total_modules.  */
+    /* 
+     * First, set all module indices, 
+     * and init total_modules. 
+     */
     total_modules = 0;
-    for (m = ap_preloaded_modules; *m; ++m, ++total_modules) {
-	(*m)->module_index = total_modules;
-    }
+    for (m = ap_preloaded_modules; *m; ++m, ++total_modules)
+        (*m)->module_index = total_modules;
 
-    for (m = ap_prelinked_modules; *m; ++m) {
-	ap_add_module(*m);
-    }
+    /* 
+     * Second, initialize the list of loaded 
+     * modules with the preloaded ones
+     */
+    ap_loaded_modules = (module **)malloc(sizeof(module *)*(total_modules+1));
+    memcpy(ap_loaded_modules, ap_preloaded_modules, 
+           sizeof(module *)*(total_modules+1));
+
+    /*
+     * Third, chain these module structures
+     * to form the list of active modules
+     */
+    for (m = ap_prelinked_modules; *m; ++m)
+        ap_add_module(*m);
 }
 
 API_EXPORT(const char *) ap_find_module_name(module *m)
@@ -654,7 +700,7 @@
     module *modp;
     int i = 0;
 
-    for (modp = ap_preloaded_modules[i]; modp; modp = ap_preloaded_modules[++i]) {
+    for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
 	if (strcmp(modp->name, name) == 0) {
 	    /* Only add modules that are not already enabled.  */
 	    if (modp->next == NULL) {
@@ -1515,12 +1561,12 @@
     const command_rec *pc;
     int n;
 
-    for (n = 0; ap_preloaded_modules[n]; ++n)
-	for (pc = ap_preloaded_modules[n]->cmds; pc && pc->name; ++pc) {
-	    printf("%s (%s)\n", pc->name, ap_preloaded_modules[n]->name);
+    for (n = 0; ap_loaded_modules[n]; ++n)
+	for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
+	    printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
 	    if (pc->errmsg)
 		printf("\t%s\n", pc->errmsg);
-	    show_overrides(pc, ap_preloaded_modules[n]);
+	    show_overrides(pc, ap_loaded_modules[n]);
 	}
 }
 
@@ -1530,6 +1576,6 @@
     int n;
 
     printf("Compiled-in modules:\n");
-    for (n = 0; ap_preloaded_modules[n]; ++n)
-	printf("  %s\n", ap_preloaded_modules[n]->name);
+    for (n = 0; ap_loaded_modules[n]; ++n)
+	printf("  %s\n", ap_loaded_modules[n]->name);
 }
Index: include/http_config.h
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/include/http_config.h,v
retrieving revision 1.80
diff -u -r1.80 http_config.h
--- http_config.h	1998/04/13 18:11:51	1.80
+++ http_config.h	1998/04/16 17:33:23
@@ -297,6 +297,8 @@
 
 /* Finally, the hook for dynamically loading modules in... */
 
+API_EXPORT(void) ap_add_loaded_module(module *mod);
+API_EXPORT(void) ap_remove_loaded_module(module *mod);
 API_EXPORT(void) ap_add_module(module *m);
 API_EXPORT(void) ap_remove_module(module *m);
 API_EXPORT(int) ap_add_named_module(const char *name);
@@ -313,6 +315,7 @@
 
 extern module *ap_prelinked_modules[];
 extern module *ap_preloaded_modules[];
+extern module **ap_loaded_modules;
 
 /* For http_main.c... */
 

Mime
View raw message