From a2f326687951cb7af2284c49992bcdd8dc7d385b Mon Sep 17 00:00:00 2001 From: serassio <> Date: Sun, 17 Feb 2008 18:37:52 +0000 Subject: [PATCH] Merged changes from SQUID_3_0 --- src/WinSvc.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/main.cc | 6 ++++- src/protos.h | 6 ++--- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/WinSvc.cc b/src/WinSvc.cc index 1d2fab2e02..c1a9534be4 100755 --- a/src/WinSvc.cc +++ b/src/WinSvc.cc @@ -1,6 +1,6 @@ /* - * $Id: WinSvc.cc,v 1.3 2007/04/28 22:26:37 hno Exp $ + * $Id: WinSvc.cc,v 1.3.6.1 2008/02/17 11:37:52 serassio Exp $ * * Windows support * AUTHOR: Guido Serassio @@ -69,6 +69,11 @@ static int s_iInitCount = 0; #endif static int Squid_Aborting = 0; +static HANDLE NotifyAddrChange_thread = INVALID_HANDLE_VALUE; + +#undef NotifyAddrChange +typedef DWORD(WINAPI * PFNotifyAddrChange) (OUT PHANDLE, IN LPOVERLAPPED); +#define NOTIFYADDRCHANGE "NotifyAddrChange" #if USE_WIN32_SERVICE static SERVICE_STATUS svcStatus; @@ -385,6 +390,17 @@ WIN32_Abort(int sig) 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() { @@ -406,12 +422,57 @@ WIN32_Exit() DeleteCriticalSection(dbg_mutex); WIN32_ExceptionHandlerCleanup(); + WIN32_IpAddrChangeMonitorExit(); #endif _exit(0); } +#ifdef _SQUID_MSWIN_ +static DWORD WINAPI +WIN32_IpAddrChangeMonitor(LPVOID lpParam) +{ + DWORD Result; + HMODULE IPHLPAPIHandle; + PFNotifyAddrChange NotifyAddrChange; + + if ((IPHLPAPIHandle = GetModuleHandle("IPHLPAPI")) == NULL) + IPHLPAPIHandle = LoadLibrary("IPHLPAPI"); + NotifyAddrChange = (PFNotifyAddrChange) GetProcAddress(IPHLPAPIHandle, NOTIFYADDRCHANGE); + + while (1) { + Result = NotifyAddrChange(NULL, NULL); + if (Result != NO_ERROR) { + debugs(1, 1, "NotifyAddrChange error " << Result); + return 1; + } + debugs(1, 1, "Notification of IP address change received, requesting Squid reconfiguration ..."); + reconfigure(SIGHUP); + } + return 0; +} + +DWORD +WIN32_IpAddrChangeMonitorInit() +{ + DWORD status = ERROR_SUCCESS; + DWORD threadID = 0, ThrdParam = 0; + + 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; + debugs(1, 1, "Failed to start IP monitor thread."); + } else + debugs(1, 2, "Starting IP monitor thread [" << threadID << "] ..."); + } + return status; +} +#endif + int WIN32_Subsystem_Init(int * argc, char *** argv) { #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ diff --git a/src/main.cc b/src/main.cc index cd3f631f75..5c363d4f02 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.451 2007/12/02 08:23:56 amosjeffries Exp $ + * $Id: main.cc,v 1.451.4.1 2008/02/17 11:37:52 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -826,6 +826,10 @@ mainInitialize(void) if (WIN32_Socks_initialized) debugs(1, 1, "Windows sockets initialized"); + if (WIN32_OS_version > _WIN_OS_WINNT) { + WIN32_IpAddrChangeMonitorInit(); + } + #endif if (!configured_once) diff --git a/src/protos.h b/src/protos.h index 333463e3bc..e5b5642af8 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.550 2007/09/28 00:22:38 hno Exp $ + * $Id: protos.h,v 1.550.4.1 2008/02/17 11:37:52 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -771,8 +771,8 @@ SQUIDCEXTERN int WIN32_pipe(int[2]); SQUIDCEXTERN int WIN32_getrusage(int, struct rusage *); SQUIDCEXTERN void WIN32_ExceptionHandlerInit(void); -SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set - ); +SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set); +SQUIDCEXTERN DWORD WIN32_IpAddrChangeMonitorInit(); #endif -- 2.47.2