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/main alloc.c
Date Thu, 19 Dec 2002 21:22:23 GMT
wrowe       2002/12/19 13:22:23

  Modified:    src/main alloc.c
  Log:
    Teach win32 about magic_cleanups to toggle the INHERIT bit for handles.
  
    This can only work for NT, since 9x cannot alter a handle's INHERIT bit
    without a DuplicateHandle() and then closing the original handle, which
    just doesn't fit into this API very well.
  
    {Actually, could be done with a bit of convolutions for FILE and fd,
    but this won't work by the ap_note_cleanups_for_h() api.)
  
  Revision  Changes    Path
  1.137     +67 -7     apache-1.3/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/alloc.c,v
  retrieving revision 1.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- alloc.c	18 Dec 2002 22:22:08 -0000	1.136
  +++ alloc.c	19 Dec 2002 21:22:23 -0000	1.137
  @@ -1790,6 +1790,44 @@
    * generic cleanup interface.
    */
   
  +#if defined(WIN32)
  +/* Provided by service.c, internal to the core library (not exported) */
  +BOOL isWindowsNT(void);
  +
  +int ap_close_handle_on_exec(HANDLE nth)
  +{
  +    /* Protect the fd so that it will not be inherited by child processes */
  +    if (isWindowsNT()) {
  +        DWORD hinfo;
  +        if (!GetHandleInformation(nth, &hinfo)) {
  +	    ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "GetHandleInformation"
  +                         "(%08x) failed", nth);
  +	    return 0;
  +        }
  +        if ((hinfo & HANDLE_FLAG_INHERIT)
  +                && !SetHandleInformation(nth, HANDLE_FLAG_INHERIT, 0)) {
  +	    ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "SetHandleInformation"
  +                         "(%08x, HANDLE_FLAG_INHERIT, 0) failed", nth);
  +	    return 0;
  +        }
  +        return 1;
  +    }
  +    else /* Win9x */ {
  +        /* XXX: This API doesn't work... you can't change the handle by just
  +         * 'touching' it... you must duplicat to a second handle and close
  +         * the original.
  +         */
  +        return 0;
  +    }
  +}
  +
  +int ap_close_fd_on_exec(int fd)
  +{
  +    return ap_close_handle_on_exec((HANDLE)_get_osfhandle(fd));
  +}
  +
  +#else
  +
   int ap_close_fd_on_exec(int fd)
   {
   #if defined(F_SETFD) && defined(FD_CLOEXEC)
  @@ -1806,6 +1844,8 @@
   #endif
   }
   
  +#endif /* ndef(WIN32) */
  +
   static void fd_cleanup(void *fdv)
   {
       close((int) (long) fdv);
  @@ -1870,14 +1910,27 @@
   }
   
   #ifdef WIN32
  -static void h_cleanup(void *fdv)
  +static void h_cleanup(void *nth)
  +{
  +    CloseHandle((HANDLE) nth);
  +}
  +
  +static int h_magic_cleanup(void *nth)
  +{
  +    /* Set handle not-inherited
  +     */
  +    return ap_close_handle_on_exec((HANDLE) nth);
  +}
  +
  +API_EXPORT(void) ap_note_cleanups_for_h_ex(pool *p, HANDLE nth, int domagic)
   {
  -    CloseHandle((HANDLE) fdv);
  +    ap_register_cleanup_ex(p, (void *) nth, h_cleanup, h_cleanup,
  +                           domagic ? h_magic_cleanup : NULL);
   }
   
  -API_EXPORT(void) ap_note_cleanups_for_h(pool *p, HANDLE hDevice)
  +API_EXPORT(void) ap_note_cleanups_for_h(pool *p, HANDLE nth)
   {
  -    ap_register_cleanup(p, (void *) hDevice, h_cleanup, h_cleanup);
  +    ap_note_cleanups_for_h_ex(p, nth, 0);
   }
   
   API_EXPORT(int) ap_pcloseh(pool *a, HANDLE hDevice)
  @@ -1908,10 +1961,12 @@
   {
       fclose((FILE *) fpv);
   }
  +
   static void file_child_cleanup(void *fpv)
   {
       close(fileno((FILE *) fpv));
   }
  +
   static int file_magic_cleanup(void *fpv)
   {
       return ap_close_fd_on_exec(fileno((FILE *) fpv));
  @@ -2036,9 +2091,14 @@
   {
       closesocket((int) (long) fdv);
   }
  +
   static int socket_magic_cleanup(void *fpv)
   {
  +#ifdef WIN32
  +    return ap_close_handle_on_exec((HANDLE) fpv);
  +#else
       return ap_close_fd_on_exec((int) (long) fpv);
  +#endif
   }
   
   API_EXPORT(void) ap_note_cleanups_for_socket_ex(pool *p, int fd, int domagic)
  @@ -2613,7 +2673,7 @@
               *pipe_out = ap_bcreate(p, B_RD);
   
   	    /* Setup the cleanup routine for the handle */
  -            ap_note_cleanups_for_h(p, hPipeOutputRead);   
  +            ap_note_cleanups_for_h_ex(p, hPipeOutputRead, 1);   
   
   	    /* Associate the handle with the new buffer */
               ap_bpushh(*pipe_out, hPipeOutputRead);
  @@ -2628,7 +2688,7 @@
               *pipe_in = ap_bcreate(p, B_WR);             
   
   	    /* Setup the cleanup routine for the handle */
  -            ap_note_cleanups_for_h(p, hPipeInputWrite);
  +            ap_note_cleanups_for_h_ex(p, hPipeInputWrite, 1);
   
   	    /* Associate the handle with the new buffer */
               ap_bpushh(*pipe_in, hPipeInputWrite);
  @@ -2644,7 +2704,7 @@
               *pipe_err = ap_bcreate(p, B_RD);
   
   	    /* Setup the cleanup routine for the handle */
  -            ap_note_cleanups_for_h(p, hPipeErrorRead);
  +            ap_note_cleanups_for_h_ex(p, hPipeErrorRead, 1);
   
   	    /* Associate the handle with the new buffer */
               ap_bpushh(*pipe_err, hPipeErrorRead);
  
  
  

Mime
View raw message