--------------------- PatchSet 10311 Date: 2007/12/25 16:02:19 Author: serassio Branch: nt Tag: (none) Log: Handle notification of IP address changes for dial-up connections - revised code Members: src/main.c:1.45.2.35->1.45.2.36 src/protos.h:1.74.2.57->1.74.2.58 src/win32.c:1.7.8.22->1.7.8.23 Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.45.2.35 retrieving revision 1.45.2.36 diff -u -r1.45.2.35 -r1.45.2.36 --- squid/src/main.c 25 Nov 2007 08:40:27 -0000 1.45.2.35 +++ squid/src/main.c 25 Dec 2007 16:02:19 -0000 1.45.2.36 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.45.2.35 2007/11/25 08:40:27 serassio Exp $ + * $Id: main.c,v 1.45.2.36 2007/12/25 16:02:19 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -569,6 +569,9 @@ debug(1, 1) ("With %d CRT stdio descriptors available\n", _getmaxstdio()); if (WIN32_Socks_initialized) debug(1, 1) ("Windows sockets initialized\n"); + if (WIN32_OS_version > _WIN_OS_WINNT) { + WIN32_IpAddrChangeMonitorInit(); + } #endif comm_select_postinit(); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.74.2.57 retrieving revision 1.74.2.58 diff -u -r1.74.2.57 -r1.74.2.58 --- squid/src/protos.h 25 Dec 2007 15:37:57 -0000 1.74.2.57 +++ squid/src/protos.h 25 Dec 2007 16:02:19 -0000 1.74.2.58 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.74.2.57 2007/12/25 15:37:57 serassio Exp $ + * $Id: protos.h,v 1.74.2.58 2007/12/25 16:02:19 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1414,6 +1414,9 @@ extern int WIN32_getrusage(int, struct rusage *); extern void WIN32_ExceptionHandlerInit(void); extern int SquidMain(int, char **); +#ifdef _SQUID_MSWIN_ +extern DWORD WIN32_IpAddrChangeMonitorInit(); +#endif #endif /* external_acl.c */ Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.7.8.22 retrieving revision 1.7.8.23 diff -u -r1.7.8.22 -r1.7.8.23 --- squid/src/win32.c 16 Dec 2007 19:32:31 -0000 1.7.8.22 +++ squid/src/win32.c 25 Dec 2007 16:02:19 -0000 1.7.8.23 @@ -67,6 +67,7 @@ extern LPCRITICAL_SECTION dbg_mutex; void WIN32_ExceptionHandlerCleanup(void); static LPTOP_LEVEL_EXCEPTION_FILTER Win32_Old_ExceptionHandler = NULL; +static HANDLE NotifyAddrChange_thread = INVALID_HANDLE_VALUE; #endif /* _SQUID_MSWIN_ */ #if USE_WIN32_SERVICE @@ -361,6 +362,17 @@ WIN32_Exit(); } +void +WIN32_IpAddrChangeMonitorExit() +{ + DWORD status = ERROR_SUCCESS; + + if (NotifyAddrChange_thread == INVALID_HANDLE_VALUE) { + TerminateThread(NotifyAddrChange_thread, status); + CloseHandle(NotifyAddrChange_thread); + } +} + void WIN32_Exit() { @@ -379,10 +391,12 @@ if (dbg_mutex) DeleteCriticalSection(dbg_mutex); WIN32_ExceptionHandlerCleanup(); + WIN32_IpAddrChangeMonitorExit(); #endif _exit(0); } +#ifdef _SQUID_MSWIN_ static DWORD WINAPI WIN32_IpAddrChangeMonitor(LPVOID lpParam) { @@ -390,16 +404,17 @@ HMODULE IPHLPAPIHandle; PFNotifyAddrChange NotifyAddrChange; - IPHLPAPIHandle = GetModuleHandle("IPHLPAPI"); + if ((IPHLPAPIHandle = GetModuleHandle("IPHLPAPI")) == NULL) + IPHLPAPIHandle = LoadLibrary("IPHLPAPI"); NotifyAddrChange = (PFNotifyAddrChange) GetProcAddress(IPHLPAPIHandle, NOTIFYADDRCHANGE); - while (TRUE) { + while (1) { Result = NotifyAddrChange(NULL, NULL); if (Result != NO_ERROR) { debug(1, 1) ("NotifyAddrChange error %ld\n", Result); return 1; } - debug(1, 1) ("Notification of IP address change received, reconfiguring Squid ...\n"); + debug(1, 1) ("Notification of IP address change received, requesting Squid reconfiguration ...\n"); reconfigure(SIGHUP); } return 0; @@ -409,17 +424,21 @@ WIN32_IpAddrChangeMonitorInit() { DWORD status = ERROR_SUCCESS; - HANDLE thread; - ULONG threadID = 0; + DWORD threadID = 0, ThrdParam = 0; - thread = CreateThread(NULL, 0, WIN32_IpAddrChangeMonitor, - NULL, 0, &threadID); - if (thread == NULL) { - status = GetLastError(); + if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) { + NotifyAddrChange_thread = CreateThread(NULL, 0, WIN32_IpAddrChangeMonitor, + &ThrdParam, 0, &threadID); + if (NotifyAddrChange_thread == NULL) { + status = GetLastError(); + NotifyAddrChange_thread = INVALID_HANDLE_VALUE; + debug(1, 1) ("Failed to start IP monitor thread.\n"); + } else + debug(1, 2) ("Starting IP monitor thread [%li] ...\n", threadID); } - CloseHandle(thread); return status; } +#endif int WIN32_Subsystem_Init(int *argc, char ***argv) @@ -497,10 +516,6 @@ #ifdef _SQUID_MSWIN_ if (Win32SockInit() < 0) return 1; - if (WIN32_OS_version > _WIN_OS_WINNT) { - if (WIN32_IpAddrChangeMonitorInit() != ERROR_SUCCESS) - return 1; - } #endif return 0; }