You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/06/11 17:17:46 UTC

[PATCH] Fix module init

Fix module init
===============

While adding DSO support to mod_perl Doug and I have discovered horrible
problems when running the mod_perl test suite. Today I've traced the various
problems down to the fact that Apache 1.3 is unable to find the "perl-script"
handler of mod_perl. When compiling mod_perl statically with Apache, all went
fine.  But when mod_perl is loaded from a DSO the "perl-script" handler is
unavailable, although mod_info says both mod_perl and the "perl-script"
handler are available. Looked really crazy ;_)

The reason is an incomplete module initialization inside mod_so.  In
particular the handlers are not initialized. But the core function
init_handlers() is not in the API, so we cannot directly call it. OTOH the
complete configure step for the module in mod_so is ugly. So the appended
patch does this:

1. It adds a call to second new API function named ap_single_module_init()
   which is similar to ap_init_modules() _but_ only initialised one single
   module. This way we avoid that mod_so runs the init handlers of old modules
   again (would be the third time, ARGL!). Actually this call fixes the above
   problem.

2. It replaces the raw-level hacking inside mod_so to
   create the configuration for the loaded module by a clean
   ap_single_module_configure() call. And even this does the job a little bit
   cleaner by using at_set_module_config(). This is mostly cleanup.

Although there may be votes against this patch (perhaps I've patched
incorrectly or missed something), the problem itself _HAS_ to be solved
_BEFORE_ 1.3.1 some way.  So please review this code and help that we can
solve the problem now. Either via this patch or perhaps via another patch (if
this one is not correct in any way).

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

Index: src/CHANGES
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/CHANGES,v
retrieving revision 1.910
diff -u -r1.910 CHANGES
--- CHANGES	1998/06/10 21:13:26	1.910
+++ CHANGES	1998/06/11 15:03:36
@@ -1,4 +1,13 @@
 Changes with Apache 1.3.1
+ 
+  *) Add two new core API functions ap_single_module_configure() and 
+     ap_single_module_init() which are now used by mod_so to correctly
+     initialize a module after loading. Because in the past the handlers of a
+     module were not correctly installed into the Apache processing.  This
+     lead to unusable handlers, for instance mod_perl's perl-script handler
+     was not found when mod_perl was loaded as a DSO. Same applied to other
+     similar modules. 
+     [Ralf S. Engelschall]
 
   *) Add httpd -t (test) option for running configuration syntax tests only.
      If something is broken it complains and exits with a return code
Index: src/include/http_config.h
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/include/http_config.h,v
retrieving revision 1.87
diff -u -r1.87 http_config.h
--- http_config.h	1998/05/27 14:01:31	1.87
+++ http_config.h	1998/06/11 14:12:14
@@ -275,7 +275,7 @@
  * handle it back-compatibly, or at least signal an error).
  */
 
-#define MODULE_MAGIC_NUMBER 19980527
+#define MODULE_MAGIC_NUMBER 19980611
 #define STANDARD_MODULE_STUFF MODULE_MAGIC_NUMBER, -1, __FILE__, NULL, NULL
 
 /* Generic accessors for other modules to get at their own module-specific
@@ -330,6 +330,8 @@
 
 server_rec *ap_read_config(pool *conf_pool, pool *temp_pool, char *config_name);
 void ap_init_modules(pool *p, server_rec *s);
+void ap_single_module_configure(pool *p, server_rec *s, module *m);
+void ap_single_module_init(pool *p, server_rec *s, module *m);
 void ap_child_init_modules(pool *p, server_rec *s);
 void ap_child_exit_modules(pool *p, server_rec *s);
 void ap_setup_prelinked_modules(void);
Index: src/main/http_config.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/http_config.c,v
retrieving revision 1.116
diff -u -r1.116 http_config.c
--- http_config.c	1998/05/06 15:18:01	1.116
+++ http_config.c	1998/06/11 14:22:44
@@ -1463,6 +1463,23 @@
     return s;
 }
 
+void ap_single_module_configure(pool *p, server_rec *s, module *m)
+{
+    if (m->create_server_config)
+        ap_set_module_config(s->module_config, m,
+                             (*m->create_server_config)(p, s));
+    if (m->create_dir_config)
+        ap_set_module_config(s->lookup_defaults, m,
+                             (*m->create_dir_config)(p, NULL));
+}
+
+void ap_single_module_init(pool *p, server_rec *s, module *m)
+{
+    if (m->init)
+        (*m->init)(s, p);
+    build_method_shortcuts();
+    init_handlers(p);
+}
 
 void ap_init_modules(pool *p, server_rec *s)
 {
Index: src/modules/standard/mod_so.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/modules/standard/mod_so.c,v
retrieving revision 1.25
diff -u -r1.25 mod_so.c
--- mod_so.c	1998/05/06 15:18:02	1.25
+++ mod_so.c	1998/06/11 14:12:31
@@ -125,6 +125,7 @@
  */
 
 
+#define CORE_PRIVATE
 #include "httpd.h"
 #include "http_config.h"
 #include "http_log.h"
@@ -262,15 +263,11 @@
 		     (void (*)(void*))unload_module, ap_null_cleanup);
 
     /* 
-     * Finally we need to run the configuration functions 
-     * in new modules now.
+     * Finally we need to create the configuration for the
+     * module and initialize it
      */
-    if (modp->create_server_config)
-      ((void**)cmd->server->module_config)[modp->module_index] =
-	(*modp->create_server_config)(cmd->pool, cmd->server);
-    if (modp->create_dir_config)
-      ((void**)cmd->server->lookup_defaults)[modp->module_index] =
-	(*modp->create_dir_config)(cmd->pool, NULL);
+    ap_single_module_configure(cmd->pool, cmd->server, modp);
+    ap_single_module_init(cmd->pool, cmd->server, modp);
 
     return NULL;
 }
Index: src/support/httpd.exp
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/support/httpd.exp,v
retrieving revision 1.4
diff -u -r1.4 httpd.exp
--- httpd.exp	1998/06/10 12:40:26	1.4
+++ httpd.exp	1998/06/11 14:07:32
@@ -297,6 +297,8 @@
 ap_show_directives
 ap_show_modules
 ap_signal
+ap_single_module_configure
+ap_single_module_init
 ap_slack
 ap_snprintf
 ap_soft_timeout

Re: [PATCH] Fix module init

Posted by Dean Gaudet <dg...@arctic.org>.

On Thu, 11 Jun 1998, Ralf S. Engelschall wrote:

> Although there may be votes against this patch (perhaps I've patched
> incorrectly or missed something), the problem itself _HAS_ to be solved
> _BEFORE_ 1.3.1 some way.  So please review this code and help that we can
> solve the problem now. Either via this patch or perhaps via another patch (if
> this one is not correct in any way).

Yeah sure I agree it has to be fixed.  But I cannot see why any changes to
the API are necessary.  Why are those modules not called by the
init_modules() routine already?  That sounds to me like they're not in the
module list properly.   And given that init_handler() is called during
init_modules() it should work fine too.  i.e. I want to know what the real
bug is, I don't want this kludge fix.

Dean