httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apache-1.3/src/os/win32 service.c
Date Mon, 26 Feb 2001 20:33:57 GMT
wrowe       01/02/26 12:33:56

  Modified:    src      CHANGES
               src/os/win32 service.c
  Log:
    Introduce NUL device pipes for stdin and stdout for the parent Win32
    service process.  This solves bugs such as PR7198 that report
    "dup2(stdin) failed" when trying to use piped logs.
  
  Revision  Changes    Path
  1.1660    +4 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1659
  retrieving revision 1.1660
  diff -u -r1.1659 -r1.1660
  --- CHANGES	2001/02/26 17:39:05	1.1659
  +++ CHANGES	2001/02/26 20:33:48	1.1660
  @@ -1,5 +1,9 @@
   Changes with Apache 1.3.20
   
  +  *) Introduce NUL device pipes for stdin and stdout for the parent Win32
  +     service process.  This solves bugs such as PR7198 that report 
  +     "dup2(stdin) failed" when trying to use piped logs.  [William Rowe]
  +
   Changes with Apache 1.3.19
   
     *) Rewrite ap_unparse_uri_components() to make it safer and more readable
  
  
  
  1.45      +41 -0     apache-1.3/src/os/win32/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/service.c,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- service.c	2001/02/21 00:36:38	1.44
  +++ service.c	2001/02/26 20:33:53	1.45
  @@ -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 nak 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