Apache Lounge


About Forum Index Downloads Search Register Log in  RSS Apache Lounge  

Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.



A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.

Post new topic   Forum Index -> News & Hangout View previous topic :: View next topic
Reply to topic   Topic: Apache 2.2.6 version working with mod_perl and mod_fcgid !!!

Joined: 15 Oct 2005
Posts: 2835
Location: Hilversum, NL, EU

PostPosted: Tue 25 Sep '07 21:06    Post subject: Apache 2.2.6 version working with mod_perl and mod_fcgid !!! Reply with quote

With the official version from ASF, modules like mod_perl and mod_fcgid are not working, it contains bugs. Thanks to Tom we can make a complete working version of 2.2.6 available at www.apachelounge.com/download .

This version works with mod_perl and mod_fcgid. No issues running with ActivePerl with official mod_perl from http://theoryx5.uwinnipeg.ca/ppms/ and mod_fcid 2.2 from Apache Lounge.

Back to top

Joined: 17 Dec 2005
Posts: 610
Location: Milford, MA, USA

PostPosted: Wed 26 Sep '07 2:50    Post subject: Reply with quote

For those interested in the details. If you are not interested in the Apache C code, the following will probably bore you to tears Wink

The actual code changes (as patch files) and a few notes are at http://www.tomdonovan.net/download/httpd226_cgi_patches.zip.
EDIT: this patch has been updated - see the following note

There were three parts of the problem, described in this earlier post.

Correcting change #1 was not terribly hard. It is possible to create new processes and do both: 1) avoid unwanted inherited handles and 2) pass INVALID_HANDLE_VALUE for any of stdin/stdout/stderr which are not passed to the new process. FastCGI programs need this.

Correcting problem #2 was done by guesswork. Debugging mod_perl.so showed that mod_perl tries to do this:
    * override stdin and stdout when mod_perl is called. (modules\perl\modperl_io.c line 107)

    * restore stdin and stdout when mod_perl returns to Apache. (modules\perl\modperl_io.c line 197)
The first problem was when mod_perl tried to Duplicate() (i.e. make another handle to) the stdin handle, this failed. This is odd because when the child process starts, stdin is a pipe between the Apache parent and child processes. If Apache Duplicate()s the stdin handle and closes the original one (near line 1100 in mpm_winnt.c) like it does for Win95, this fixes mod_perl's problem with stdin. I don't know why this is true.

The next problem was with stdout - but only when running from the command line. stdout is the DOS window when Apache is started at the command line. When running as a service it is a handle to "NUL" created by Apache (since there is no default stdout for a service). I tried creating a similar handle to "NUL" for stdout but this didn't satisfy mod_perl. I am mystified why it didn't, since mod_perl is happy when this is done by the Apache parent process running as a service. I tried a few other things - like setting it to "inheritable", or to "not-inheritable" or even to "not-closeable" - but nothing worked. Finally I tried making the Apache parent process pass its stderr (the error log) to the Apache child process as both stdout and stderr. Surprisingly, mod_perl was happy with this copy of stderr as stdout. I have no idea why this worked when the other (more reasonable) things that I tried to use for stdout didn't work. The Apache child process, and any created processes, should never write to stdout - but if they do, it will now go into the error log.

Alas, while everything works now - it just "happens to work", without a good explanation. If I can learn the reason it all works I'll post the patches and explanation to Apache bug 43329. If I give up - well, I guess I'll just post the patches and hope it helps the Apache/Perl guys figure it out.

If anyone else is inclined to debug mod_perl with Apache 2.2.6, and can shed some light on the odd behavior of stdin/stdout/stderr on Windows - please post your discoveries.


Last edited by tdonovan on Tue 02 Oct '07 14:09; edited 1 time in total
Back to top

Joined: 17 Dec 2005
Posts: 610
Location: Milford, MA, USA

PostPosted: Tue 02 Oct '07 14:03    Post subject: Reply with quote

I finally did figure it out. Here are the details.

mod_perl uses integer file descriptors instead of regular Windows file HANDLEs to refer to stdin and stdout.

Starting with Apache 2.2.6 - Apache closes the stdin HANDLE and replaces it with a HANDLE to "NUL".
This works OK for modules which use HANDLE functions for file access, but it leaves the stdin file descriptor unuseable. This prevents mod_perl from running.

I entered a new Apache bug 43534 for this problem and the FastCGI problem combined.

The previous patch I posted worked because it opened enough HANDLEs so that the original HANDLE number got re-used by Windows. This made the stdin file descriptor valid again, although it pointed to the wrong file. Since mod_perl just saves and restores stdin, it didn't matter that it was the wrong file - as long as the stdin file descriptor was associated with a valid HANDLE.

If you are running Apache 2.2.6 from the Downloads page, there is no need to update. It should run fine on Win2k, WinXP, and Win2k3.

Hopefully this patch or a similar one will make it into Apache 2.2.7, and FastCGI and mod_perl programs will work again on Windows with unaltered builds of Apache.

Back to top

Reply to topic   Topic: Apache 2.2.6 version working with mod_perl and mod_fcgid !!! View previous topic :: View next topic
Post new topic   Forum Index -> News & Hangout