httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Stoddard" <b...@wstoddard.com>
Subject Re: [PATCH 1.3] Diagnosing W2K service bugreports
Date Mon, 26 Feb 2001 18:15:35 GMT
Not tested, but I am +1 for taking the chance and including it in the build.
Hav eyou tested to make sure CGIs work still? If it breaks anything, I would
expect it be 95/98.

Bill


----- Original Message -----
From: William A. Rowe, Jr. <wrowe@rowe-clan.net>
To: <new-httpd@apache.org>; <v.j.orlikowski@gte.net>; Bill Stoddard
<bill@wstoddard.com>
Sent: Monday, February 26, 2001 11:27 AM
Subject: [PATCH 1.3] Diagnosing W2K service bugreports


> This bugfix should go in if we want rotatelogs to behave correctly, per
PR7198
> and Victor's observations.  I don't know, Martin, if you can let this one
> slide in, and unless FirstBill and Victor can both comment in the next few
> minutes, I'm expecting we will loose any window for the patch.
>
> We were -1 (?) from FirstBill, who posted that we should fix the behavior
that
> broke the code.  Unfortunately, it was MS + our introduction of piped logs
into
> Win32, which never worked before my patch to 1.3.13-dev.  Bill, please
clarify.
>
> I can find no fault with the code, yet I've been playing some very odd games
> trying to break the server with this patch (amongst others that I don't
propose
> today.)
>
> The concept of the patch is this: Win32 services aren't getting valid
handles
> for their stdin/stdout/stderr.  We have fixed stderr to dump into the event
> log through a seperate thread and pipe.  This simply introduces handles to
the
> "NUL" device on Win32 for stdin/stdout.
>
> Comments?
>
> Bill
>
> ----- Original Message -----
> From: "William A. Rowe, Jr." <wrowe@rowe-clan.net>
> To: <new-httpd@apache.org>
> Sent: Saturday, February 24, 2001 3:05 PM
> Subject: Diagnosing W2K service bugreports
>
>
> > I've noticed something very interesting in the Win32 code.
> >
> > Services gain no stdin/out/err handles as the parent is launched.
> > I suspected this could be confusing perl56.dll when it tries to
> > clean up before stopping the service.  That appears to _not_ be
> > the issue.  But there is a bug report, 7198 [hope I don't transpose
> > the digits yet again :-] that indicates the system fails on dup2(stdin)
> > when the user tries to use rotatelogs.  Now I've come up with the
> > following patch that introduces "NUL" handles for win32 stdin/stdout,
> > and the stderr is already set to a pipe that captures all 'pre-logging'
> > fprintf(stderr...) stuff into the event log.
> >
> > Here's the code I'm suggesting we include in 1.3.19 that resolves the
> > spawning rotatelogs bug after I test on NT (it's already tested on Win2K):
>
>  Index: service.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/os/win32/service.c,v
> retrieving revision 1.44
> diff -u -r1.44 service.c
> --- service.c 2001/02/21 00:36:38 1.44
> +++ service.c 2001/02/24 21:00:13
> @@ -547,6 +547,7 @@
>      HANDLE hCurrentProcess;
>      HANDLE hPipeRead = NULL;
>      HANDLE hPipeReadDup;
> +    HANDLE hNullFile;
>      DWORD  threadid;
>      SECURITY_ATTRIBUTES sa = {0};
>      char **newargv;
> @@ -601,6 +602,46 @@
>              CloseHandle(eventlog_pipewrite);
>              eventlog_pipewrite = NULL;
>          }
> +    }
> +
> +    /* Open a null handle to spoof our stdin */
> +    hNullFile = CreateFile("nul", GENERIC_READ | GENERIC_WRITE,
> +                           FILE_SHARE_READ | FILE_SHARE_WRITE,
> +                           &sa, OPEN_EXISTING, 0, NULL);
> +    if (hNullFile == INVALID_HANDLE_VALUE) {
> +        ap_log_error(APLOG_MARK, APLOG_WIN32ERROR | APLOG_CRIT, NULL,
> +                     "Parent: Unable to create null stdin pipe for this
service process.\n");
> +    }
> +    else {
> +        int fh;
> +        FILE *fl;
> +        fflush(stdin);
> +        SetStdHandle(STD_INPUT_HANDLE, hNullFile);
> +        fh = _open_osfhandle((long) STD_INPUT_HANDLE,
> +                             _O_RDONLY | _O_BINARY);
> +        dup2(fh, STDIN_FILENO);
> +        fl = _fdopen(STDIN_FILENO, "rcb");
> +        memcpy(stdin, fl, sizeof(FILE));
> +    }
> +
> +    /* Open a null handle to soak our stdout */
> +    hNullFile = CreateFile("nul", GENERIC_READ | GENERIC_WRITE,
> +                           FILE_SHARE_READ | FILE_SHARE_WRITE,
> +                           &sa, OPEN_EXISTING, 0, NULL);
> +    if (hNullFile == INVALID_HANDLE_VALUE) {
> +        ap_log_error(APLOG_MARK, APLOG_WIN32ERROR | APLOG_CRIT, NULL,
> +                     "Parent: Unable to create null stdout pipe for this
service process.\n");
> +    }
> +    else {
> +        int fh;
> +        FILE *fl;
> +        fflush(stdout);
> +        SetStdHandle(STD_OUTPUT_HANDLE, hNullFile);
> +        fh = _open_osfhandle((long) STD_OUTPUT_HANDLE,
> +                             _O_WRONLY | _O_BINARY);
> +        dup2(fh, STDOUT_FILENO);
> +        fl = _fdopen(STDOUT_FILENO, "wcb");
> +        memcpy(stdout, fl, sizeof(FILE));
>      }
>
>      atexit(service_main_fn_terminate);
>
>
>


Mime
View raw message