Stas Bekman wrote:
It looks like Jan's patch allows me to reproduce the problems that you see. So if that's true, we will be all set shortly. So don't waste your time on testing things I've asked to. I'll keep you posted. Thanks.

It's so much happier when things fail ;)


Here is what happening:

<VirtualHost _default_:8530>
 PerlOptions  +Parent
 <Perl>
    use Apache::ServerUtil;
    my $s = Apache->server;
    $s->add_config(['PerlModule Whatever']);
 </Perl>
</VirtualHost>

There are two contexts here. Base and vhost contexts. When <perl> section is entered the context switches to vhost perl. and (with my recent patch) everything is cool, untill we hit:

my $s = Apache->server;

which doesn't return the vhost server record, but the global server record! When we next call:

$s->add_config(['PerlModule Whatever']);

it switches context to the base server context, allocating things from it when 'PerlModule' is alled, causing the 'free' problem. If I do:

-        dTHXa(scfg->mip->parent->perl);
+        dTHXa(PERL_GET_CONTEXT);

which ignores $s and uses the context set by the <Perl> sections (vhost context) everything rolls.

This is most likely not the final solution, but my guess is that the following patch resolves all the short conf and the whole TestVhost::basic problems.

This patch includes both the workaround and the TestVhost::basic test.

Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.52
diff -u -u -r1.52 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c      19 Dec 2003 01:17:31 -0000      1.52
+++ src/modules/perl/modperl_cmd.c      22 Jan 2004 06:22:11 -0000
@@ -114,8 +114,13 @@

     if (modperl_is_running()) {
 #ifdef USE_ITHREADS
-        /* XXX: .htaccess support cannot use this perl with threaded MPMs */
-        dTHXa(scfg->mip->parent->perl);
+ /* XXX: .htaccess support cannot use this perl with threaded MPMs */
+        dTHXa(PERL_GET_CONTEXT);
+        /* dTHXa(scfg->mip->parent->perl); */
+        MP_TRACE_d(MP_FUNC,
+                   "using mip_perl=0x%lx, my_perl=0x%lx, PL_curinterp=0x%lx\n",
+                   (PerlInterpreter *)scfg->mip->parent->perl, aTHX,
+                   PERL_GET_CONTEXT);
 #endif
         MP_TRACE_d(MP_FUNC, "load PerlModule %s\n", arg);

@@ -373,6 +378,7 @@
 #ifdef USE_ITHREADS
     MP_dSCFG(s);
     pTHX;
+    PerlInterpreter *orig_perl;
 #endif

     if (!(arg && *arg)) {
@@ -388,7 +394,9 @@

 #ifdef USE_ITHREADS
     /* XXX: .htaccess support cannot use this perl with threaded MPMs */
+    orig_perl = PERL_GET_CONTEXT;
     aTHX = scfg->mip->parent->perl;
+    PERL_SET_CONTEXT(aTHX);
 #endif

     /* data will be set by a <Perl> section */
@@ -478,6 +486,11 @@
                              handler->name, status);
         }
     }
+
+#ifdef USE_ITHREADS
+    /* restore the original perl context */
+    PERL_SET_CONTEXT(orig_perl);
+#endif

     return NULL;
 }

--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ t/htdocs/vhost/startup.pl   2004-01-21 15:44:34.000000000 -0800
@@ -0,0 +1,32 @@
+use warnings;
+use strict;
+
+use Apache2;
+use Apache::ServerUtil ();
+use Apache::Server ();
+
+use File::Spec::Functions qw(catdir);
+
+# base server
+my $s = Apache->server;
+
+my $vhost_doc_root = catdir Apache::Server::server_root, qw(htdocs vhost);
+
+# testing $s->add_config() in vhost
+my $conf = <<"EOC";
+# must use PerlModule here to check for segfaults
+# (even though it's not required)
+PerlModule TestVhost::basic
+PerlSetVar DocumentRootCheck $vhost_doc_root
+<Location /TestVhost__basic>
+    SetHandler modperl
+    PerlResponseHandler TestVhost::basic
+</Location>
+EOC
+
+$s->add_config([split /\n/, $conf]);
+
+# this used to have problems on win32
+$s->add_config(['<Perl >', '1;', '</Perl>']);
+
+1;

--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ t/response/TestVhost/basic.pm       2004-01-21 21:29:51.000000000 -0800
@@ -0,0 +1,59 @@
+package TestVhost::basic;
+
+# Test whether vhost with 'PerlOptions +Parent', which doesn't inherit
+# from the base, has its own INC and therefore can have a modules with
+# the same namespace as the base, but different content.
+#
+# Also see the parallel TestDirective::perlmodule handler
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+
+use Apache::RequestUtil ();
+use APR::Table ();
+
+use File::Spec::Functions qw(catdir);
+
+use Apache::Const -compile => 'OK';
+
+sub handler {
+    my $r = shift;
+
+    plan $r, tests => 1;
+
+    {
+        my $expected = $r->document_root;
+        my $received = $r->dir_config->get('DocumentRootCheck');
+        ok t_cmp($expected, $received, "DocumentRoot");
+    }
+
+    Apache::OK;
+}
+
+1;
+__END__
+<NoAutoConfig>
+<VirtualHost TestVhost::basic>
+    DocumentRoot @documentroot@/vhost
+
+    <IfDefine PERL_USEITHREADS>
+        # a new interpreter pool
+        PerlOptions +Parent
+    </IfDefine>
+
+    # use test system's @INC
+    PerlSwitches [EMAIL PROTECTED]@
+
+    # mp2 modules
+    PerlRequire "@serverroot@/conf/modperl_inc.pl"
+
+    # private to this vhost stuff
+    PerlRequire "@documentroot@/vhost/startup.pl"
+
+    # <Location /TestVhost__basic> container is added via add_config
+    # in t/htdocs/vhost/startup.pl
+</VirtualHost>
+</NoAutoConfig>

--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ t/vhost/basic.t     2004-01-21 15:51:20.000000000 -0800
@@ -0,0 +1,33 @@
+# the handler is configured in modperl_extra.pl via
+# Apache->server->add_config
+
+use Apache::TestUtil;
+use Apache::TestRequest 'GET';
+
+my $config = Apache::Test::config();
+my $vars = $config->{vars};
+
+my $module = 'TestVhost::basic';
+my $path = Apache::TestRequest::module2path($module);
+
+Apache::TestRequest::module($module);
+my $hostport = Apache::TestRequest::hostport($config);
+
+t_debug("connecting to $hostport");
+my $res = GET "http://$hostport/$path";;
+
+if ($res->is_success) {
+    print $res->content;
+}
+else {
+    if ($res->code == 404) {
+        my $docroot = $vars->{documentroot};
+        die "this test gets its <Location> configuration added via " .
+            "$documentroot/vhost/startup.pl, this could be the cause " .
+            "of the failure";
+    }
+    else {
+        die "server side has failed (response code: ", $res->code, "),\n",
+            "see t/logs/error_log for more details\n";
+    }
+}


__________________________________________________________________ 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]



Reply via email to