]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug #863 Unable to stop ntpd because the handle index changed
authorDanny Mayer <mayer@ntp.org>
Sat, 23 Jun 2007 12:42:58 +0000 (08:42 -0400)
committerDanny Mayer <mayer@ntp.org>
Sat, 23 Jun 2007 12:42:58 +0000 (08:42 -0400)
bk: 467d1552f4-Mm-YNirjZKHYc5R3Tyw

ports/winnt/include/ntp_iocompletionport.h
ports/winnt/ntpd/ntp_iocompletionport.c
ports/winnt/ntpd/ntservice.c

index 24ec25dc87e9c314ea86fa0338986bbeebd8a086..dafc5606ee41385e8241c90f577a8b3f7c8e45fd 100644 (file)
@@ -1,6 +1,7 @@
 #if !defined __ntp_iocompletionport_h
 # define __ntp_iocompletionport_h
 
+#include "ntp_fp.h"
 #include "ntp.h"
 
 # if defined(HAVE_IO_COMPLETION_PORT)
@@ -19,6 +20,8 @@ extern        DWORD   io_completion_port_sendto (struct interface *, struct pkt *, int, s
 
 extern HANDLE get_io_event (void);
 
+extern HANDLE get_exit_event(void);            /* Handle of the exit event */
+
 int GetReceivedBuffers(void);
 
 # endif
index 39ae4f15ae9363e356fed23a90b3771e4d89d58b..ee379902db2611df9147aaad67677ccbd5b09077 100644 (file)
@@ -57,6 +57,7 @@ static HANDLE hHeapHandle = NULL;
 static HANDLE hIoCompletionPort = NULL;
 
 static HANDLE WaitableIoEventHandle = NULL;
+static HANDLE WaitableExitEventHandle = NULL;
 
 #define MAXHANDLES 3
 HANDLE WaitHandles[MAXHANDLES] = { NULL, NULL, NULL };
@@ -120,6 +121,11 @@ get_io_event()
 {
        return( WaitableIoEventHandle );
 }
+HANDLE
+get_exit_event()
+{
+       return( WaitableExitEventHandle );
+}
 
 /*  This function will add an entry to the I/O completion port
  *  that will signal the I/O thread to exit (gracefully)
@@ -242,6 +248,14 @@ init_io_completion_port(
                "Can't create I/O event handle: %m - another process may be running - EXITING");
                exit(1);
        }
+       /* Create the event used to signal an exit event
+        */
+       WaitableExitEventHandle = CreateEvent(NULL, FALSE, FALSE, "WaitableExitEventHandle");
+       if (WaitableExitEventHandle == NULL) {
+               msyslog(LOG_ERR,
+               "Can't create exit event handle: %m - another process may be running - EXITING");
+               exit(1);
+       }
 
        /* Create the IO completion port
         */
@@ -255,7 +269,7 @@ init_io_completion_port(
         * Initialize the Wait Handles
         */
        WaitHandles[0] = get_io_event();
-       WaitHandles[1] = CreateEvent(NULL, FALSE, FALSE, "WaitHandles0"); /* exit request */
+       WaitHandles[1] = get_exit_event(); /* exit request */
        WaitHandles[2] = get_timer_handle();
 
        /* Have one thread servicing I/O - there were 4, but this would 
index 5eee4c12a074f4a91d952e1d37aae944d7c17091..065f510c040990b17a75651445cd57f04bbb2c47 100644 (file)
@@ -25,6 +25,7 @@
 #include "syslog.h"
 #include "ntservice.h"
 #include "clockstuff.h"
+#include "ntp_iocompletionport.h"
 #ifdef DEBUG
 #include <crtdbg.h>
 #endif
@@ -36,7 +37,6 @@ static char ConsoleTitle[128];
 static int glb_argc;
 static char **glb_argv;
 HANDLE hServDoneEvent = NULL;
-extern HANDLE WaitHandles[3];
 extern volatile int debug;
 extern char *progname;
 
@@ -172,13 +172,15 @@ ntservice_exit( void )
 void
 ServiceControl(DWORD dwCtrlCode) {
        /* Handle the requested control code */
+       HANDLE exitEvent = get_exit_event();
+
        switch(dwCtrlCode) {
 
        case SERVICE_CONTROL_SHUTDOWN:
        case SERVICE_CONTROL_STOP:
                UpdateSCM(SERVICE_STOP_PENDING);
-               if (WaitHandles[0] != NULL) {
-                       SetEvent(WaitHandles[0]);
+               if (exitEvent != NULL) {
+                       SetEvent(exitEvent);
                        Sleep( 100 );  //##++
                }
                return;
@@ -225,6 +227,8 @@ OnConsoleEvent(
        DWORD dwCtrlType
        )
 {
+       HANDLE exitEvent = get_exit_event();
+
        switch (dwCtrlType) {
 #ifdef DEBUG
                case CTRL_BREAK_EVENT :
@@ -244,8 +248,8 @@ OnConsoleEvent(
                case CTRL_C_EVENT  :
                case CTRL_CLOSE_EVENT :
                case CTRL_SHUTDOWN_EVENT :
-                       if (WaitHandles[0] != NULL) {
-                               SetEvent(WaitHandles[0]);
+                       if (exitEvent != NULL) {
+                               SetEvent(exitEvent);
                                Sleep( 100 );  //##++
                        }
                break;