httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@locus.apache.org
Subject cvs commit: apache-1.3/src/os/win32 service.c service.h
Date Tue, 21 Nov 2000 12:42:07 GMT
wrowe       00/11/21 04:42:03

  Modified:    src/os/win32 service.c service.h
  Log:
    This patch begins the process of getting 16 bit CGIs working again on
    Win9x.  [note - apparently some NTs also have this problem at present.]
    Since we no longer free the child console window when the child process
    starts, we now do so in response to shutdown messages, since the child
    console interferes with the process manager.
  
    Also attempt to tag the child console as a service process to get around
    logoff/logon sequences, clean up the remaining issues with the Win9x
    -k start/restart/stop options, make pause work again (W2K fix broke 98)
    get rid of ugly casts, and add our copyright message.
  
  Revision  Changes    Path
  1.28      +176 -30   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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- service.c	2000/11/16 23:14:24	1.27
  +++ service.c	2000/11/21 12:41:56	1.28
  @@ -1,3 +1,60 @@
  +/* ====================================================================
  + * Copyright (c) 1995-2000 The Apache Group.  All rights reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer. 
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. All advertising materials mentioning features or use of this
  + *    software must display the following acknowledgment:
  + *    "This product includes software developed by the Apache Group
  + *    for use in the Apache HTTP server project (http://httpd.apache.org/)."
  + *
  + * 4. The names "Apache Server" and "Apache Group" must not be used to
  + *    endorse or promote products derived from this software without
  + *    prior written permission. For written permission, please contact
  + *    apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * 6. Redistributions of any form whatsoever must retain the following
  + *    acknowledgment:
  + *    "This product includes software developed by the Apache Group
  + *    for use in the Apache HTTP server project (http://httpd.apache.org/)."
  + *
  + * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  + * OF THE POSSIBILITY OF SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Group and was originally based
  + * on public domain software written at the National Center for
  + * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  + * For more information on the Apache Group and the Apache HTTP server
  + * project, please see <http://www.apache.org/>.
  + *
  + */
  +
   #ifdef WIN32
   
   #include <windows.h>
  @@ -31,8 +88,9 @@
   /* statics for atexit processing or shared between threads */
   static BOOL  die_on_logoff = FALSE;
   static DWORD monitor_thread_id = 0;
  -DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
  -HINSTANCE    monitor_hkernel = NULL;
  +static DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
  +static HINSTANCE monitor_hkernel = NULL;
  +static DWORD dos_child_procid = 0;
   
   static void WINAPI service_main_fn(DWORD, LPTSTR *);
   static void WINAPI service_ctrl(DWORD ctrlCode);
  @@ -60,6 +118,7 @@
       HANDLE hConIn;
       HANDLE hConErr;
       DWORD result;
  +    DWORD mode;
       time_t start;
       time_t remains;
       char *msg = "Note the errors or messages above, "
  @@ -78,7 +137,11 @@
           return;
       if (!GetConsoleScreenBufferInfo(hConErr, &coninfo))
           return;
  -    if (!SetConsoleMode(hConIn, ENABLE_MOUSE_INPUT | 0x80))
  +    if (isWindowsNT())
  +        mode = ENABLE_MOUSE_INPUT | 0x80;
  +    else
  +        mode = ENABLE_MOUSE_INPUT;
  +    if (!SetConsoleMode(hConIn, mode))
           return;
           
       start = time(NULL);
  @@ -134,6 +197,21 @@
       }
   }
   
  +static HHOOK catch_term_hook = NULL;
  +static HWND  console_wnd = NULL;
  +
  +static LRESULT CALLBACK HookCatchTerm(int nCode, WPARAM wParam, LPARAM lParam)
  +{
  +    LPMSG msg = (LPMSG) lParam;
  +    if (msg->hwnd == console_wnd) {
  +        if (msg->message == WM_QUERYENDSESSION 
  +         || msg->message == WM_ENDSESSION)
  +            DebugBreak();
  +            msg->message = WM_NULL;
  +    }
  +    return CallNextHookEx(catch_term_hook, nCode, wParam, lParam);
  +}
  +
   /* This is the WndProc procedure for our invisible window.
    * When the user shuts down the system, this window is sent
    * a signal WM_QUERYENDSESSION with lParam == 0 to indicate
  @@ -144,21 +222,33 @@
    * as well, but with lParam != 0. We ignore this case.
    */
   
  -int send_signal(pool *p, char *signal);
  -
   LRESULT CALLBACK Service9xWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
   {
       if (message == WM_QUERYENDSESSION)
       {
  +        return (!(lParam & ENDSESSION_LOGOFF) || die_on_logoff);
  +    }
  +    if (message == WM_ENDSESSION)
  +    {
           /* Hmmm... not logging out, must be shutting down */
  -        if ((lParam == 0) || die_on_logoff)
  +        if (dos_child_procid) {
  +            if (!(lParam & ENDSESSION_LOGOFF)) {
  +                /* Release the winoldap window from the child so that it
  +                 * won't interfere with the shutdown
  +                 */
  +                RegisterServiceProcess(dos_child_procid, 0);
  +                dos_child_procid = 0;
  +                FreeConsole();
  +            }
  +        }
  +        else if (!(lParam & ENDSESSION_LOGOFF) || die_on_logoff)
           {
  -            /* Tell Apache to shut down gracefully */
  +            /* Tell Apache to shut down gracefully and sleep it off 
  +             */
               ap_start_shutdown();
  -	    if (wParam)
  -		Sleep(30000);
  +   	    Sleep(60000);
           }
  -        return TRUE;
  +        return 0;
       }
       return (DefWindowProc(hWnd, message, wParam, lParam));
   }
  @@ -188,8 +278,15 @@
       wc.lpszMenuName  = NULL;
       if (service_name)
   	wc.lpszClassName = "ApacheWin95ServiceMonitor";
  +    else if (!dos_child_procid)
  +        wc.lpszClassName = "ApacheWin95ConsoleMonitor";
       else
  -	wc.lpszClassName = "ApacheWin95SystemMonitor";
  +	wc.lpszClassName = "ApacheWin95ChildMonitor";
  +
  +    /* hook window messages - ugly */
  +    if (dos_child_procid)
  +        catch_term_hook = SetWindowsHookEx(WH_GETMESSAGE, 
  +                                           HookCatchTerm, NULL, 0);
   
       die_on_logoff = service_name ? FALSE : TRUE;
   
  @@ -218,6 +315,11 @@
           TranslateMessage(&msg);
           DispatchMessage(&msg);
       }
  +
  +    /* unhook window messages - ugly */
  +    if (catch_term_hook)
  +        UnhookWindowsHookEx(catch_term_hook);
  +
       return 0;
   }
   
  @@ -228,12 +330,31 @@
   
       /* When the service quits, remove it from the 
          system service table */
  -    RegisterServiceProcess((DWORD)NULL, 0);
  +    RegisterServiceProcess(0, 0);
  +    
  +    if (dos_child_procid) {
  +        RegisterServiceProcess(dos_child_procid, 0);
  +        dos_child_procid = 0;
  +    }
   
       /* Free the kernel library */
       FreeLibrary(monitor_hkernel);
   }
   
  +static BOOL CALLBACK EnumttyWindow(HWND wnd, LPARAM retwnd)
  +{
  +    char tmp[8];
  +    if (GetClassName(wnd, tmp, sizeof(tmp)) && !strcmp("tty",tmp)) 
  +    {
  +        DWORD wndproc, thisproc = GetCurrentProcessId();
  +        GetWindowThreadProcessId(wnd, &wndproc);
  +        if (wndproc == thisproc) {
  +            *((HWND*)retwnd) = wnd;
  +            return FALSE;
  +        }
  +    }
  +    return TRUE;
  +}
   /*
    * The WinNT child can simply free its console.
    * Win9x children cannot loose the console since 16bit cgi processes
  @@ -243,6 +364,9 @@
    */
   void ap_prepare_child_console(void)
   {
  +    HANDLE thread;
  +    HWND console = NULL;
  +
       if (isWindowsNT()) {
           FreeConsole();
           return;
  @@ -260,11 +384,27 @@
           return;
   	
       /* Register this process as a service */
  -    if (!RegisterServiceProcess((DWORD)NULL, 1))
  +    if (!RegisterServiceProcess(0, 1))
           return;
   
  -    /* Borrowing stop_service_monitor, but there is no monitor thread */
  -    monitor_thread_id = 0;
  +    /* Locate our winoldap process, and tag it as a service process */
  +    EnumWindows(EnumttyWindow, (long)(&console_wnd));
  +    if (console)
  +    {
  +        console = GetWindow(console_wnd, GW_CHILD);
  +        GetWindowThreadProcessId(console, &dos_child_procid);
  +        if (!RegisterServiceProcess(dos_child_procid, 1))
  +            return;
  +    }
  +
  +    /* WatchWindow is NULL - that is - we are not the actual service,
  +     * so we are not monitoring these events, nor will we respond to
  +     * service requests to our window.
  +     */
  +    thread = CreateThread(NULL, 0, WatchWindow, NULL, 0, 
  +			  &monitor_thread_id);
  +    if (thread)
  +        CloseHandle(thread);
   
       atexit(stop_service_monitor);
   }
  @@ -292,7 +432,7 @@
           return -1;
   	
       /* Register this process as a service */
  -    if (!RegisterServiceProcess((DWORD)NULL, 1))
  +    if (!RegisterServiceProcess(0, 1))
           return -1;
   
       /* Prevent holding open the (nonexistant) console */
  @@ -865,7 +1005,7 @@
       static BOOL once = FALSE;
       static BOOL isNT = FALSE;
       
  -    if (!once) 
  +    if (!once)
       {
           OSVERSIONINFO osver;
           osver.dwOSVersionInfoSize = sizeof(osver);
  @@ -949,10 +1089,13 @@
       if (globdat.ssStatus.dwCurrentState == SERVICE_STOPPED 
               && action == stop) {
           printf("The %s service is not started.\n", display_name);
  +        return FALSE;
       }
       else if (globdat.ssStatus.dwCurrentState == SERVICE_RUNNING 
                    && action == start) {
  -       printf("The %s service has already been started.\n", display_name);
  +        printf("The %s service has already been started.\n", display_name);
  +        strcpy(sig, "");
  +        return FALSE;
       }
       else
       {
  @@ -988,7 +1131,7 @@
                       Sleep(1000);
                   }
               }
  -            else /* !stop */
  +            else if (action == restart) 
               {   
                   /* This gets a bit tricky... start and restart (of stopped service)
                    * will simply fall through and *THIS* process will fade into an
  @@ -997,19 +1140,22 @@
                    * if the service was not -yet- running, and we do return FALSE
                    * to assure main() that we haven't done anything yet.
                    */
  -                if (action == restart) 
  +                if (globdat.ssStatus.dwCurrentState == SERVICE_STOPPED) 
                   {
  -                    if (globdat.ssStatus.dwCurrentState == SERVICE_STOPPED) 
  -                    {
  -                        printf("The %s service has %s.\n", display_name, 
  -                               past[action]);
  -                        strcpy(sig, "start");
  -                        return success;
  -                    }
  -                    
  -                    ap_start_restart(1);
  -                    success = TRUE;
  +                    printf("The %s service has %s.\n", display_name, 
  +                           past[action]);
  +                    strcpy(sig, "start");
  +                    return FALSE;
                   }
  +                
  +                ap_start_restart(1);
  +                success = TRUE;
  +            }
  +            else /* action == start */
  +            {
  +                printf("The %s service is %s.\n", display_name, 
  +                       past[action]);
  +                return FALSE;
               }
           }
   
  
  
  
  1.11      +56 -0     apache-1.3/src/os/win32/service.h
  
  Index: service.h
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/service.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- service.h	2000/11/16 23:14:24	1.10
  +++ service.h	2000/11/21 12:41:57	1.11
  @@ -1,3 +1,59 @@
  +/* ====================================================================
  + * Copyright (c) 1995-2000 The Apache Group.  All rights reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer. 
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. All advertising materials mentioning features or use of this
  + *    software must display the following acknowledgment:
  + *    "This product includes software developed by the Apache Group
  + *    for use in the Apache HTTP server project (http://httpd.apache.org/)."
  + *
  + * 4. The names "Apache Server" and "Apache Group" must not be used to
  + *    endorse or promote products derived from this software without
  + *    prior written permission. For written permission, please contact
  + *    apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * 6. Redistributions of any form whatsoever must retain the following
  + *    acknowledgment:
  + *    "This product includes software developed by the Apache Group
  + *    for use in the Apache HTTP server project (http://httpd.apache.org/)."
  + *
  + * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  + * OF THE POSSIBILITY OF SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Group and was originally based
  + * on public domain software written at the National Center for
  + * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  + * For more information on the Apache Group and the Apache HTTP server
  + * project, please see <http://www.apache.org/>.
  + *
  + */
   
   #ifndef SERVICE_H
   #define SERVICE_H
  
  
  

Mime
View raw message