perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@ectoplasm.org>
Subject Re: [mp2] mod_perl closes apache's stdin and/or stdout
Date Tue, 09 Oct 2007 07:47:49 GMT
Dmitry Karasik wrote:
>> Does this test pass for you when you apply the patch in this thread?
>> http://marc.info/?l=apache-modperl&m=119072925228529&w=2
> 
> You mean my own patch? Yes, it does pass with the patch applied. 

Here is what I am testing with:

Index: ModPerl-Registry/t/stdin.t
===================================================================
--- ModPerl-Registry/t/stdin.t  (revision 0)
+++ ModPerl-Registry/t/stdin.t  (revision 0)
@@ -0,0 +1,26 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestRequest qw(POST);
+
+Apache::TestRequest::user_agent(keep_alive => 1);
+
+plan tests => 2, need [qw(CGI)],
+    need_min_module_version CGI => 3.08;
+
+{
+    my $url = "/stdin_override/mod_perl";
+    my $res = POST $url, [submit=>1];
+
+    ok t_cmp($res->content,
+             qr{submitted},
+             "form submission ok under mod_perl");
+
+    $url = "/stdin_override/cgi";
+    $res = POST $url, [submit=>1];
+    ok t_cmp($res->content,
+             qr{submitted},
+             "stdin reset, form submission ok under cgi");
+}
Index: ModPerl-Registry/t/conf/extra.conf.in
===================================================================
--- ModPerl-Registry/t/conf/extra.conf.in       (revision 583059)
+++ ModPerl-Registry/t/conf/extra.conf.in       (working copy)
@@ -183,6 +183,24 @@
     PerlResponseHandler ModPerl::Registry
 </Location>

+### test for mixed mod_perl/cgi environment ###
+<IfModule mod_alias.c>
+    Alias /stdin_override/mod_perl @ServerRoot@/cgi-bin/stdin.pl
+    Alias /stdin_override/cgi      @ServerRoot@/cgi-bin/stdin.pl
+</IfModule>
+
+<Location /stdin_override/mod_perl>
+    SetHandler perl-script
+    PerlResponseHandler ModPerl::Registry
+    PerlOptions +ParseHeaders
+    Options +ExecCGI
+</Location>
+
+<Location /stdin_override/cgi>
+    SetHandler cgi-script
+    Options +ExecCGI
+</Location>
+
 ### deflate tests ###
 <IfModule mod_alias.c>
     Alias /registry_bb_deflate/ @ServerRoot@/cgi-bin/
Index: ModPerl-Registry/t/cgi-bin/stdin.pl
===================================================================
--- ModPerl-Registry/t/cgi-bin/stdin.pl (revision 0)
+++ ModPerl-Registry/t/cgi-bin/stdin.pl (revision 0)
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use CGI qw/:standard/;
+
+print <<END;
+Content-type: text/plain
+
+END
+
+if (param()) {
+    my $submit = param('submit');
+    if ($submit) {
+        print "submitted";
+    }
+}


$> t/TEST -start-httpd -one-process
$> t/TEST -run-tests -verbose t/stdin.t
[...]
All tests successful.

That's without the IO patch, and I tried with :

Perl-5.8.8 (Redhat Fedora Core 7)
  httpd/2.2.2/worker
  httpd/2.2.2/prefork

I, for one, suspect there is some important variable we are not narrowing
down on here.

The IO patch itself, which avoids calling close() on the underlying FD, worries
me a little. Are we really fixing the problem, or just dodging it for this
particular case ?

With the patch, I see this test failing:
t/modperl/io_nested_with_cled_stds

I agree with the spirit of the patch. Avoiding the call to close() on
the underlying FD for STDIN makes sure nobody else calling open() could
accidentally grab it. (BTW, shouldn't the same fix be applied to STDOUT
as well?).

Looking at modperl_io_perlio_restore_stdin however, isn't this where the
real problem lies? It does restore Perl's stdin handle back to it's original
state, but I don't see where/how that code would guarantee STDIN to re-acquire
the same FD. Isn't that the bug ?

And avoiding the close() in the sugested patch would still need to undo
the override in modperl_io_perlio_restore_stdin() to allow the real, underlying
STDIN to be eventially closed, no ?

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/


Mime
View raw message