httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org (Ralf S. Engelschall)
Subject cvs commit: apache-1.3/src/modules/standard mod_so.c
Date Tue, 10 Mar 1998 08:53:00 GMT
rse         98/03/10 00:52:59

  Modified:    .        STATUS
               src      CHANGES
               src/modules/standard mod_so.c
  Log:
  Enhance Shared Object Loading (II)
  ----------------------------------
  
  mod_so now keeps track itself of which modules are actually loaded and which
  are not by remembering both the module pointer and the module name. This fixes
  two problems:
  
  1. Because our server configuration is read twice the modules
     were loaded twice which is both not needed and leads to confusion later on
     unload because the OS-internal load counter increases. Then on unload the
     module pointer was removed from the Apache core structure on the first
     unloads but (because of the load counter) the modules were removed later.
     Although this worked, it was very ugly. The only consequence is that we now
     keep track of loaded modules ourself and don't rely on the dynamic loader
     of the platform. This now also avoids multiply tries to unload an already
     unloaded module and thus removes harmless but irritating error_log entries
     ``[error] Cannot remove module mod_setenvif.c: not found in module list''.
     as shown below.
  
  2. Because we now keep track of the module names we used on loading we now can
     give correct corresponding log messages even on unloading.
  
  To illustrate the change, here is the old error_log:
  (the first unloads correspond to the first loads which
   are printed on stderr unless mod_log_config is present)
  
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [debug] mod_so.c(163): unloaded module mod_access.c
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  [error] Cannot remove module mod_setenvif.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [error] Cannot remove module mod_access.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_access.c
  [error] Cannot remove module mod_userdir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [error] Cannot remove module mod_dir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [error] Cannot remove module mod_autoindex.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [error] Cannot remove module mod_negotiation.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [error] Cannot remove module mod_log_config.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  [error] Cannot remove module mod_setenvif.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [error] Cannot remove module mod_access.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_access.c
  [error] Cannot remove module mod_userdir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [error] Cannot remove module mod_dir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [error] Cannot remove module mod_autoindex.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [error] Cannot remove module mod_negotiation.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [error] Cannot remove module mod_log_config.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  [debug] mod_so.c(211): loaded module config_log_module
  [debug] mod_so.c(211): loaded module negotiation_module
  [debug] mod_so.c(211): loaded module autoindex_module
  [debug] mod_so.c(211): loaded module dir_module
  [debug] mod_so.c(211): loaded module userdir_module
  [debug] mod_so.c(211): loaded module access_module
  [debug] mod_so.c(211): loaded module setenvif_module
  [debug] mod_so.c(211): loaded module config_log_module
  [debug] mod_so.c(211): loaded module negotiation_module
  [debug] mod_so.c(211): loaded module autoindex_module
  [debug] mod_so.c(211): loaded module dir_module
  [debug] mod_so.c(211): loaded module userdir_module
  [debug] mod_so.c(211): loaded module access_module
  [debug] mod_so.c(211): loaded module setenvif_module
  [debug] mod_so.c(211): loaded module config_log_module
  [debug] mod_so.c(211): loaded module negotiation_module
  [debug] mod_so.c(211): loaded module autoindex_module
  [debug] mod_so.c(211): loaded module dir_module
  [debug] mod_so.c(211): loaded module userdir_module
  [debug] mod_so.c(211): loaded module access_module
  [debug] mod_so.c(211): loaded module setenvif_module
  [notice] Apache/1.3b6-dev configured -- resuming normal operations
  [notice] httpd: caught SIGTERM, shutting down
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [debug] mod_so.c(163): unloaded module mod_access.c
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  [error] Cannot remove module mod_setenvif.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [error] Cannot remove module mod_access.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_access.c
  [error] Cannot remove module mod_userdir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [error] Cannot remove module mod_dir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [error] Cannot remove module mod_autoindex.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [error] Cannot remove module mod_negotiation.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [error] Cannot remove module mod_log_config.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  [error] Cannot remove module mod_setenvif.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_setenvif.c
  [error] Cannot remove module mod_access.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_access.c
  [error] Cannot remove module mod_userdir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_userdir.c
  [error] Cannot remove module mod_dir.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_dir.c
  [error] Cannot remove module mod_autoindex.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_autoindex.c
  [error] Cannot remove module mod_negotiation.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_negotiation.c
  [error] Cannot remove module mod_log_config.c: not found in module list
  [debug] mod_so.c(163): unloaded module mod_log_config.c
  
  And this is the one with the new mod_so.c:
  (again the first unloads correspond to the first loads which
   are printed on stderr unless mod_log_config is present)
  
  [debug] mod_so.c(191): unloaded module setenvif_module
  [debug] mod_so.c(191): unloaded module access_module
  [debug] mod_so.c(191): unloaded module userdir_module
  [debug] mod_so.c(191): unloaded module dir_module
  [debug] mod_so.c(191): unloaded module autoindex_module
  [debug] mod_so.c(191): unloaded module negotiation_module
  [debug] mod_so.c(191): unloaded module config_log_module
  [debug] mod_so.c(261): loaded module config_log_module
  [debug] mod_so.c(261): loaded module negotiation_module
  [debug] mod_so.c(261): loaded module autoindex_module
  [debug] mod_so.c(261): loaded module dir_module
  [debug] mod_so.c(261): loaded module userdir_module
  [debug] mod_so.c(261): loaded module access_module
  [debug] mod_so.c(261): loaded module setenvif_module
  [notice] Apache/1.3b6-dev configured -- resuming normal operations
  [notice] httpd: caught SIGTERM, shutting down
  [debug] mod_so.c(191): unloaded module setenvif_module
  [debug] mod_so.c(191): unloaded module access_module
  [debug] mod_so.c(191): unloaded module userdir_module
  [debug] mod_so.c(191): unloaded module dir_module
  [debug] mod_so.c(191): unloaded module autoindex_module
  [debug] mod_so.c(191): unloaded module negotiation_module
  [debug] mod_so.c(191): unloaded module config_log_module
  
  Revision  Changes    Path
  1.183     +1 -0      apache-1.3/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/STATUS,v
  retrieving revision 1.182
  retrieving revision 1.183
  diff -u -r1.182 -r1.183
  --- STATUS	1998/03/10 07:45:03	1.182
  +++ STATUS	1998/03/10 08:52:55	1.183
  @@ -78,6 +78,7 @@
       * Corrections to the setup of the REMOTE_HOST variable. PR#1925 
       * Fix for rputs() which did not calculate r->sent_bodyct properly. PR#1900
       * Don't tweak TZ envvar if the user has specified an explicit one. PR#1888
  +    * Ralf's mod_so changes to keep track of loaded modules ourself.
   
   Available Patches:
   
  
  
  
  1.698     +4 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.697
  retrieving revision 1.698
  diff -u -r1.697 -r1.698
  --- CHANGES	1998/03/10 06:30:46	1.697
  +++ CHANGES	1998/03/10 08:52:56	1.698
  @@ -1,5 +1,9 @@
   Changes with Apache 1.3b6
   
  +  *) Now mod_so keeps track of which module shared objects with which names
  +     are loaded and thus avoids multiple loading and unloading and irritating
  +     error_log messages. [Ralf S. Engelschall]
  +
     *) Prior to the existence of mod_setenv it was necessary to tweak the TZ
        environment variable in the apache core.  But that tweaking interferes
        with mod_setenv.  So don't tweak if the user has specified an explicit
  
  
  
  1.7       +61 -17    apache-1.3/src/modules/standard/mod_so.c
  
  Index: mod_so.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_so.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- mod_so.c	1998/03/09 11:35:42	1.6
  +++ mod_so.c	1998/03/10 08:52:58	1.7
  @@ -139,29 +139,54 @@
   #include "http_config.h"
   #include "http_log.h"
   
  +module MODULE_VAR_EXPORT so_module;
  +
  +
  +/*
  + * Server configuration to keep track of actually
  + * loaded modules and the corresponding module name.
  + */
  +
  +typedef struct moduleinfo {
  +    char *name;
  +    module *modp;
  +} moduleinfo;
  +
  +typedef struct so_server_conf {
  +    array_header *loaded_modules;
  +} so_server_conf;
  +
  +static void *so_sconf_create(pool *p, server_rec *s)
  +{
  +    so_server_conf *soc;
  +
  +    soc = (so_server_conf *)pcalloc(p, sizeof(so_server_conf));
  +    soc->loaded_modules = make_array(p, DYNAMIC_MODULE_LIMIT, 
  +                                     sizeof(moduleinfo));
  +    return (void *)soc;
  +}
  +
   #ifndef NO_DLOPEN
   
   /* This is the cleanup for a loaded DLL. It unloads the module.
    * This is called as a cleanup function.
    */
   
  -void unload_module(module *modp)
  +void unload_module(moduleinfo *modi)
   {
  -    char mod_name[50];		/* Um, no pool, so make this static */
  +    /* only unload if module information is still existing */
  +    if (modi->modp == NULL)
  +        return;
   
  -    /* Take a copy of the module name so we can report that it has been
  -     * unloaded (since modp itself will have been unloaded). */
  -    strncpy(mod_name, modp->name, 49);
  -    mod_name[49] = '\0';
  +    /* remove the module pointer from the core structure */
  +    remove_module(modi->modp);
   
  -    remove_module(modp);
  +    /* unload the module space itself */
  +    os_dl_unload((os_dl_module_handle_type)modi->modp->dynamic_load_handle);
   
  -    /* The Linux manpage doesn't give any way to check the success of
  -     * dlclose() */
  -    os_dl_unload((os_dl_module_handle_type)modp->dynamic_load_handle);
  -
  -    aplog_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,
  -		"unloaded module %s", mod_name);
  +    /* destroy the module information */
  +    modi->modp = NULL;
  +    modi->name = NULL;
   }
   
   /* unload_file is the cleanup routine for files loaded by
  @@ -198,6 +223,24 @@
       void *modhandle;
       module *modp;
       const char *szModuleFile=server_root_relative(cmd->pool, filename);
  +    so_server_conf *sconf;
  +    moduleinfo *modi;
  +    moduleinfo *modie;
  +    int i;
  +
  +    /* check for already existing module
  +     * If it already exists, we have nothing to do 
  +     */
  +    sconf = (so_server_conf *)get_module_config(cmd->server->module_config, 
  +	                                        &so_module);
  +    modie = (moduleinfo *)sconf->loaded_modules->elts;
  +    for (i = 0; i < sconf->loaded_modules->nelts; i++) {
  +        modi = &modie[i];
  +        if (modi->name != NULL && strcmp(modi->name, modname) == 0)
  +            return NULL;
  +    }
  +    modi = push_array(sconf->loaded_modules);
  +    modi->name = pstrdup(cmd->pool, modname);
   
       if (!(modhandle = os_dl_load(szModuleFile)))
         {
  @@ -219,7 +262,8 @@
   	return pstrcat (cmd->pool, "Can't find module ", modname,
   			" in file ", filename, ":", os_dl_error(), NULL);
       }
  -	
  +    modi->modp = modp;
  +
       modp->dynamic_load_handle = modhandle;
   
       add_module(modp);
  @@ -228,7 +272,7 @@
        * we do a restart (or shutdown) this cleanup will cause the
        * DLL to be unloaded.
        */
  -    register_cleanup(cmd->pool, modp, 
  +    register_cleanup(cmd->pool, modi, 
   		     (void (*)(void*))unload_module, mod_so_null_cleanup);
   
       /* Alethea Patch (rws,djw2) - need to run configuration functions
  @@ -292,12 +336,12 @@
   { NULL }
   };
   
  -module so_module = {
  +module MODULE_VAR_EXPORT so_module = {
      STANDARD_MODULE_STUFF,
      NULL,			/* initializer */
      NULL,			/* create per-dir config */
      NULL,			/* merge per-dir config */
  -   NULL,			/* server config */
  +   so_sconf_create,		/* server config */
      NULL,			/* merge server config */
      so_cmds,			/* command table */
      NULL,			/* handlers */
  
  
  

Mime
View raw message