hi all
ok, I spent some time and was able to get configuration-based dynamic hook ordering working.
the attached patch adds a PerlHook*Handler directive for each request phase (minus the PerlResponseHandler). so, you would have a configuration like this
PerlHookTransHandler Last
valid values correspond to APR_HOOK* values: ReallyFirst, First, Middle, Last, ReallyLast.
the directives (and effects) are global, so they are not allowed in vhosts - you get one shot, just like you did with ClearModuleList/AddModule in 1.3.
two things of note:
1 - I really need someone on Win32 to give this a whirl. there's some code in there (swiped from mod_info) that is Win32 specific so it needs to be excercised. running both the mod_perl test suite as well as the attached tests would be greatly appreciated.
2 - on a parallel with this specific feature, I noticed that mod_perl hooks PerlOptions +GlobalRequest logic in post-read-request and header-parser phases, via RUN_FIRST. since we moved user-defined PerlInitHandler logic to RUN_REALLY_FIRST, its possible that user-defined Perl handlers will run _before_ mod_perl gets the chance to insert its global logic. I'm not sure if this is a bad thing, but it sounds bad. so, I created a MODPERL_HOOK_REALLY_FIRST define (-20) to put the +GlobalRequest logic really, really first for those two phases. please review.
very nice work, geoff! see some comments below.
Index: src/modules/perl/mod_perl.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/mod_perl.h,v
retrieving revision 1.61
diff -u -r1.61 mod_perl.h
--- src/modules/perl/mod_perl.h 22 Sep 2003 17:43:41 -0000 1.61
+++ src/modules/perl/mod_perl.h 27 Feb 2004 16:33:23 -0000
@@ -108,4 +108,7 @@
const char *,
const char *);
+/* we need to hook a few internal things before APR_HOOK_REALLY_FIRST */
+#define MODPERL_HOOK_REALLY_FIRST (-20)
The name is confusing, since APR_REALLY_FIRST is -10 and you kept the rest of the MODPERL_HOOK_ names matching . Call it REALLY_REALLY_FIRST? or anything else which is not _REALLY_FIRST?
#endif /* MOD_PERL_H */
Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.57
diff -u -r1.57 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c 14 Feb 2004 04:25:01 -0000 1.57
+++ src/modules/perl/modperl_cmd.c 27 Feb 2004 16:33:23 -0000
@@ -142,6 +142,62 @@
return NULL;
}
+MP_CMD_SRV_DECLARE(order)
please s/order/hook_order/ or similar, order on its own is too vague of a name.
Index: src/modules/perl/modperl_config.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_config.c,v
retrieving revision 1.76
diff -u -r1.76 modperl_config.c
--- src/modules/perl/modperl_config.c 14 Feb 2004 01:38:05 -0000 1.76
+++ src/modules/perl/modperl_config.c 27 Feb 2004 16:33:23 -0000
@@ -179,6 +179,9 @@
scfg->gtop = modperl_gtop_new(p);
#endif + /* no merge required - applies to the main server only */
+ scfg->hook_order = apr_table_make(p, 2);
I think it's a waste. If it's used only by the main server and relevant only at the startup, just use some static variable and don't blow the size of scfg for vhosts.
/* must copy ap_server_argv0, because otherwise any read/write of
* $0 corrupts process' argv[0] (visible with 'ps -ef' on most
* unices). This is due to the logic of calculating PL_origalen in
Index: src/modules/perl/modperl_types.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_types.h,v
retrieving revision 1.73
diff -u -r1.73 modperl_types.h
--- src/modules/perl/modperl_types.h 12 Feb 2004 02:05:28 -0000 1.73
+++ src/modules/perl/modperl_types.h 27 Feb 2004 16:33:23 -0000
@@ -137,6 +137,7 @@
modperl_options_t *flags;
apr_hash_t *modules;
server_rec *server;
+ MpHV *hook_order;
} modperl_config_srv_t;
see above.
typedef struct {
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.62
diff -u -r1.62 modperl_util.c
--- src/modules/perl/modperl_util.c 12 Feb 2004 02:05:28 -0000 1.62
+++ src/modules/perl/modperl_util.c 27 Feb 2004 16:33:23 -0000
@@ -843,3 +843,103 @@
/* copy the SV in case the pool goes out of scope before the perl scalar */
return newSVpv(ap_server_root_relative(p, fname), 0);
}
+
+/* from here down is support for dynamic hook ordering. this is mostly
+ * stolen from mod_info.c, so see also the logic and descriptions there.
+ */
That's a bad idea to point to description in another module. What happens if it gets nuked/rewritten and it won't match the code below any longer. Just copy it over while it's correct.
The whole sorting code doesn't belong to modperl_util.c, IMHO. It's a one-time use code and should be static in where it is used, i.e. mod_perl.c
And finally, if there are already two modules who need to copy so much cruft to resort hooks, perhaps it should become an Apache API, so that you don't have to worry about win32 users and what not. This stuff is really not urgent to put in, IMHO. So if it gets added in 2.0.49 that's still cool with us, no?
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
