Author: stas
Date: Tue May 10 19:17:16 2005
New Revision: 169560

URL: http://svn.apache.org/viewcvs?rev=169560&view=rev
Log:
introduce ModPerl::RegistryPrefork and ModPerl::PerlRunPrefork, which
behave the same as ModPerl::Registry and ModPerl::PerlRun,
respectively, but chdir to the script's directory like mod_cgi
does. These two new handlers will refuse to load under threaded MPMs
where chdir can't be used as it will affect all running threads
+ tests

Added:
    perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm   (with 
props)
    perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm   (with 
props)
    perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl   (with props)
    perl/modperl/trunk/ModPerl-Registry/t/prefork.t   (with props)
Modified:
    perl/modperl/trunk/Changes
    perl/modperl/trunk/ModPerl-Registry/t/conf/extra.conf.in

Modified: perl/modperl/trunk/Changes
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/Changes?rev=169560&r1=169559&r2=169560&view=diff
==============================================================================
--- perl/modperl/trunk/Changes (original)
+++ perl/modperl/trunk/Changes Tue May 10 19:17:16 2005
@@ -12,6 +12,12 @@
 
 =item 1.999_24-dev
 
+introduce ModPerl::RegistryPrefork and ModPerl::PerlRunPrefork, which
+behave the same as ModPerl::Registry and ModPerl::PerlRun,
+respectively, but chdir to the script's directory like mod_cgi
+does. These two new handlers will refuse to load under threaded MPMs
+where chdir can't be used as it will affect all running threads [Stas]
+
 ModPerl::RegistryCooker::chdir_file_normal() now chdirs to the current
 script's directory or the specified directory as an argument, as it
 was planned in first place. Therefore switch ModPerl::Registry and

Added: perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm?rev=169560&view=auto
==============================================================================
--- perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm (added)
+++ perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm Tue May 
10 19:17:16 2005
@@ -0,0 +1,24 @@
+package ModPerl::PerlRunPrefork;
+
+use strict;
+use warnings FATAL => 'all';
+
+our $VERSION = '0.01';
+
+use base qw(ModPerl::PerlRun);
+
+use Apache2::MPM ();
+
+die "This package can't be used under threaded MPMs"
+    if Apache2::MPM->is_threaded;
+
+sub handler : method {
+    my $class = (@_ >= 2) ? shift : __PACKAGE__;
+    my $r = shift;
+    return $class->new($r)->default_handler();
+}
+
+*chdir_file = \&ModPerl::RegistryCooker::chdir_file_normal;
+
+1;
+__END__

Propchange: perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/PerlRunPrefork.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm?rev=169560&view=auto
==============================================================================
--- perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm (added)
+++ perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm Tue May 
10 19:17:16 2005
@@ -0,0 +1,24 @@
+package ModPerl::RegistryPrefork;
+
+use strict;
+use warnings FATAL => 'all';
+
+our $VERSION = '0.01';
+
+use base qw(ModPerl::Registry);
+
+use Apache2::MPM ();
+
+die "This package can't be used under threaded MPMs"
+    if Apache2::MPM->is_threaded;
+
+sub handler : method {
+    my $class = (@_ >= 2) ? shift : __PACKAGE__;
+    my $r = shift;
+    return $class->new($r)->default_handler();
+}
+
+*chdir_file = \&ModPerl::RegistryCooker::chdir_file_normal;
+
+1;
+__END__

Propchange: perl/modperl/trunk/ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl?rev=169560&view=auto
==============================================================================
--- perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl (added)
+++ perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl Tue May 10 
19:17:16 2005
@@ -0,0 +1,19 @@
+#!perl -w
+
+# test that prefork runs from the directory the script lives in
+
+# All Modperl::*Prefork modules must chdir into the current dir, so we
+# should be able to read ourselves via a relative path
+
+print "Content-type: text/plain\n\n";
+
+my $script = "prefork.pl";
+if (open my $fh, $script) {
+    print "ok $script";
+}
+else {
+    print "prefork didn't chdir into the scripts directory?";
+    print " The error was: $!";
+}
+
+

Propchange: perl/modperl/trunk/ModPerl-Registry/t/cgi-bin/prefork.pl
------------------------------------------------------------------------------
    svn:executable = *

Modified: perl/modperl/trunk/ModPerl-Registry/t/conf/extra.conf.in
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/ModPerl-Registry/t/conf/extra.conf.in?rev=169560&r1=169559&r2=169560&view=diff
==============================================================================
--- perl/modperl/trunk/ModPerl-Registry/t/conf/extra.conf.in (original)
+++ perl/modperl/trunk/ModPerl-Registry/t/conf/extra.conf.in Tue May 10 
19:17:16 2005
@@ -38,7 +38,9 @@
 Alias /registry/         @ServerRoot@/cgi-bin/
 Alias /registry_bb/      @ServerRoot@/cgi-bin/
 Alias /registry_oo_conf/ @ServerRoot@/cgi-bin/
+Alias /registry_prefork/ @ServerRoot@/cgi-bin/
 Alias /perlrun/          @ServerRoot@/cgi-bin/
+Alias /perlrun_prefork/  @ServerRoot@/cgi-bin/
 Alias /nph/              @ServerRoot@/cgi-bin/
 Alias /registry_modperl_handler/  @ServerRoot@/cgi-bin/
 
@@ -79,6 +81,24 @@
     SetHandler perl-script
     Options +ExecCGI
     PerlResponseHandler ModPerl::Registry
+</Location>
+
+# don't preload ModPerl::RegistryPrefork as it won't load under
+# threaded MPMs
+<Location /registry_prefork>
+    SetHandler perl-script
+    Options +ExecCGI
+    PerlResponseHandler ModPerl::RegistryPrefork
+    PerlOptions +ParseHeaders
+</Location>
+
+# don't preload ModPerl::PerlRunPrefork as it won't load under
+# threaded MPMs
+<Location /perlrun_prefork>
+    SetHandler perl-script
+    Options +ExecCGI
+    PerlResponseHandler ModPerl::PerlRunPrefork
+    PerlOptions +ParseHeaders
 </Location>
 
 PerlModule ModPerl::PerlRun

Added: perl/modperl/trunk/ModPerl-Registry/t/prefork.t
URL: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/ModPerl-Registry/t/prefork.t?rev=169560&view=auto
==============================================================================
--- perl/modperl/trunk/ModPerl-Registry/t/prefork.t (added)
+++ perl/modperl/trunk/ModPerl-Registry/t/prefork.t Tue May 10 19:17:16 2005
@@ -0,0 +1,47 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestRequest;
+use Apache::TestConfig ();
+
+use Apache2::Build ();
+
+my $mpm_is_threaded = Apache2::Build->build_config->mpm_is_threaded();
+
+my %modules = (
+    registry         => 'ModPerl::Registry',
+    perlrun          => 'ModPerl::PerlRun',
+    registry_prefork => 'ModPerl::RegistryPrefork',
+    perlrun_prefork  => 'ModPerl::PerlRunPrefork',
+);
+
+my @aliases = sort keys %modules;
+
+plan tests => [EMAIL PROTECTED], need {
+    "can't run under threaded MPMs" => !$mpm_is_threaded };
+
+my $script = "prefork.pl";
+
+# very basic compilation/response test
+for my $alias (qw(registry_prefork perlrun_prefork)) {
+    my $url = "/$alias/$script";
+
+    #t_debug "$url";
+    ok t_cmp GET_BODY($url), "ok $script", "$modules{$alias} test";
+}
+
+# the order is important, we also want to check that prefork specific
+# modules didn't affect the cwd of other modules
+
+# the normal handlers should not find the script in the cwd, as they
+# don't chdir to its directory before running the script
+for my $alias (qw(registry perlrun)) {
+    my $url = "/$alias/$script";
+
+    #t_debug "$url";
+    ok t_cmp GET_BODY($url), 
+        qr/prefork didn't chdir into the scripts directory/,
+            "$modules{$alias} test";
+}

Propchange: perl/modperl/trunk/ModPerl-Registry/t/prefork.t
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to