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 http_main.c
Date Mon, 26 Mar 2001 19:25:55 GMT
wrowe       01/03/26 11:25:55

  Modified:    src      CHANGES
               src/os/win32 service.c
               src/main http_main.c
  Log:
    Solved a very serious threading problem with WinNT/2K Services.  The
    moment master_main told that the shutdown was complete, the parent
    control thread exited Apache, leaving mod_jserv's Java process running
    and alternately invoking mod_perl's cleanups from the correct thread
    or the service control thread. [William Rowe]
  
    List of PR's too long to cite...
  
  Revision  Changes    Path
  1.1670    +6 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1669
  retrieving revision 1.1670
  diff -u -r1.1669 -r1.1670
  --- CHANGES	2001/03/26 17:13:41	1.1669
  +++ CHANGES	2001/03/26 19:25:52	1.1670
  @@ -1,5 +1,11 @@
   Changes with Apache 1.3.20
   
  +  *) Solved a very serious threading problem with WinNT/2K Services.  The
  +     moment master_main told that the shutdown was complete, the parent
  +     control thread exited Apache, leaving mod_jserv's Java process running
  +     and alternately invoking mod_perl's cleanups from the correct thread
  +     or the service control thread. [William Rowe]
  +
     *) Populate the Win32 HKLM\System\CurrentControlSet\Services\[apachesvc]
        key with the Description value of the running server across all Win32
        platforms, including NT, ME and 9x.  This value is the server_version
  
  
  
  1.52      +28 -27    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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- service.c	2001/03/26 18:10:34	1.51
  +++ service.c	2001/03/26 19:25:53	1.52
  @@ -127,7 +127,21 @@
       CONSOLE_SCREEN_BUFFER_INFO coninfo;
       INPUT_RECORD in;
       char count[16];
  -    
  +
  +#ifdef WIN32
  +    /* The service parent cannot just 'pop' out of the main thread,
  +     * as it is about to try to do...
  +     * We must end this thread properly so the service control
  +     * thread exits gracefully.  atexit()s registered in the running
  +     * apache_main thread _should_ have already been handled, so now
  +     * we can exit this thread and allow the service thread to exit.
  +     */
  +    if (isWindowsNT() && isProcessService() && globdat.connected) {
  +        service_set_status(SERVICE_STOPPED);
  +        ExitThread(0);
  +    }
  +#endif
  +
       if (!real_exit_code)
           return;
       hConIn = GetStdHandle(STD_INPUT_HANDLE);
  @@ -411,6 +425,9 @@
       return (globdat.exit_status);
   }
   
  +static HANDLE eventlog_pipewrite = NULL;
  +static HANDLE eventlog_thread = NULL;
  +
   int service_main(int (*main_fn)(int, char **), int argc, char **argv )
   {
       SERVICE_TABLE_ENTRY dispatchTable[] =
  @@ -435,17 +452,20 @@
       {
           /* This is a genuine failure of the SCM. */
           ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_WIN32ERROR, NULL,
  -        "Error starting service control dispatcher");
  -        return(globdat.exit_status);
  +                     "Error starting service control dispatcher");
       }
  -    else
  +
  +    globdat.connected = 0;
  +
  +    if (eventlog_pipewrite)
       {
  -        return(globdat.exit_status);
  +        CloseHandle(eventlog_pipewrite);
  +        WaitForSingleObject(eventlog_thread, 10000);
  +        eventlog_pipewrite = NULL;
       }
  -}
   
  -static HANDLE eventlog_pipewrite = NULL;
  -static HANDLE eventlog_thread = NULL;
  +    return(globdat.exit_status);
  +}
   
   long __stdcall service_stderr_thread(LPVOID hPipe)
   {
  @@ -523,22 +543,6 @@
       return 0;
   }
   
  -static void service_main_fn_terminate(void)
  -{
  -    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, NULL,
  -                 "The service manager thread is terminating.");
  -
  -    if (eventlog_pipewrite)
  -    {
  -        CloseHandle(eventlog_pipewrite);
  -        WaitForSingleObject(eventlog_thread, 10000);
  -        eventlog_pipewrite = NULL;
  -        eventlog_pipewrite = NULL;
  -    }
  -
  -    ReportStatusToSCMgr(SERVICE_STOPPED, NO_ERROR, 0);
  -}
  -
   void __stdcall service_main_fn(DWORD argc, LPTSTR *argv)
   {
       HANDLE hCurrentProcess;
  @@ -641,8 +645,6 @@
           memcpy(stdout, fl, sizeof(FILE));
       }
   
  -    atexit(service_main_fn_terminate);
  -
       /* Grab it or lose it */
       globdat.name = argv[0];
   
  @@ -781,7 +783,6 @@
                            "Service Stop/Shutdown signaled, shutting down server.");
               ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 15000);
               ap_start_shutdown();
  -            // ReportStatusToSCMgr(SERVICE_STOPPED, NO_ERROR, 0);
               break;
   
           case SERVICE_APACHE_RESTART:
  
  
  
  1.533     +6 -4      apache-1.3/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
  retrieving revision 1.532
  retrieving revision 1.533
  diff -u -r1.532 -r1.533
  --- http_main.c	2001/03/02 22:37:00	1.532
  +++ http_main.c	2001/03/26 19:25:54	1.533
  @@ -1088,7 +1088,7 @@
       fprintf(stderr, "  -k uninstall | -u: uninstall an Apache service\n");
   #endif
   
  -#ifdef NETWARE
  +#if defined(NETWARE)
       clean_parent_exit(0);
   #else
       exit(1);
  @@ -6568,8 +6568,6 @@
       }
   
       ap_destroy_mutex(start_mutex);
  -
  -    service_set_status(SERVICE_STOPPED);
       return (0);
   }
   #endif
  @@ -6686,7 +6684,11 @@
               || ((argc == 2) && !strcmp(argv[1], "--ntservice")))
           {
               service_main(apache_main, argc, argv);
  -            clean_parent_exit(0);
  +            /* this was the end of the service control thread... 
  +             * cleanups already ran when second thread of apache_main
  +             * terminated, so simply...
  +             */
  +            exit(0);
           }
       }
   
  
  
  

Mime
View raw message