Index: server/mpm/winnt/nt_eventlog.c =================================================================== --- server/mpm/winnt/nt_eventlog.c (revision 579787) +++ server/mpm/winnt/nt_eventlog.c (working copy) @@ -21,6 +21,7 @@ #include "mpm_winnt.h" #include "apr_strings.h" #include "apr_lib.h" +#include "apr_portable.h" #include "ap_regkey.h" static char *display_name = NULL; @@ -138,7 +139,8 @@ HANDLE hPipeWrite = NULL; HANDLE hDup = NULL; DWORD threadid; - int fd; + apr_file_t *eventlog_file; + apr_file_t *stderr_file; display_name = argv0; @@ -159,28 +161,12 @@ WaitForSingleObject(stderr_ready, INFINITE); - /* Flush stderr and unset its buffer, then commit and replace stderr. - * This is typically a noop for Win2K/XP since services with NULL std - * handles [but valid FILE *'s, oddly enough], but is required - * for NT 4.0 and to use this code outside of services. - */ - fflush(stderr); - setvbuf(stderr, NULL, _IONBF, 0); - _commit(2 /* stderr */); - fd = _open_osfhandle((long) hPipeWrite, - _O_WRONLY | _O_BINARY); - _dup2(fd, 2); - _close(fd); - _setmode(2, _O_BINARY); + if ((apr_file_open_stderr(&stderr_file, p) + == APR_SUCCESS) + && (apr_os_file_put(&eventlog_file, &hPipeWrite, APR_WRITE, p) + == APR_SUCCESS)) + apr_file_dup2(stderr_file, eventlog_file, p); - /* hPipeWrite was _close()'ed above, and _dup2()'ed - * to fd 2 creating a new, inherited Win32 handle. - * Recover that real handle from fd 2. - */ - hPipeWrite = (HANDLE)_get_osfhandle(2); - - SetStdHandle(STD_ERROR_HANDLE, hPipeWrite); - /* The code above _will_ corrupt the StdHandle... * and we must do so anyways. We set this up only * after we initialized the posix stderr API. Index: server/mpm/winnt/mpm_winnt.c =================================================================== --- server/mpm/winnt/mpm_winnt.c (revision 579787) +++ server/mpm/winnt/mpm_winnt.c (working copy) @@ -1034,7 +1034,7 @@ pid = getenv("AP_PARENT_PID"); if (pid) { - HANDLE filehand, newhand; + HANDLE filehand; HANDLE hproc = GetCurrentProcess(); /* This is the child */ @@ -1047,17 +1047,12 @@ /* The parent gave us stdin, we need to remember this * handle, and no longer inherit it at our children * (we can't slurp it up now, we just aren't ready yet). + * The original handle is closed below, at apr_file_dup2() */ pipe = GetStdHandle(STD_INPUT_HANDLE); - - if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) { - /* This doesn't work for 9x, but it's cleaner. */ - SetHandleInformation(pipe, HANDLE_FLAG_INHERIT, 0); - } - else if (DuplicateHandle(hproc, pipe, - hproc, &filehand, 0, FALSE, - DUPLICATE_SAME_ACCESS)) { - CloseHandle(pipe); + if (DuplicateHandle(hproc, pipe, + hproc, &filehand, 0, FALSE, + DUPLICATE_SAME_ACCESS)) { pipe = filehand; } @@ -1067,13 +1062,18 @@ * Don't infect child processes with our stdin * handle, use another handle to NUL! */ - if ((filehand = GetStdHandle(STD_OUTPUT_HANDLE)) - && DuplicateHandle(hproc, filehand, - hproc, &newhand, 0, - TRUE, DUPLICATE_SAME_ACCESS)) { - SetStdHandle(STD_INPUT_HANDLE, newhand); + { + apr_file_t *infile, *outfile; + if ((apr_file_open_stdout(&outfile, process->pool) == APR_SUCCESS) + && (apr_file_open_stdin(&infile, process->pool) == APR_SUCCESS)) + apr_file_dup2(infile, outfile, process->pool); } + /* This child needs the existing stderr opened for logging, + * already + */ + + /* The parent is responsible for providing the * COMPLETE ARGUMENTS REQUIRED to the child. * @@ -1239,19 +1239,10 @@ if ((rv = apr_file_open(&nullfile, "NUL", APR_READ | APR_WRITE, APR_OS_DEFAULT, process->pool)) == APR_SUCCESS) { - HANDLE hproc = GetCurrentProcess(); - HANDLE nullstdout = NULL; - HANDLE nullhandle; - - /* Duplicate the handle to be inherited by children */ - if ((apr_os_file_get(&nullhandle, nullfile) == APR_SUCCESS) - && DuplicateHandle(hproc, nullhandle, - hproc, &nullstdout, - 0, TRUE, DUPLICATE_SAME_ACCESS)) { - SetStdHandle(STD_OUTPUT_HANDLE, nullstdout); - } - - /* Close the original handle, we used the duplicate */ + apr_file_t *nullstdout; + if (apr_file_open_stdout(&nullstdout, process->pool) + == APR_SUCCESS) + apr_file_dup2(nullstdout, nullfile, process->pool); apr_file_close(nullfile); } } Index: server/log.c =================================================================== --- server/log.c (Revision 579708) +++ server/log.c (Arbeitskopie) @@ -421,6 +421,16 @@ apr_pool_destroy(stderr_pool); stderr_pool = stderr_p; replace_stderr = 0; + /* + * Now that we have dup'ed s_main->error_log to stderr_log + * close it and set s_main->error_log to stderr_log. This avoids + * this fd being inherited by the next piped logger who would + * keep open the writing end of the pipe that this one uses + * as stdin. This in turn would prevent the piped logger from + * exiting. + */ + apr_file_close(s_main->error_log); + s_main->error_log = stderr_log; } } /* note that stderr may still need to be replaced with something