1. Problem Description: Hiya,
After querying a mod_perl run CGI, the corresponding apache2 process ends up having its fd 0 and/or fd 1 closed. This then causes some other CGIs (for instance mod_python's viewvc) to fail because they are not robust enough to cope with a closed fd 0. Stracing the apache2 process, here is what I observe: [...] 4760 dup(0) = 17 4760 ioctl(17, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94938) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(17, 0, [0], SEEK_CUR) = 0 4760 fstat64(17, {st_dev=makedev(0, 14), st_ino=1673, st_mode=S_IFCHR|0666, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_rdev=makedev(1, 3), st_atime=2007/02/20-09:50:23, st_mtime=2007/02/20-09:50:23, st_ctime=2007/02/20-09:50:23}) = 0 4760 fcntl64(17, F_SETFD, FD_CLOEXEC) = 0 4760 close(0) = 0 4760 dup(1) = 0 4760 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94938) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(0, 0, [0], SEEK_CUR) = 0 4760 fstat64(0, {st_dev=makedev(0, 14), st_ino=1673, st_mode=S_IFCHR|0666, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_rdev=makedev(1, 3), st_atime=2007/02/20-09:50:23, st_mtime=2007/02/20-09:50:23, st_ctime=2007/02/20-09:50:23}) = 0 4760 fcntl64(0, F_SETFD, 0) = 0 4760 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94918) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(0, 0, [0], SEEK_CUR) = 0 4760 close(1) = 0 [...] And in the end: [...] 4760 close(18) = 0 4760 close(1) = 0 4760 chdir("/etc/apache2") = 0 4760 dup(17) = 1 4760 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94938) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(1, 0, [0], SEEK_CUR) = 0 4760 fstat64(1, {st_dev=makedev(0, 14), st_ino=1673, st_mode=S_IFCHR|0666, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_rdev=makedev(1, 3), st_atime=2007/02/20-09:50:23, st_mtime=2007/02/20-09:50:23, st_ctime=2007/02/20-09:50:23}) = 0 4760 fcntl64(1, F_SETFD, 0) = 0 4760 close(17) = 0 4760 dup(0) = 17 4760 ioctl(17, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94938) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(17, 0, [0], SEEK_CUR) = 0 4760 fstat64(17, {st_dev=makedev(0, 14), st_ino=1673, st_mode=S_IFCHR|0666, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=0, st_rdev=makedev(1, 3), st_atime=2007/02/20-09:50:23, st_mtime=2007/02/20-09:50:23, st_ctime=2007/02/20-09:50:23}) = 0 4760 fcntl64(17, F_SETFD, FD_CLOEXEC) = 0 4760 ioctl(17, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa94918) = -1 ENOTTY (Inappropriate ioctl for device) 4760 _llseek(17, 0, [0], SEEK_CUR) = 0 4760 close(0) = 0 4760 writev(16, [{"10\r\n", 4}, {"\n</body>\n</html>", 16}, {"\r\n", 2}, {"0\r\n\r\n", 5}], 4) = 27 4760 read(16, 0x84a69c0, 8000) = -1 EAGAIN (Resource temporarily unavailable) 4760 write(9, "10.95.129.198 - - [28/Mar/2007:1"..., 2220) = 2220 4760 poll( <unfinished ...> As you can see mod_perl saves the fd 0 with a dup, and then closes it. It does the same for fd 1 but as 0 is now an available fd, fd 1 ends up being dupped to fd 0. Things are then messed up when mod_perl restores the fds in the end. This is using debian's unstable apache 2.2.3, using the prefork MPM. I get the same behavior with either of the debian mod_perl package (2.0.2) or 2.0.3 or a checkout (a few minutes ago) from the svn repository. 2. Used Components and their Configuration: *** mod_perl version 2.000004 *** using /usr/local/lib/perl/5.8.8/Apache2/BuildConfig.pm *** Makefile.PL options: MP_APR_LIB => aprext MP_APXS => /usr/bin/apxs MP_COMPAT_1X => 1 MP_GENERATE_XS => 1 MP_LIBNAME => mod_perl MP_USE_DSO => 1 *** The httpd binary was not found $ apache2ctl -V Server version: Apache/2.2.3 Server built: Feb 5 2007 02:13:07 Server's Module Magic Number: 20051115:3 Server loaded: APR 1.2.7, APR-Util 1.2.7 Compiled using: APR 1.2.7, APR-Util 1.2.7 Architecture: 32-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="" -D SUEXEC_BIN="/usr/lib/apache2/suexec" -D DEFAULT_PIDLOG="/var/run/apache2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types" -D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf" *** (apr|apu)-config linking info -L/usr/lib -laprutil-1 -L/usr/lib -lapr-1 -luuid -lrt -lcrypt -lpthread -ldl *** /usr/bin/perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.18.3, archname=i486-linux-gnu-thread-multi uname='linux saens 2.6.18.3 #1 smp sat nov 25 13:39:52 est 2006 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.1.2 20061115 (prerelease) (Debian 4.1.1-20)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=/lib/libc-2.3.6.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8 gnulibc_version='2.3.6' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Built under linux Compiled at Dec 6 2006 23:05:53 %ENV: PERL5LIB="/home/stephane/lib/perl" PERL_LWP_USE_HTTP_10="1" @INC: /home/stephane/lib/perl /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . *** Packages of interest status: Apache2 : - Apache2::Request : - CGI : 3.15 ExtUtils::MakeMaker: 6.30_01 LWP : 5.805 mod_perl : - mod_perl2 : 2.000004 $ svn info Path: . URL: https://svn.apache.org/repos/asf/perl/modperl/trunk Repository Root: https://svn.apache.org/repos/asf Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68 Revision: 523256 Node Kind: directory Schedule: normal Last Changed Author: geoff Last Changed Rev: 522508 Last Changed Date: 2007-03-26 14:04:00 +0100 (Mon, 26 Mar 2007) Best regards, Stephane