httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <wr...@lnd.com>
Subject RE: Win32 Process Window Termination
Date Tue, 16 May 2000 20:03:51 GMT
I'm -really- hesitant to touch this, seeing as you own 
it at this moment, Bill.  Here's the 2.0 equivilant of
the new 1.3.x code for clean process termination.

Feel free to test and criticize.  This -does-not- solve
the Win9x hung shutdown issue, which is it's own beast.

Index: src/modules/mpm/winnt/winnt.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/winnt.c,v
retrieving revision 1.65
diff -u -r1.65 winnt.c
--- src/modules/mpm/winnt/winnt.c	2000/05/12 00:43:43	1.65
+++ src/modules/mpm/winnt/winnt.c	2000/05/16 20:00:45
     return 0;
 }
 
+static BOOL CALLBACK master_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;
+}
+
 static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_event)
 {
     int remaining_children_to_start = ap_daemons_to_start;
@@ -1548,6 +1581,8 @@
 
     HANDLE process_handles[MAX_PROCESSES];
     HANDLE process_kill_events[MAX_PROCESSES];
+
+    SetConsoleCtrlHandler(master_control_handler, TRUE);
 
     setup_listeners(s);
     bind_listeners_to_completion_port();

Mime
View raw message