From: Danny Mayer Date: Sat, 23 Jun 2007 12:42:58 +0000 (-0400) Subject: Bug #863 Unable to stop ntpd because the handle index changed X-Git-Tag: NTP_4_2_4P3_RC1~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96c7ac09722b1bf8b325369c144b6ec76bb0c87a;p=thirdparty%2Fntp.git Bug #863 Unable to stop ntpd because the handle index changed bk: 467d1552f4-Mm-YNirjZKHYc5R3Tyw --- diff --git a/ports/winnt/include/ntp_iocompletionport.h b/ports/winnt/include/ntp_iocompletionport.h index 24ec25dc8..dafc5606e 100644 --- a/ports/winnt/include/ntp_iocompletionport.h +++ b/ports/winnt/include/ntp_iocompletionport.h @@ -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 diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index 39ae4f15a..ee379902d 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -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 diff --git a/ports/winnt/ntpd/ntservice.c b/ports/winnt/ntpd/ntservice.c index 5eee4c12a..065f510c0 100644 --- a/ports/winnt/ntpd/ntservice.c +++ b/ports/winnt/ntpd/ntservice.c @@ -25,6 +25,7 @@ #include "syslog.h" #include "ntservice.h" #include "clockstuff.h" +#include "ntp_iocompletionport.h" #ifdef DEBUG #include #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;