You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Martin Pool <mb...@linuxcare.com.au> on 2000/03/11 13:28:12 UTC
lost error messages while detaching in 2.0a
(Excuse me if this rambles a bit)
Just after forking, Apache 2.0a1 does this in the parent:
open("/home/mbp/apache-2.0/logs/error_log", O_RDWR|O_APPEND|O_CREAT,
0777) = 4
dup2(4, 2) = 2
open("/home/mbp/apache-2.0/conf/mime.types", O_RDONLY) = 5
stat("/home/mbp/apache-2.0/conf/mime.types", {st_mode=S_IFREG|0755,
st_size=9957, ...}) = 0
brk(0x80d7000) = 0x80d7000
fstat(5, {st_mode=S_IFREG|0755, st_size=9957, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x40014000
read(5, "# This is a comment. I love comm"..., 4096) = 4096
read(5, "tion/vnd.lotus-1-2-3\napplication"..., 4096) = 4096
brk(0x80da000) = 0x80da000
read(5, "b\t\t\tpdb xyz\nimage/bmp\t\t\tbmp\nimag"..., 4096) = 1765
read(5, "", 4096) = 0
close(5) = 0
munmap(0x40014000, 4096) = 0
close(2) = 0
close(4) = 0
chdir("/") = 0
fork() = 18187
_exit(0) = ?
and this in the child:
~/apache-2.0$ ~/bin/lesspipe.sh /tmp/trace.18187
+ cat /tmp/trace.18187
getpid() = 18187
setsid() = 18187
close(0) = 0
open("/dev/null", O_RDONLY|O_LARGEFILE) = 0
close(1) = 0
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 1
getpid() = 18187
open("/home/mbp/apache-2.0/./conf/httpd.conf", O_RDONLY) = 2
stat("/home/mbp/apache-2.0/./conf/httpd.conf", {st_mode=S_IFREG|0644,
st_size=1687, ...}) = 0
fstat(2, {st_mode=S_IFREG|0644, st_size=1687, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x40014000
read(2, "# Ha, you\'re reading this config"..., 4096) = 1687
stat("/home/mbp/apache-2.0", {st_mode=S_IFDIR|0755, st_size=4096,
...}) = 0
stat("htdocs", 0xbfffd5ac) = -1 ENOENT (No such file or
directory)
write(2, "Syntax error on line 16 of /home"..., 67) = -1 EBADF (Bad
file descriptor)
write(2, "DocumentRoot must be a directory"..., 33) = -1 EBADF (Bad
file descriptor)
_exit(1) = ?
The net result is that error messages generated before opening the
error.log are lost, and it silently fails. This is a bit bad; it
would be better not to close stderr until we're immediately about to
freopen it pointing somewhere else. The comments say this is what we
want to do.
We had already opened the error log file and pointed stderr into it,
but we closed it again. FD 2 was later reused by the OS to read the
configuration file, but we thought it was stderr and tried to write
into it. Fifteen killed, twelve wounded.
The dup2 is presumably happening in ap_dupfile, called from
ap_open_logs. This is correct. However, ap_dupfile routine does an
ap_register_cleanup on the new file, so the file is closed off before
we fork. So, the child starts up with no stderr whatsoever.
What's a clean way to fix this? One way would be not to reopen stderr
until we've detached: that way, any errors in the very early startup
will go to the console where they'll be seen. Other alternatives are
that perhaps ap_dupfile should not automatically add a cleanup for the
file it created, or perhaps we shouldn't clean up the pool before
detaching, but both of those are a bit inconsistent. It's a
philosophical decision about cleaning up pools versus letting children
inherit fds, so I'll leave it to somebody more philosophical than
myself.
--
Martin Pool, (null), Linuxcare, Inc.
+61 2 6262 8990
mbp@linuxcare.com, http://www.linuxcare.com/
Linuxcare. Support for the revolution.