You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@locus.apache.org on 2000/05/17 02:35:22 UTC

cvs commit: apache-2.0/src/os/win32 main_win32.c os.h service.c service.h

wrowe       00/05/16 17:35:22

  Modified:    src      ApacheCore.def Apache.dsp ApacheCore.dsp
               src/include http_config.h
               src/main http_main.c
               src/modules/mpm/winnt winnt.c
               src/os/win32 main_win32.c os.h service.c service.h
  Log:
  
    Radical overhaul of the Apache-2.0/Win32 mpm <-> service schema.
  
    1) Services and Registry are not part of the core Apache operations,
       so registry.c and service.c are moved into Apache.exe - assuring
       the service control layers of NT and 95 are truly isolated.
  
    2) Isolation can't be complete, we need to know when the mpm is
       fully initialized.  A new pointer to a no-arg function returning
       void is provided for this purpose, ap_mpm_init_complete.  It is
       only called if overridden with a non-NULL value prior to invoking
       apache_main.
  
    3) Control+C, Control+Break are handled on both WinNT and Win9x.
  
    4) The window close, logoff and shutdown events are handled on WinNT.
  
    5) The beginnings of a Win95 service startup are provided, -k startservice
       but this is horribly incomplete since Win95 will NOT report shutdown.
  
  
  
  Revision  Changes    Path
  1.18      +9 -8      apache-2.0/src/ApacheCore.def
  
  Index: ApacheCore.def
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/ApacheCore.def,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ApacheCore.def	2000/05/12 18:15:21	1.17
  +++ ApacheCore.def	2000/05/17 00:35:16	1.18
  @@ -369,18 +369,18 @@
           regerror @364
           ap_send_error_response @365
   	ap_start_shutdown @366
  -        send_signal_to_service  @367
  +;       send_signal_to_service  @367
           ap_read_config   @368
   	ap_server_pre_read_config  @369
   	ap_server_post_read_config @370
   	ap_setup_prelinked_modules @371
  -	RemoveService @372
  -	InstallService @373
  -	isValidService @374
  -	service_main  @375
  -	isProcessService @376
  -	ap_registry_get_server_root @377
  -	ap_registry_get_service_conf @378
  +;	RemoveService @372
  +;	InstallService @373
  +;	isValidService @374
  +;	service_main  @375
  +;	isProcessService @376
  +;	ap_registry_get_server_root @377
  +;	ap_registry_get_service_conf @378
           ap_hook_pre_connection @379
           ap_hook_post_read_request @380
           ap_hook_log_transaction @381
  @@ -399,3 +399,4 @@
           ap_run_http_method @394
           ap_bread_core @395
           ap_bwrite_core @396
  +	ap_mpm_init_complete @397
  
  
  
  1.6       +23 -0     apache-2.0/src/Apache.dsp
  
  Index: Apache.dsp
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/Apache.dsp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Apache.dsp	2000/04/17 13:56:38	1.5
  +++ Apache.dsp	2000/05/17 00:35:16	1.6
  @@ -90,10 +90,26 @@
   
   SOURCE=.\os\win32\main_win32.c
   # End Source File
  +# Begin Source File
  +
  +SOURCE=.\os\win32\registry.c
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=.\os\win32\service.c
  +# End Source File
   # End Group
   # Begin Group "Header Files"
   
   # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
  +# Begin Source File
  +
  +SOURCE=.\os\win32\registry.h
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=.\os\win32\service.h
  +# End Source File
   # End Group
   # Begin Group "Resource Files"
   
  @@ -105,6 +121,13 @@
   # Begin Source File
   
   SOURCE=.\os\win32\apache.rc
  +
  +!IF  "$(CFG)" == "Apache - Win32 Release"
  +
  +!ELSEIF  "$(CFG)" == "Apache - Win32 Debug"
  +
  +!ENDIF 
  +
   # End Source File
   # End Group
   # End Target
  
  
  
  1.21      +0 -16     apache-2.0/src/ApacheCore.dsp
  
  Index: ApacheCore.dsp
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/ApacheCore.dsp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ApacheCore.dsp	2000/05/06 15:44:39	1.20
  +++ ApacheCore.dsp	2000/05/17 00:35:16	1.21
  @@ -227,18 +227,10 @@
   # End Source File
   # Begin Source File
   
  -SOURCE=.\os\win32\registry.c
  -# End Source File
  -# Begin Source File
  -
   SOURCE=.\main\rfc1413.c
   # End Source File
   # Begin Source File
   
  -SOURCE=.\os\win32\service.c
  -# End Source File
  -# Begin Source File
  -
   SOURCE=.\main\util.c
   # End Source File
   # Begin Source File
  @@ -363,15 +355,7 @@
   # End Source File
   # Begin Source File
   
  -SOURCE=.\os\win32\registry.h
  -# End Source File
  -# Begin Source File
  -
   SOURCE=.\include\rfc1413.h
  -# End Source File
  -# Begin Source File
  -
  -SOURCE=.\os\win32\service.h
   # End Source File
   # Begin Source File
   
  
  
  
  1.20      +1 -0      apache-2.0/src/include/http_config.h
  
  Index: http_config.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/http_config.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- http_config.h	2000/05/15 19:21:35	1.19
  +++ http_config.h	2000/05/17 00:35:17	1.20
  @@ -382,6 +382,7 @@
   server_rec *ap_read_config(process_rec *process, ap_pool_t *temp_pool, const char *config_name);
   void ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
   void ap_child_init_hook(ap_pool_t *pchild, server_rec *s);
  +void ap_run_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp);
   
   void ap_register_hooks(module *m);
   void ap_hook_deregister_all(void);
  
  
  
  1.45      +2 -2      apache-2.0/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_main.c,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- http_main.c	2000/05/09 20:24:56	1.44
  +++ http_main.c	2000/05/17 00:35:18	1.45
  @@ -280,9 +280,9 @@
   ap_pool_t *g_pHookPool;
   
   #ifdef WIN32
  -API_EXPORT_NONSTD(int) apache_main(int argc, char *argv[])
  +API_EXPORT(int) apache_main(int argc, char *argv[])
   #else
  -API_EXPORT_NONSTD(int)        main(int argc, char *argv[])
  +API_EXPORT(int)        main(int argc, char *argv[])
   #endif
   {
       int c;
  
  
  
  1.66      +11 -6     apache-2.0/src/modules/mpm/winnt/winnt.c
  
  Index: winnt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/winnt.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- winnt.c	2000/05/12 00:43:43	1.65
  +++ winnt.c	2000/05/17 00:35:19	1.66
  @@ -68,7 +68,7 @@
   #include "ap_config.h"
   #include "ap_listen.h"
   #include "mpm_default.h"
  -#include "service.h"
  +//#include "service.h"
   #include "iol_socket.h"
   #include "winnt.h"
   
  @@ -107,6 +107,8 @@
   ap_lock_t *start_mutex;
   int my_pid;
   int parent_pid;
  +typedef void (CALLBACK *ap_completion_t)();
  +API_VAR_EXPORT ap_completion_t ap_mpm_init_complete = NULL;
   
   static ap_status_t socket_cleanup(void *sock)
   {
  @@ -1555,7 +1557,7 @@
       /* Create child process 
        * Should only be one in this version of Apache for WIN32 
        */
  -    service_set_status(SERVICE_START_PENDING);
  +    //service_set_status(SERVICE_START_PENDING);
       while (remaining_children_to_start--) {
           if (create_process(pconf, process_handles, process_kill_events, 
                              &current_live_processes) < 0) {
  @@ -1565,7 +1567,7 @@
               goto die_now;
           }
       }
  -    service_set_status(SERVICE_RUNNING);
  +    //service_set_status(SERVICE_RUNNING);
   
       restart_pending = shutdown_pending = 0;
       
  @@ -1738,7 +1740,7 @@
               }
   
               ap_log_pid(pconf, ap_pid_fname);
  -            service_set_status(SERVICE_START_PENDING);
  +            //service_set_status(SERVICE_START_PENDING);
   
               /* Create shutdown event, apPID_shutdown, where PID is the parent 
                * Apache process ID. Shutdown is signaled by 'apache -k shutdown'.
  @@ -1763,7 +1765,10 @@
                   exit(1);
               }
               CleanNullACL((void *)sa);
  -            
  +
  +            if (ap_mpm_init_complete)
  +                ap_mpm_init_complete();
  +
               /* Create the start mutex, apPID, where PID is the parent Apache process ID.
                * Ths start mutex is used during a restart to prevent more than one 
                * child process from entering the accept loop at once.
  @@ -1808,7 +1813,7 @@
               CloseHandle(restart_event);
               CloseHandle(shutdown_event);
   
  -            service_set_status(SERVICE_STOPPED);
  +            //service_set_status(SERVICE_STOPPED);
   
               return 1;
           }
  
  
  
  1.15      +62 -4     apache-2.0/src/os/win32/main_win32.c
  
  Index: main_win32.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/main_win32.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- main_win32.c	2000/04/28 18:27:54	1.14
  +++ main_win32.c	2000/05/17 00:35:20	1.15
  @@ -75,9 +75,12 @@
   #include "registry.h"
   #include "ap_config.h"
   
  -__declspec(dllexport) int apache_main(int argc, char *argv[]);
  +API_EXPORT(int) apache_main(int argc, char *argv[]);
   #define DEFAULTSERVICENAME "Apache"
   
  +typedef void (CALLBACK *ap_completion_t)();
  +API_VAR_IMPORT ap_completion_t ap_mpm_init_complete;
  +
   static const char* read_config_cmd(char *filename, char *cmd, ap_pool_t *p)
   {
       ap_status_t rc;
  @@ -156,15 +159,58 @@
       return;
       
   }
  +
   static void cleanup_and_exit(void)
   {
       ap_terminate();
       exit(0);
   }
  +
  +static BOOL CALLBACK console_control_handler(DWORD ctrl_type)
  +{
  +    switch (ctrl_type)
  +    {
  +        case CTRL_C_EVENT:
  +        case CTRL_BREAK_EVENT:
  +            fprintf(stderr, "Apache server interrupted...\n");
  +            /* for Interrupt signals, shut down the server.
  +             * Tell the system we have dealt with the signal
  +             * without waiting for Apache to terminate.
  +             */
  +            ap_start_shutdown();            
  +            return TRUE;
  +
  +        case CTRL_CLOSE_EVENT:
  +        case CTRL_LOGOFF_EVENT:
  +        case CTRL_SHUTDOWN_EVENT:
  +            /* for Terminate signals, shut down the server.
  +             * Wait for Apache to terminate, but respond
  +             * after a reasonable time to tell the system
  +             * that we did attempt to shut ourself down.
  +             * THESE EVENTS WILL NOT OCCUR UNDER WIN9x!
  +             */
  +            fprintf(stderr, "Apache server shutdown initiated...\n");
  +            ap_start_shutdown();
  +            Sleep(30000);
  +            return TRUE;
  +    }
  + 
  +    /* We should never get here, but this is (mostly) harmless */
  +    return FALSE;
  +}
  +
  +void CALLBACK console_started_hook()
  +{
  +    SetConsoleCtrlHandler(console_control_handler, TRUE);
  +
  +    /* We do this only once, ever! */
  +    ap_mpm_init_complete = NULL;
  +}
  +
   int main(int argc, char *argv[])
   {
       ap_pool_t *pwincmd;
  -    int c;
  +    int c, rv;
       char *ch;
       char *service_name = NULL; //DEFAULTSERVICENAME;
       char *signal = NULL;
  @@ -308,6 +354,12 @@
           cleanup_and_exit();
       }
   
  +    /* Handle -k startservice */
  +    if (signal && !strcasecmp(signal, "startservice")) {
  +        service95_main(apache_main, argc, argv);
  +        cleanup_and_exit();
  +    }
  +
       /* Handle -k <signal> -n <service_name> */
       if (service_name && signal) {
           send_signal_to_service(service_name, signal);
  @@ -348,6 +400,12 @@
       ap_optreset = 1;
       ap_optind = 1;
   
  -    return apache_main(new_argc, (char**) cmdtbl->elts);
  -    
  +    /* Proxy to delay console_control_handler hook until all is running */
  +    ap_mpm_init_complete = console_started_hook;
  +
  +    rv = apache_main(new_argc, (char**) cmdtbl->elts);
  +
  +    SetConsoleCtrlHandler(console_control_handler, FALSE);
  +
  +    return (rv);
   }
  
  
  
  1.26      +1 -1      apache-2.0/src/os/win32/os.h
  
  Index: os.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/os.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- os.h	2000/05/06 16:09:10	1.25
  +++ os.h	2000/05/17 00:35:20	1.26
  @@ -109,7 +109,7 @@
   #define USE_MMAP_SCOREBOARD
   #define HAVE_CANONICAL_FILENAME
   #define HAVE_DRIVE_LETTERS
  -#define HAVE_SENDFILE
  +#define HAVE_SENDFILE_UNKNOWN
   
   typedef int uid_t;
   typedef int gid_t;
  
  
  
  1.10      +63 -0     apache-2.0/src/os/win32/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/service.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- service.c	2000/04/28 18:27:55	1.9
  +++ service.c	2000/05/17 00:35:21	1.10
  @@ -71,6 +71,9 @@
   #include "registry.h"
   #include "ap_mpm.h"
   
  +typedef void (CALLBACK *ap_completion_t)();
  +API_VAR_IMPORT ap_completion_t ap_mpm_init_complete;
  +
   static struct
   {
       int (*main_fn)(int, char **);
  @@ -90,6 +93,53 @@
   static int ap_start_service(SC_HANDLE);
   static int ap_stop_service(SC_HANDLE);
   
  +static void CALLBACK report_service95_running()
  +{
  +    FreeConsole();
  +
  +    /* We do this only once, ever */
  +    ap_mpm_init_complete = NULL;
  +}
  +
  +int service95_main(int (*main_fn)(int, char **), int argc, char **argv )
  +{
  +    HINSTANCE hkernel;
  +    DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
  +    
  +    /* Obtain a handle to the kernel library */
  +    hkernel = LoadLibrary("KERNEL32.DLL");
  +    if (!hkernel)
  +        return -1;
  +    
  +    /* Find the RegisterServiceProcess function */
  +    RegisterServiceProcess = (DWORD (WINAPI *)(DWORD, DWORD))
  +                             GetProcAddress(hkernel, "RegisterServiceProcess");
  +    if (RegisterServiceProcess == NULL)
  +        return -1;
  +	
  +    /* Register this process as a service */
  +    if (!RegisterServiceProcess((DWORD)NULL, 1))
  +        return -1;
  +
  +    /* Eliminate the console for the remainer of the service session */
  +    ap_mpm_init_complete = report_service95_running;
  +
  +    /* Run the service */
  +    globdat.exit_status = main_fn(argc, argv);
  +
  +    /* When the service quits, remove it from the 
  +       system service table */
  +    RegisterServiceProcess((DWORD)NULL, 0);
  +
  +    /* Free the kernel library */
  +    // Worthless, methinks, since it won't be reclaimed
  +    // FreeLibrary(hkernel);
  +
  +    /* We have to quit right here to avoid an invalid page fault */
  +    // But, this is worth experimenting with!
  +    return (globdat.exit_status);
  +}
  +
   int service_main(int (*main_fn)(int, char **), int argc, char **argv )
   {
       SERVICE_TABLE_ENTRY dispatchTable[] =
  @@ -125,6 +175,17 @@
       chdir(buf);
   }
   
  +static void CALLBACK report_service_started()
  +{
  +    ReportStatusToSCMgr(
  +        SERVICE_RUNNING,    // service state
  +        NO_ERROR,           // exit code
  +        0);                 // wait hint
  +    
  +    /* This is only reported once, ever! */
  +    ap_mpm_init_complete = NULL;
  +}
  +
   void __stdcall service_main_fn(DWORD argc, LPTSTR *argv)
   {
       int i, new_argc;
  @@ -156,6 +217,8 @@
           SERVICE_START_PENDING, // service state
           NO_ERROR,              // exit code
           3000);                 // wait hint
  +
  +    ap_mpm_init_complete = report_service_started;
   
       service_cd();
   
  
  
  
  1.4       +1 -0      apache-2.0/src/os/win32/service.h
  
  Index: service.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/service.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- service.h	2000/04/15 17:48:16	1.3
  +++ service.h	2000/05/17 00:35:21	1.4
  @@ -61,6 +61,7 @@
   
   #ifdef WIN32
   int service_main(int (*main_fn)(int, char **), int argc, char **argv);
  +int service95_main(int (*main_fn)(int, char **), int argc, char **argv);
   void service_set_status(int status);
   void service_cd();
   BOOL isProcessService();