httpd-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 31565] New: - Won't start correctly if parent closed stdin, stdout and stderr
Date Wed, 06 Oct 2004 15:52:18 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31565>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31565

Won't start correctly if parent closed stdin, stdout and stderr

           Summary: Won't start correctly if parent closed stdin, stdout and
                    stderr
           Product: Apache httpd-2.0
           Version: 2.0.51
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: All
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: tchan@austin.rr.com


I have this test program which starts apache.  The result is the child processes
all die on an accept() call with errno 88 (ENOTSOCK).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

int main (int argc, char *argv[]) {
    int i;
    char *arg;

    if (argc < 2) {
        printf("Must specify the path to the executable\n");
        exit(1);
    }
    close(0);
    close(1);
    close(2);

    arg = malloc(strlen(argv[1]) + 1);
    strcpy(arg, argv[1]);
    for (i = 2; i < argc; i++) {
        arg = realloc(arg, strlen(arg) + strlen(argv[i]) + 2);
        strcat(arg, " ");
        strcat(arg, argv[i]);
    }
    syslog(LOG_ERR, "Calling system(%s)", arg);
    system(arg);
    exit(0);
}

If I comment out the close()'s (or open /dev/null in their place), the child
processes will have no problems.

I think the problem is with the order of these events:
First, apache processes the config file with a LISTEN directive, opens the
listen socket(s) and keeps the file descriptor(s) in its table.  With no stdin,
stdout, etc, the first listen socket will be fd 0 and so on.
Then later, apr_proc_detach() in srclib/apr/threadproc/unix/procsup.c does
freopen() on stdin, stdout and stderr which, regardless of whether fd 0, 1 and 2
are sockets or the std files, may wipe out listen sockets created earlier.
Later, when accept() is called on the first listen socket, it has already been
freopen() to a file, causing ENOTSOCK.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


Mime
View raw message