Re: Problem with Perl sections in httpd.conf, mod_perl 1.26

2002-04-19 Thread Salvador Ortiz Garcia

On Fri, 2002-04-19 at 01:43, PinkFreud wrote:
 Here's a bit more information:
 
 Given two directives:
 $VirtualHost{$host}-{Alias} = [ '/perl/', $vhostdir/$dir/perl/ ];
 $VirtualHost{$host}-{Alias} = $vhost{config}-{Alias};
 
 The first works.  The second does not.  According to
 Apache::PerlSections-dump, %VirtualHost is *exactly* the same when
 using both directives - yet it seems the server ignores the Alias
 directive when it's assigned from $vhost{config} (either that, mod_perl
 fails to pass it to the server).
 Also, if I set a variable within httpd.conf to mimic $vhost{config} and
 then assign that to $VirtualHost{$host}, it works without a problem.
 The issuse is definitely with the variable being read in from an
 external file.
 
 Strange, no?

Yes, weird.

I'm hunting any remaining bugs related to Perl Sections.

Can you please test the attached patch vs 1.26? (please forget about the
patch posted by Michel, it is mine and in CVS now, but in this I'm
trying a more radical approach and checking for the proper nesting of
directives)

Then try to reproduce your problems under MOD_PERL_TRACE=ds (see the
DEBUGGIN section in the mod_perl man page), thats is, compile mod_perl
with PERL_TRACE=1 and run your Apache in single process mode:

  # MOD_PERL_TRACE=ds path_to_your/httpd -X

And please post the generated log.

Regards.

Salvador Ortiz


diff -ru mod_perl-1.26.orig/src/modules/perl/perl_config.c mod_perl-1.26.msg/src/modules/perl/perl_config.c
--- mod_perl-1.26.orig/src/modules/perl/perl_config.c	Tue Jul 10 20:47:15 2001
+++ mod_perl-1.26.msg/src/modules/perl/perl_config.c	Thu Feb 21 01:43:10 2002
 -51,6 +51,7 
 #include mod_perl.h
 
 extern API_VAR_EXPORT module *top_module;
+IV mp_cmdparms = 0;
 
 #ifdef PERL_SECTIONS
 static int perl_sections_self_boot = 0;
 -1166,6 +1167,9 
 char *tmpkey; 
 I32 tmpklen; 
 SV *tmpval;
+const command_rec *orec = cmd-cmd;
+const char *old_end_token = cmd-end_token;
+cmd-end_token = (const char *)cmd-info;
 (void)hv_iterinit(hv); 
 while ((tmpval = hv_iternextsv(hv, tmpkey, tmpklen))) { 
 	char line[MAX_STRING_LEN]; 
 -1173,6 +1177,13 
 	if (SvMAGICAL(tmpval)) mg_get(tmpval); /* tied hash FETCH */
 	if(SvROK(tmpval)) {
 	if(SvTYPE(SvRV(tmpval)) == SVt_PVAV) {
+		module *tmod = top_module;
+		const command_rec *c; 
+		if(!(c = find_command_in_modules((const char *)tmpkey, tmod))) {
+		fprintf(stderr, command_rec for directive `%s' not found!\n, tmpkey);
+		continue;
+		}
+		cmd-cmd = c; /* for do_quote */
 		perl_handle_command_av((AV*)SvRV(tmpval), 
    0, tmpkey, cmd, cfg);
 		continue;
 -1195,8 +1206,12 
 	if(errmsg)
 	log_printf(cmd-server, Perl: %s, errmsg);
 }
-/* Emulate the handling of end token for the section */ 
+cmd-cmd = orec;
+cmd-info = cmd-end_token;
+cmd-end_token = old_end_token;
+/* Emulate the handling of end token for the section  
 perl_set_config_vectors(cmd, cfg, core_module);
+*/
 } 
 
 #ifdef WIN32
 -1225,13 +1240,21 
 pool *p = cmd-pool;
 char *arg; 
 const char *errmsg = NULL;
+const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+if (err != NULL) {
+return err;
+}
+if (main_server-is_virtual) {
+	return VirtualHost doesn't nest!;
+}
+
 dSECiter_start
 
 if(entries) {
 	SECiter_list(perl_virtualhost_section(cmd, dummy, tab));
 }
 
-arg = pstrdup(cmd-pool, getword_conf (cmd-pool, key));
+arg = getword_conf (cmd-pool, key);
 
 #if MODULE_MAGIC_NUMBER = 19970912
 errmsg = init_virtual_host(p, arg, main_server, s);
 -1256,9 +1279,9 
 perl_section_hash_walk(cmd, s-lookup_defaults, tab);
 
 cmd-server = main_server;
+TRACE_SECTION_END(VirtualHost);
 
 dSECiter_stop
-TRACE_SECTION_END(VirtualHost);
 return NULL;
 }
 
 -1281,6 +1304,11 
 #ifdef PERL_TRACE
 char *sname = SECTION_NAME(Location);
 #endif
+const char *err = ap_check_cmd_context(cmd,
+	   NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+if (err != NULL) {
+return err;
+}
 
 dSECiter_start
 
 -1295,10 +1323,10 
 
 new_url_conf = create_per_dir_config (cmd-pool);
 
-cmd-path = pstrdup(cmd-pool, getword_conf (cmd-pool, key));
+cmd-path = getword_conf (cmd-pool, key);
 cmd-override = OR_ALL|ACCESS_CONF;
 
-if (cmd-info) { /* LocationMatch */
+if (cmd-cmd-cmd_data) { /* LocationMatch */
 	r = pregcomp(cmd-pool, cmd-path, REG_EXTENDED);
 }
 else if (!strcmp(cmd-path, ~)) {
 -1317,12 +1345,12 
 conf-r = r;
 
 add_per_url_conf (cmd-server, new_url_conf);
+TRACE_SECTION_END(sname);
 	
 dSECiter_stop
 
 cmd-path = old_path;
 cmd-override = old_overrides;
-TRACE_SECTION_END(sname);
 return NULL;
 }
 
 -1334,6 +1362,11 
 #ifdef PERL_TRACE
 char *sname = SECTION_NAME(Directory);
 #endif
+const char *err = ap_check_cmd_context(cmd,
+	   NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+if (err != NULL) {
+ 

Re: Perl Section Bug?

2002-02-13 Thread Salvador Ortiz Garcia

On Wed, 2002-02-13 at 13:44, David Wheeler wrote:
 On Fri, 2002-02-08 at 20:25, Salvador Ortiz Garcia wrote:
  Yes, It's a bug in Perl Sections. Confirmed in 1.26.
 
 snip /
 
  I'm digging into it.
 
 Thanks. I'm glad to know that I'm not imagining things. We've just found
 a place in Bricolage where the Location directive *does* work as
 expected. So you're right -- it's worse. Ugh.
 
 Thanks,
 
 David

Ok, I found it. Right now all Location, Directory and Files are afected
by being upgraded at random to the Match versions.

Can you please test the following patch for perl_config.c:

===
--- perl_config.c   Tue Jul 10 20:47:15 2001
+++ perl_config.c.new   Wed Feb 13 22:40:27 2002
@@ -1166,6 +1166,7 @@
 char *tmpkey; 
 I32 tmpklen; 
 SV *tmpval;
+void *old_info = cmd-info;
 (void)hv_iterinit(hv); 
 while ((tmpval = hv_iternextsv(hv, tmpkey, tmpklen))) { 
char line[MAX_STRING_LEN]; 
@@ -1195,6 +1196,7 @@
if(errmsg)
log_printf(cmd-server, Perl: %s, errmsg);
 }
+cmd-info = old_info;
 /* Emulate the handling of end token for the section */ 
 perl_set_config_vectors(cmd, cfg, core_module);
 } 
@@ -1511,9 +1513,7 @@
 void *dummy = perl_set_config_vectors(cmd, config, core_module);
 void *old_info = cmd-info;
 
-if (strstr(key, Match)) {
-   cmd-info = (void*)key;
-}
+cmd-info = (void*)strstr(key,Match);
 
 if(strnEQ(key, Location, 8))
perl_urlsection(cmd, dummy, hv);
===

Right now I'm working in a more radical patch to fix other minor
problems related to Perl sections handling.

Regards

Salvador Ortiz.





Re: Perl Section Bug?

2002-02-08 Thread Salvador Ortiz Garcia

Yes, It's a bug in Perl Sections. Confirmed in 1.26.

But it is worse.
 
With the following in httpd.conf try /info vs /status vs /status/info vs
/info/status, with and without the commented part, (if one section
fails, if two sections works)

Perl
  $Location{'/status'} = {
 SetHandler = 'server-status',
 Allow = 'from localhost'
  };
#/Perl
#Perl
  $Location{'/info'} = {
 SetHandler = 'server-info',
 Allow = 'from localhost'
 };
/Perl

I'm digging into it.

Regards,

Salvador Ortiz.

 
On Fri, 2002-02-01 at 20:56, David Wheeler wrote:
 Okay, let me try again.
 
 I have a simple module I've written that demonstrates the problem. here
 it is:
 
 package MyTest;
 our $VERSION = '0.1';
 use Apache;
 
 sub one {
 print STDERR One\n;
 print STDOUT One\n;
 return Apache::OK;
 }
 
 sub two {
 print STDERR Two\n;
 print STDOUT Two\n;
 return Apache::OK;
 }
 
 package Apache::ReadConfig;
 use strict;
 use warnings;
 
 our $NameVirtualHost = '*:80';
 
 our %VirtualHost = ('*:80' = {
 ServerName = '_default_',
 DocumentRoot = '/usr/local/apache/htdocs',
 Location = {
 '/one' = {
  SetHandler = 'perl-script',
  PerlHandler= 'MyTest::one'
  },
 '/two' = {
  SetHandler = 'perl-script',
  PerlHandler= 'MyTest::two'
  }
 }
 });
 
 
 Now, if I execute this from httpd.conf by simply calling
 
   PerlModule MyTest
 
 Here's what I get for my requests:
 
 URL Prints
 === ==
 http://myserver/one  One
 http://myserver/two  Two
 http://myserver/one/foo  One
 http://myserver/two/foo  Two
 http://myserver/one/two  One
 http://myserver/one/twofoo   One
 http://myserver/one/two/foo  One
 http://myserver/two/one  One
 http://myserver/two/onefoo   One
 http://myserver/two/one/foo  One
 
 It's the last three requests that are the problem. Because I'm hitting
 the '/two' location, I expect each of those examples to print Two. But
 because they each have one in the URL, they all print One!
 
 Why is this? It seems to be acting like LocationMatch directives rather
 than Location. Could this be a bug in how the Perl sections work? If
 not, how do I get that last request to print Two instead of One?
 Even if it *is* a bug, how do I get the proper behavior?
 
 TIA,
 
 David
 
 -- 
 David Wheeler AIM: dwTheory
 [EMAIL PROTECTED] ICQ: 15726394
Yahoo!: dew7e
Jabber: [EMAIL PROTECTED]