Peter Valdemar Mørch wrote:
Hi,

Dmitry Karasik dmitry-at-karasik.eu.org wrote:
mod_perl during the initialization process closes file descriptor 0,
and frees it for further reuse in other processes. Therefore, any cgi script executing after mod_perl is initialized, and in the same process tree, will have file descriptor 0 closed. The concrete example where this behavior leads to impossibility of processing POST requests is reported earlier and is located
at

  http://marc.info/?l=apache-modperl&m=119062450730646&w=2

Dmitry's patch from Sep 25, 2007 http://www.gossamer-threads.com/lists/modperl/modperl/94912 has still not been applied to SVN. May I humbly ask that this patch is applied?

I remember that Toersten and I put together a unit test for this but I don't think there was any change in behavior with this patch, so I'm not sure if anyone was able to demonstrate that it changed the behavior.

If you have the tuits and could track down that unit test, show that it exercises the problem in question, we probably wouldn't need much else to apply this patch. I'd try to do this but am overextended on my tuits right now.


On the dev list http://marc.info/?l=apache-modperl-dev&m=119125026607247&w=2 it seems that whether or not this really is a bug is drawn into question. I can confirm that it, really, really is a bug!

I'm now getting emails from others experiencing the same problem, querying for a solution. Dmitry's patch fixes our problem. I'm now forwarding links to the patch to other users. Wouldn't it be easier to have this or another patch applied or another that also fixes the problem???

The patch didn't apply completely cleanly here against HEAD, but this one does ( also at http://demo.capmon.dk/~pvm/modperl_io.patch ) :

~/mod_perl-2.0/src/modules/perl> svn diff
Index: modperl_io.c
===================================================================
--- modperl_io.c        (revision 604795)
+++ modperl_io.c        (working copy)
@@ -116,6 +116,7 @@
     /* if STDIN is open, dup it, to be restored at the end of response */
     if (handle && SvTYPE(handle) == SVt_PVGV &&
         IoTYPE(GvIO(handle)) != IoTYPE_CLOSED) {
+       IO * io = GvIO(handle);
         handle_save = gv_fetchpv(Perl_form(aTHX_
                                            "Apache2::RequestIO::_GEN_%ld",
                                            (long)PL_gensym++),
@@ -128,6 +129,17 @@
Perl_croak(aTHX_ "Failed to dup STDIN: %" SVf, get_sv("!", TRUE));
         }

+       /* In mixed environment of mod_perl and cgi scripts, cgi
+        * scripts may read content of POST requests off
+        * STDIN. do_close() calls actual close(0), freeing the
+        * descriptor 0 for reuse, and creating havoc for anyone
+        * reading from file descriptor 0.  This hack changes the IO
+        * type to IoTYPE_STD, because do_close() does not call
+        * underlying close() on IO handles of these types, but does
+        * free the associated resources. */
+        if ( IoIFP(io) && PerlIO_fileno(IoIFP(io)) == 0)
+           IoTYPE(io) = IoTYPE_STD;
+
         /* similar to PerlIO::scalar, the PerlIO::Apache layer doesn't
          * have file descriptors, so STDIN must be closed before it can
          * be reopened */

Thanks,

Peter

Reply via email to