From e8fc0557d3da988b9a830af0dd0b84c27a4c1ff4 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 19 Mar 2004 01:09:40 +0000 Subject: [PATCH] notifyaddrchange-20040318 NotifyAddrChange() on Win2000 without privs fails. Detect the failure and terminate the IPChangeMonitor thread to prevent an infinite loop eating up system resources. Anyone have a clue which bits are required? --- src/WINNT/client_creds/afskfw.c | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/WINNT/client_creds/afskfw.c b/src/WINNT/client_creds/afskfw.c index 5c93cfefe6..1a00fe889d 100644 --- a/src/WINNT/client_creds/afskfw.c +++ b/src/WINNT/client_creds/afskfw.c @@ -3462,12 +3462,13 @@ void IpAddrChangeMonitor(void * hWnd) { #ifdef USE_OVERLAPPED - HANDLE Handle = INVALID_HANDLE_VALUE; + HANDLE Handle = INVALID_HANDLE_VALUE; /* Do Not Close This Handle */ OVERLAPPED Ovlap; #endif /* USE_OVERLAPPED */ DWORD Result; DWORD prevNumOfAddrs = GetNumOfIpAddrs(); DWORD NumOfAddrs; + char message[256]; if ( !hWnd ) return; @@ -3479,33 +3480,48 @@ IpAddrChangeMonitor(void * hWnd) Result = NotifyAddrChange(&Handle,&Ovlap); if (Result != ERROR_IO_PENDING) { - printf("NotifyAddrChange() failed with error %d \n", Result); + if ( IsDebuggerPresent() ) { + sprintf(message, "NotifyAddrChange() failed with error %d \n", Result); + OutputDebugString(message); + } break; } - if ((Result = WaitForSingleObject(Handle,INFINITE)) == WAIT_FAILED) + if ((Result = WaitForSingleObject(Handle,INFINITE)) != WAIT_OBJECT_0) { - printf("WaitForSingleObject() failed with error %d\n", - GetLastError()); + if ( IsDebuggerPresent() ) { + sprintf(message, "WaitForSingleObject() failed with error %d\n", + GetLastError()); + OutputDebugString(message); + } continue; } if (GetOverlappedResult(Handle, &Ovlap, &DataTransfered, TRUE) == 0) { - printf("GetOverlapped result failed %d \n", - GetLastError()); + if ( IsDebuggerPresent() ) { + sprintf(message, "GetOverlapped result failed %d \n", + GetLastError()); + OutputDebugString(message); + } break; } - #else Result = NotifyAddrChange(NULL,NULL); + if (Result != NO_ERROR) + { + if ( IsDebuggerPresent() ) { + sprintf(message, "NotifyAddrChange() failed with error %d \n", Result); + OutputDebugString(message); + } + break; + } #endif NumOfAddrs = GetNumOfIpAddrs(); if ( IsDebuggerPresent() ) { - char message[256]; sprintf(message,"IPAddrChangeMonitor() NumOfAddrs: now %d was %d\n", NumOfAddrs, prevNumOfAddrs); OutputDebugString(message); @@ -3520,11 +3536,6 @@ IpAddrChangeMonitor(void * hWnd) } prevNumOfAddrs = NumOfAddrs; } - -#ifdef USE_OVERLAPPED - if (Handle != INVALID_HANDLE_VALUE) - CloseHandle(Handle); -#endif }