Bug #1160
closedSTDERR left open when daemonizing
Description
Lighttpd leaves STDERR open when it goes into the background.
I have a script A which calls:
"system('/usr/sbin/lighttpd -f lighttpd.conf 2>&1');"
This works fine but script A is called by script B:
"system('A');"
There is some setuiding going on.
Script B always hangs with a zombie child, until I kill the lighttpd process started by script A. This worked fine with apache. So I added:
"close(STDERR_FILENO);"
to daemonize() in server.c just before the first fork. This stops my problem from happening. I don't have a clue why script B blocks but script A doesn't.
I've never written a daemon before, but the Unix Programming FAQ says step 6 of going into the background is:
`close()' fds 0, 1, and 2. This releases the standard in, out, and
error we inherited from our parent process. We have no way of knowing
where these fds might have been redirected to. Note that many daemons
use `sysconf()' to determine the limit `_SC_OPEN_MAX'. `_SC_OPEN_MAX'
tells you the maximun open files/process. Then in a loop, the daemon
can close all possible file descriptors. You have to decide if you
need to do this or not. If you think that there might be
file-descriptors open you should close them, since there's a limit on
number of concurrent file descriptors.
My one line fix may cause problems if stderr is written to later on. Probably should be redirected to /dev/null like stdin and stdout.
-- richard
Updated by Anonymous over 17 years ago
I now see that STDERR is closed in log_error_open() from log.c if a logfile is specified in the config file. But this is called after daemonizing.
Working through the ramifications of this...
-- richard
Updated by Anonymous over 17 years ago
OK. Script B was in fact calling script A like this:
system('A 2>&1');
if instead B does:
system('A');
And A does:
system('/usr/sbin/lighttpd -f lighttpd.conf 2>&1');
And lighttpd.conf has:
server.errorlog='logfile'
Everything behaves, I don't get any zombies, B doesn't hang until lighttpd closes. I don't know why, but I am pleased it works. Case closed.
-- richard
Updated by jan over 17 years ago
- Status changed from New to Fixed
- Resolution set to invalid
closed by reporter.
Also available in: Atom