perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Valdemar Mørch <>
Subject Re: [mp2] mod_perl closes apache's stdin and/or stdout
Date Mon, 17 Dec 2007 09:31:09 GMT

Dmitry Karasik 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

Dmitry's patch from  Sep 25, 2007 has still 
not been applied to SVN. May I humbly ask that this patch is applied?

On the dev list 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 ) :

~/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_
@@ -128,6 +129,17 @@
              Perl_croak(aTHX_ "Failed to dup STDIN: %" SVf, get_sv("!", 

+       /* 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 */


Peter Valdemar Mørch

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message