httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralf S. Engelschall" <...@engelschall.com>
Subject [PATCH] APACI: --permute-module=foo:bar
Date Thu, 22 Oct 1998 14:12:59 GMT

People often want to permute the order of modules. Sure, for the default
modules we provide a reasonable order, but when you want to add third-party
modules, you want to add it not always at the end of the module list.

For the good old edit-src/Configuration-manually approach of configuring this
is trivial: Permute the AddModule lines in the editor. But APACI (especially
--add-module) didn't provide this functionality in batch because when I wrote
APACI initially I though this functionality cannot be done in a portable way
with /bin/sh, awk and sed.  Recently people mailed me again that they would
appreciate this functionality, so I thought about the implementation again and
discovered that it can be done in a portable way. Not really an easy way and
short (oneliner!) way, but at least in a portable way (which is more important
for us than a few code lines more).

So, here it is: --permute-module=foo:bar plus support for two special
variants: --permute-module=^:foo (moves module to start) and
--permute-module=foo:$ (moves module to end). The complete stuff stays inside
an if-clause which is only triggered when the option is actually used. So
don't worry about the large Awk part.

Greetings,
                                       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.1115
diff -u -r1.1115 CHANGES
--- CHANGES	1998/10/22 11:54:56	1.1115
+++ CHANGES	1998/10/22 14:03:58
@@ -1,5 +1,15 @@
 Changes with Apache 1.3.4
 
+  *) Add a new powerful APACI option --permute-module=foo:bar which can be
+     used to on-the-fly/batch permute the order of the two modules (mod_foo
+     and mod_bar) in the Configuration file. Two special and important
+     variants are supported for the option argument: first ^:foo which
+     permutes module mod_foo with the start of the module list, i.e.  it
+     "moves" the module to the begin of the list (gives it lowest priority).
+     And second foo:$ which permutes mod_foo with the end of the module list,
+     i.e. it "moves" the module to the end of the list (gives it highest
+     priority). [Ralf S. Engelschall]
+
   *) PORT: DSO/ELF support for FreeBSD 3.0.
      [Ralf S. Engelschall, Dirk Froemberg <ibex@physik.TU-Berlin.DE>]
   
Index: configure
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/configure,v
retrieving revision 1.48
diff -u -r1.48 configure
--- configure	1998/09/17 08:07:53	1.48
+++ configure	1998/10/22 13:58:01
@@ -75,6 +75,7 @@
 aux=src/helpers
 sedsubst=src/.apaci.sedsubst
 addconf=src/.apaci.addconf
+tplconf=src/.apaci.tplconf
 configstatus=config.status
 
 ##
@@ -203,6 +204,9 @@
 #   with adjustments
 confadjust=1
 
+#   module ordering
+permute=''
+
 #   determine rules
 rules=""
 rulelist=""
@@ -357,6 +361,7 @@
             shadowaux="src.$gnutriple/helpers"
             shadowsedsubst="src.$gnutriple/.apaci.sedsubst"
             shadowaddconf="src.$gnutriple/.apaci.addconf"
+            shadowtplconf="src.$gnutriple/.apaci.tplconf"
             #   (re)create shadow tree
             if [ .$quiet = .no ]; then
                 echo " + create shadow tree ($shadowsrc)"
@@ -372,6 +377,7 @@
             addconf=$shadowaddconf
             rm -f $addconf 2>/dev/null
             touch $addconf
+            tplconf=$shadowtplconf
             ;;
         --help | -h | -help )
             echo "Usage: configure [options]"
@@ -409,6 +415,7 @@
             echo " --activate-module=FILE on-the-fly activate existing third-party Module
source"
             echo " --enable-module=NAME   enable  a particular Module named 'NAME'"
             echo " --disable-module=NAME  disable a particular Module named 'NAME'"
+            echo " --permute-module=N1:N2 permute module 'N1' with module 'N2' in the configuration"
             $aux/ppl.sh $modulelist
             echo " --enable-shared=NAME   enable  build of Module named 'NAME' as a shared
object"
             echo " --disable-shared=NAME  disable build of Module named 'NAME' as a shared
object"
@@ -693,6 +700,29 @@
                     ;;
             esac
             ;;
+        --permute-module=*:*)
+            mod1=`echo $apc_optarg | sed -e 's/:.*//'`
+            mod2=`echo $apc_optarg | sed -e 's/.*://'`
+            for mod in $mod1 $mod2; do
+				case $mod in
+                    "^"|"\$") 
+                        ;;
+                    *)  eval "exists=\$module_${mod}" 
+                        if [ ".$exists" = . ]; then
+                            echo "configure:Error: No such module named '${mod}'" 1>&2
+                            exit 1
+                        fi
+                        ;;
+                esac
+            done
+            case $mod1:$mod2 in
+                ^:\$|*:^|\$:*)
+                    echo "configure:Error: Invalid combination of pseudo module identifiers"
1>&2
+                    exit 1
+                    ;;
+            esac
+            permute="${permute},${mod1}:${mod2}"
+            ;;
         --with-perl=*)
             PERL="$apc_optarg"
             ;;
@@ -1008,6 +1038,77 @@
     exit 1
 fi
 
+#   module permutation support
+if [ ".$permute" != . ]; then
+    sed -e '/## mod_mmap_static/,$d' <src/Configuration.tmpl >$tplconf
+    OIFS="$IFS" IFS='
+'
+    for line in `egrep '^[# ]*(Add|Shared)Module' src/Configuration.tmpl $addconf`; do
+        name=`echo "$line" |\
+              sed -e 's%^.*/\(.*\)$%\1%' \
+                  -e 's/\.[oa]$//' \
+                  -e 's/^mod_//' \
+                  -e 's/^lib//'`
+        echo "${name}::${line}"
+    done |\
+    awk '
+        BEGIN { 
+            FS="::";
+            n = 0; 
+        }
+        { 
+            mod_pos[$1]  = n; 
+            mod_list[n]  = $1; 
+            mod_line[$1] = $2;
+            n++; 
+        }
+        END {
+            pn = split(permute, perm, ",");
+            for (p = 1; p <= pn; p++) {
+                split(perm[p], mod, ":")
+                m1 = mod[1];
+                m2 = mod[2];
+                if (m1 == "^") {
+                    for (i = mod_pos[m2]-1; i >= 0; i--) {
+                        n1 = mod_list[i];
+                        n2 = mod_list[i+1];
+                        mod_list[i]   = n2;
+                        mod_list[i+1] = n1;
+                        mod_pos[n1]   = i+1;
+                        mod_pos[n2]   = i;
+                    }
+                }
+                else if (m2 == "$") {
+                    for (i = mod_pos[m1]; i < n-1; i++) {
+                        n1 = mod_list[i];
+                        n2 = mod_list[i+1];
+                        mod_list[i]   = n2;
+                        mod_list[i+1] = n1;
+                        mod_pos[n1]   = i+1;
+                        mod_pos[n2]   = i;
+                    }
+                }
+                else {
+                    p1 = mod_pos[m1];
+                    p2 = mod_pos[m2];
+                    n1 = mod_list[p1];
+                    n2 = mod_list[p2];
+                    mod_list[p1] = n2;
+                    mod_list[p2] = n1;
+                    mod_pos[m1] = p2;
+                    mod_pos[m2] = p1;
+                }
+            }
+            for (i = 0; i < n; i++) {
+                printf("%s\n", mod_line[mod_list[i]]);
+            }
+        }
+    ' "permute=$permute" >>$tplconf
+    IFS="$OIFS"
+else
+    cat $src/Configuration.tmpl $addconf >$tplconf
+fi
+
 #   generate module directives
 OIFS="$IFS" IFS=':'
 for module in $modules; do
@@ -1056,11 +1157,12 @@
 
 #   and finally translate the config template 
 #   according to our defined configuration
-eval "cat $src/Configuration.tmpl $addconf | $substcmd >$src/Configuration.apaci"
+eval "cat $tplconf | $substcmd >$src/Configuration.apaci"
 
 #   cleanup
 rm -f $sedsubst $sedsubst.[0-9] 2>/dev/null
 rm -f $addconf 2>/dev/null
+rm -f $tplconf 2>/dev/null
 
 ##
 ##  create all other Makefiles by running the proprietary 
Index: INSTALL
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/INSTALL,v
retrieving revision 1.44
diff -u -r1.44 INSTALL
--- INSTALL	1998/10/03 13:26:02	1.44
+++ INSTALL	1998/10/22 14:05:12
@@ -149,18 +149,19 @@
                                [--mandir=DIR]         [--disable-module=NAME] 
                                [--sysconfdir=DIR]     [--enable-shared=NAME]  
                                [--datadir=DIR]        [--disable-shared=NAME] 
-                               [--includedir=DIR]     
-                               [--localstatedir=DIR]  [--enable-suexec]     
-                               [--runtimedir=DIR]     [--suexec-caller=UID] 
-                               [--logfiledir=DIR]     [--suexec-userdir=DIR]
-                               [--proxycachedir=DIR]  [--suexec-uidmin=UID]
-                               [--compat]             [--suexec-gidmin=GID]
+                               [--includedir=DIR]     [--permute-module=N1:N2]
+                               [--localstatedir=DIR]  
+                               [--runtimedir=DIR]     [--enable-suexec]        
+                               [--logfiledir=DIR]     [--suexec-caller=UID]    
+                               [--proxycachedir=DIR]  [--suexec-userdir=DIR]   
+                               [--compat]             [--suexec-uidmin=UID]    
+                                                      [--suexec-gidmin=GID]    
                                                       [--suexec-safepath=PATH] 
+                                                                                
+                                                      [--with-perl=FILE]       
+                                                      [--without-support]      
+                                                      [--without-confadjust]   
 
-                                                      [--with-perl=FILE]   
-                                                      [--without-support]  
-                                                      [--without-confadjust]
-
      Use the CC, OPTIM, CFLAGS, INCLUDES, LDFLAGS, LIBS, CFLAGS_SHLIB,
      LD_SHLIB, LDFLAGS_SHLIB, LDFLAGS_SHLIB_EXPORT and RANLIB environment
      variables to override the corresponding default entries in the
@@ -339,6 +340,15 @@
                  --enable-shared for some modules on these platforms you also
                  have to enable the SHARED_CORE rule. For more details please
                  read the document `htdocs/manual/dso.html'.
+
+     Use the --permute-module=N1:N2 option to permutate the AddModule lines of
+     modules mod_N1 and mod_N2 in the Configuration file. This way one can
+     give modules different priorities.  Two special and important variants
+     are supported for the option argument: first ^:N which permutes module
+     mod_N with the start of the module list, i.e. it `moves' the module to
+     the begin of the list (gives it lowest priority).  And second N:$ which
+     permutes mod_N with the end of the module list, i.e. it `moves' the
+     module to the end of the list (gives it highest priority).
 
      Use the --with-perl=FILE option to select a particular Perl interpreter
      executable to be used with Apache. Per default APACI tries to find it

Mime
View raw message