Mailing List Archive

cvs commit: apache-1.3/src/support apxs.pl
rse 98/05/06 08:18:04

Modified: . STATUS INSTALL Makefile.tmpl
src CHANGES Configure
src/include http_config.h
src/main http_config.c
src/modules/standard mod_so.c
src/support apxs.pl
Log:
Make sure the module execution order is correct even when some modules are
loaded under runtime (`LoadModule') via the DSO mechanism:

1. The list of loaded modules is now a dynamically allocated one
and not the original statically list from modules.c
2. The loaded modules are now correctly setup by LoadModule for
later use by the AddModule command.
3. When the DSO mechanism for modules is used APACI's `install'
target now enables all created `LoadModule' lines per default because
this is both already expected by the user _and_ needed to avoid
confusion with the next point and reduces the Makefile.tmpl complexity
4. When the DSO mechanism for modules is used, APACI's `install'
target now additionally makes sure the module list is reconstructed
via a complete `ClearModuleList+AddModule...' entry.
5. The support tool `apxs' now also makes sure an AddModule command
is added in addition to the LoadModule command.
6. The modules.c generation was extended to now contain two
comments to make sure no one is confused by the confusing terminology
of loading/linking (we use load=link+load & link=activate instead of
the obvious load=activate & link=link :-( )

This way now there is no longer a difference under execution time between
statically and dynamically linked modules.

Submitted by: Ralf S. Engelschall
Reviewed by: Brian Behlendorf, Jim Jim Jagielski

Revision Changes Path
1.379 +0 -7 apache-1.3/STATUS

Index: STATUS
===================================================================
RCS file: /export/home/cvs/apache-1.3/STATUS,v
retrieving revision 1.378
retrieving revision 1.379
diff -u -r1.378 -r1.379
--- STATUS 1998/05/06 12:27:33 1.378
+++ STATUS 1998/05/06 15:17:56 1.379
@@ -11,13 +11,6 @@

FINAL RELEASE SHOWSTOPPERS:

- * Ralf's "[PATCH] Fix module execution order for DSO situation (take 2)":
- This is the final patch for 1.3b7 to make sure the module execution
- order is correct even when the DSO mechanism is used. This is mainly
- achieved by fixing the AddModule command.
- See: http://www.engelschall.com/sw/apache/ [dsoexecorder]
- Status: Ralf +1, Brian +1, Jim +1
-
* Someone other than Dean has to do a security/correctness review on
psprintf(), bprintf(), and ap_snprintf(). In particular these routines
do lots of fun pointer manipulations and such and possibly have overflow



1.24 +2 -12 apache-1.3/INSTALL

Index: INSTALL
===================================================================
RCS file: /export/home/cvs/apache-1.3/INSTALL,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- INSTALL 1998/04/30 11:32:03 1.23
+++ INSTALL 1998/05/06 15:17:56 1.24
@@ -237,20 +237,10 @@
module because there are variants like `--enable-shared=all'
which should not imply `--enable-module=all'.

- Note 2: The --enable-shared option only implies the preparation of
- LoadModule commands in the httpd.conf file for the "make
- install" procedure. But these LoadModule lines are per
- default out-commented. So, --enable-shared does not imply the
- automatic use of the module. The only exception are modules
- which have to be enabled because of their usage in the
- provided sample configuration. To actually use DSO-based
- modules you have to uncomment the corresponding LoadModule
- lines in PREFIX/etc/httpd.conf after "make install".
-
- Note 3: Per default the DSO mechanism is globally disabled, i.e. no
+ Note 2: Per default the DSO mechanism is globally disabled, i.e. no
modules are build as shared objects.

- Note 4: The usage of any --enable-shared option automatically implies
+ Note 3: The usage of any --enable-shared option automatically implies
a --enable-module=so option because the bootstrapping module
mod_so is always needed for DSO support.




1.32 +12 -18 apache-1.3/Makefile.tmpl

Index: Makefile.tmpl
===================================================================
RCS file: /export/home/cvs/apache-1.3/Makefile.tmpl,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Makefile.tmpl 1998/05/04 15:29:25 1.31
+++ Makefile.tmpl 1998/05/06 15:17:57 1.32
@@ -124,19 +124,6 @@
# forwarding arguments
MFWD = root=$(root)

-# list of shared objects which have to _ALWAYS_ be enabled
-# per default in the config file because of the directives used
-# in these default files.
-so_mods_in_conf = \
-config_log_module|\
-mime_module|\
-negotiation_module|\
-autoindex_module|\
-dir_module|\
-userdir_module|\
-access_module|\
-setenvif_module
-
## ==================================================================
## Targets
## ==================================================================
@@ -258,12 +245,19 @@
echo "$(INSTALL_SCRIPT) $(TOP)/$(SRC)/$${mod} $(root)$(libexecdir)/$${file}"; \
$(INSTALL_SCRIPT) $(TOP)/$(SRC)/$${mod} $(root)$(libexecdir)/$${file}; \
name=`$(TOP)/$(AUX)/fmn.sh $(TOP)/$(SRC)/$${mod}`; \
- prefix="#"; case $${name} in $(so_mods_in_conf) ) prefix="" ;; esac; \
- echo dummy | awk '{ printf("%sLoadModule %-18s %s\n", \
- prefix, modname, modpath); }' \
- prefix="$${prefix}" modname="$${name}" \
- modpath="$(libexecdir_relative)$${file}" >>$(SRC)/.apaci.install.conf; \
+ echo dummy | awk '{ printf("LoadModule %-18s %s\n", modname, modpath); }' \
+ modname="$${name}" modpath="$(libexecdir_relative)$${file}" >>$(SRC)/.apaci.install.conf; \
done; \
+ echo "" >>$(SRC)/.apaci.install.conf; \
+ echo "# Reconstruction of the complete module list from all available modules" >>$(SRC)/.apaci.install.conf; \
+ echo "# (static and shared ones) to achieve correct module execution order." >>$(SRC)/.apaci.install.conf; \
+ echo "# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]" >>$(SRC)/.apaci.install.conf; \
+ echo "ClearModuleList" >>$(SRC)/.apaci.install.conf; \
+ egrep "^[ ]*(Add|Shared)Module" $(SRC)/Configuration.apaci |\
+ sed -e 's:SharedModule:AddModule:' \
+ -e 's:modules/[^/]*/::' \
+ -e 's:[ ]lib: mod_:' \
+ -e 's:\.[soa]*$$:.c:' >>$(SRC)/.apaci.install.conf; \
fi
@echo "<=== [programs]"




1.826 +23 -0 apache-1.3/src/CHANGES

Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.825
retrieving revision 1.826
diff -u -r1.825 -r1.826
--- CHANGES 1998/05/06 15:06:19 1.825
+++ CHANGES 1998/05/06 15:17:58 1.826
@@ -1,4 +1,27 @@
Changes with Apache 1.3b7
+
+ *) Make sure the module execution order is correct even when some modules
+ are loaded under runtime (`LoadModule') via the DSO mechanism:
+ 1. The list of loaded modules is now a dynamically allocated one
+ and not the original statically list from modules.c
+ 2. The loaded modules are now correctly setup by LoadModule for
+ later use by the AddModule command.
+ 3. When the DSO mechanism for modules is used APACI's `install'
+ target now enables all created `LoadModule' lines per default because
+ this is both already expected by the user _and_ needed to avoid
+ confusion with the next point and reduces the Makefile.tmpl complexity
+ 4. When the DSO mechanism for modules is used, APACI's `install'
+ target now additionally makes sure the module list is reconstructed
+ via a complete `ClearModuleList+AddModule...' entry.
+ 5. The support tool `apxs' now also makes sure an AddModule command
+ is added in addition to the LoadModule command.
+ 6. The modules.c generation was extended to now contain two
+ comments to make sure no one is confused by the confusing terminology
+ of loading/linking (we use load=link+load & link=activate instead of
+ the obvious load=activate & link=link :-( )
+ This way now there is no longer a difference under execution time between
+ statically and dynamically linked modules.
+ [Ralf S. Engelschall]

*) Fix the generated mod_xxx.c from "apxs -g -f xxx" after the
Big Symbol Renaming. [Ralf S. Engelschall]



1.255 +16 -1 apache-1.3/src/Configure

Index: Configure
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/Configure,v
retrieving revision 1.254
retrieving revision 1.255
diff -u -r1.254 -r1.255
--- Configure 1998/05/04 16:59:21 1.254
+++ Configure 1998/05/06 15:17:59 1.255
@@ -1403,7 +1403,8 @@
/^Module/ { modules[n++] = $2 ; pmodules[pn++] = $2 }
/^%Module/ { pmodules[pn++] = $2 }
END {
- print "/* modules.c --- automatically generated by Apache"
+ print "/*"
+ print " * modules.c --- automatically generated by Apache"
print " * configuration script. DO NOT HAND EDIT!!!!!"
print " */"
print ""
@@ -1414,6 +1415,13 @@
printf ("extern module %s_module;\n", pmodules[i])
}
print ""
+ print "/*"
+ print " * Modules which implicitly form the"
+ print " * list of activated modules on startup,"
+ print " * i.e. these are the modules which are"
+ print " * initially linked into the Apache processing"
+ print " * [extendable under run-time via AddModule]"
+ print " */"
print "module *ap_prelinked_modules[] = {"
for (i = 0; i < n; ++i) {
printf " &%s_module,\n", modules[i]
@@ -1421,6 +1429,13 @@
print " NULL"
print "};"
print ""
+ print "/*"
+ print " * Modules which initially form the"
+ print " * list of available modules on startup,"
+ print " * i.e. these are the modules which are"
+ print " * initially loaded into the Apache process"
+ print " * [extendable under run-time via LoadModule]"
+ print " */"
print "module *ap_preloaded_modules[] = {"
for (i = 0; i < pn; ++i) {
printf " &%s_module,\n", pmodules[i]



1.83 +3 -0 apache-1.3/src/include/http_config.h

Index: http_config.h
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/include/http_config.h,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- http_config.h 1998/05/05 04:40:30 1.82
+++ http_config.h 1998/05/06 15:18:01 1.83
@@ -308,6 +308,8 @@

API_EXPORT(void) ap_add_module(module *m);
API_EXPORT(void) ap_remove_module(module *m);
+API_EXPORT(void) ap_add_loaded_module(module *mod);
+API_EXPORT(void) ap_remove_loaded_module(module *mod);
API_EXPORT(int) ap_add_named_module(const char *name);
API_EXPORT(void) ap_clear_module_list(void);
API_EXPORT(const char *) ap_find_module_name(module *m);
@@ -322,6 +324,7 @@

extern module *ap_prelinked_modules[];
extern module *ap_preloaded_modules[];
+extern module **ap_loaded_modules;

/* For http_main.c... */




1.116 +80 -15 apache-1.3/src/main/http_config.c

Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/http_config.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -r1.115 -r1.116
--- http_config.c 1998/05/05 04:40:39 1.115
+++ http_config.c 1998/05/06 15:18:01 1.116
@@ -94,11 +94,12 @@
*/
static int total_modules = 0;
/* dynamic_modules is the number of modules that have been added
- * after the pre-linked ones have been set up. It shouldn't be larger
+ * after the pre-loaded ones have been set up. It shouldn't be larger
* than DYNAMIC_MODULE_LIMIT.
*/
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 *);
@@ -620,20 +621,84 @@
dynamic_modules--;
}

+API_EXPORT(void) ap_add_loaded_module(module *mod)
+{
+ module **m;
+
+ /*
+ * Add module pointer to top of chained module list
+ */
+ ap_add_module(mod);
+
+ /*
+ * And module pointer to list of loaded modules
+ *
+ * Notes: 1. ap_add_module() would already complain if no more space
+ * exists for adding a dynamically loaded module
+ * 2. ap_add_module() accepts double-inclusion, so we have
+ * to accept this, too.
+ */
+ for (m = ap_loaded_modules; *m != NULL; m++)
+ ;
+ *m++ = mod;
+ *m = NULL;
+}
+
+API_EXPORT(void) ap_remove_loaded_module(module *mod)
+{
+ module **m;
+ module **m2;
+ int done;
+
+ /*
+ * Remove module pointer from chained module list
+ */
+ ap_remove_module(mod);
+
+ /*
+ * Remove module pointer from list of loaded modules
+ *
+ * Note: 1. We cannot determine if the module was successfully
+ * removed by ap_remove_module().
+ * 2. We have not to complain explicity when the module
+ * is not found because ap_remove_module() did it
+ * for us already.
+ */
+ for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
+ if (*m2 == mod && done == 0)
+ done = 1;
+ else
+ *m++ = *m2;
+ }
+ *m = NULL;
+}

void ap_setup_prelinked_modules()
{
module **m;
+ module **m2;

- /* First, set all module indices, and init total_modules. */
+ /*
+ * Initialise total_modules variable and module indices
+ */
total_modules = 0;
- for (m = ap_preloaded_modules; *m; ++m, ++total_modules) {
- (*m)->module_index = total_modules;
- }
+ for (m = ap_preloaded_modules; *m != NULL; m++)
+ (*m)->module_index = total_modules++;

- for (m = ap_prelinked_modules; *m; ++m) {
- ap_add_module(*m);
- }
+ /*
+ * Initialise list of loaded modules
+ */
+ ap_loaded_modules = (module **)malloc(
+ sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
+ for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
+ *m2++ = *m++;
+ *m2 = NULL;
+
+ /*
+ * Initialize chain of linked (=activate) modules
+ */
+ for (m = ap_prelinked_modules; *m != NULL; m++)
+ ap_add_module(*m);
}

API_EXPORT(const char *) ap_find_module_name(module *m)
@@ -658,7 +723,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) {
@@ -1519,12 +1584,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]);
}
}

@@ -1534,6 +1599,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);
}



1.25 +2 -2 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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- mod_so.c 1998/05/02 11:15:13 1.24
+++ mod_so.c 1998/05/06 15:18:02 1.25
@@ -170,7 +170,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);
@@ -251,7 +251,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



1.6 +22 -3 apache-1.3/src/support/apxs.pl

Index: apxs.pl
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/support/apxs.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apxs.pl 1998/05/06 15:04:12 1.5
+++ apxs.pl 1998/05/06 15:18:03 1.6
@@ -369,8 +369,9 @@
##

# determine installation commands
- # and corresponding LoadModule directives
+ # and corresponding LoadModule/AddModule directives
my @lmd = ();
+ my @amd = ();
my @cmds = ();
my $f;
foreach $f (@args) {
@@ -383,7 +384,8 @@
push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");

- # determine module name
+ # determine module symbolname and filename
+ my $filename = '';
if ($name eq 'unknown') {
$name = '';
my $base = $f;
@@ -394,11 +396,15 @@
close(FP);
if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
$name = "$1";
+ $filename = "$base.c";
+ $filename =~ s|^[^/]+/||;
}
}
if ($name eq '') {
if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
$name = "$1";
+ $filename = $base;
+ $filename =~ s|^[^/]+/||;
}
}
if ($name eq '') {
@@ -407,16 +413,20 @@
exit(1);
}
}
+ if ($filename eq '') {
+ $filename = "mod_${name}.c";
+ }
my $dir = $CFG_LIBEXECDIR;
$dir =~ s|^$CFG_PREFIX/?||;
$dir =~ s|(.)$|$1/|;
push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
+ push(@amd, sprintf("AddModule %s", $filename));
}

# execute the commands
&execute_cmds(@cmds);

- # activate module via LoadModule directive
+ # activate module via LoadModule/AddModule directive
if ($opt_a or $opt_A) {
if (not -f "$CFG_SYSCONFDIR/httpd.conf") {
print "apxs:Error: Config file $CFG_SYSCONFDIR/httpd.conf not found\n";
@@ -444,6 +454,15 @@
$lmd =~ m|LoadModule\s+(.+?)_module.*|;
my $what = $opt_A ? "preparing" : "activating";
print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/httpd.conf]\n";
+ }
+ }
+ my $amd;
+ foreach $amd (@amd) {
+ if ($content !~ m|\n#?\s*$amd|) {
+ my $c = '';
+ $c = '#' if ($opt_A);
+ $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
+ $update = 1;
}
}
if ($update) {