--------------------- PatchSet 2539 Date: 2001/06/14 21:57:53 Author: serassio Branch: cygwin-svc Tag: (none) Log: Added Windows NT code specific from SquidNT 2.3.4 Members: include/config.h.in:1.3.28.1.2.1->1.3.28.1.2.2 src/main.c:1.12.2.12.2.1->1.12.2.12.2.2 src/win32.c:1.1.50.6.2.1->1.1.50.6.2.2 Index: squid/include/config.h.in =================================================================== RCS file: /cvsroot/squid-sf//squid/include/Attic/config.h.in,v retrieving revision 1.3.28.1.2.1 retrieving revision 1.3.28.1.2.2 diff -u -r1.3.28.1.2.1 -r1.3.28.1.2.2 --- squid/include/config.h.in 3 Jun 2001 13:24:40 -0000 1.3.28.1.2.1 +++ squid/include/config.h.in 14 Jun 2001 21:57:53 -0000 1.3.28.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: config.h.in,v 1.3.28.1.2.1 2001/06/03 13:24:40 serassio Exp $ + * $Id: config.h.in,v 1.3.28.1.2.2 2001/06/14 21:57:53 serassio Exp $ * * AUTHOR: Duane Wessels * @@ -108,9 +108,16 @@ #define _SQUID_MSWIN_ /* Some tricks for MS Compilers */ +#define chdir _chdir +#define getcwd _getcwd +#define getpid _getpid +#define mkdir _mkdir #define setmode _setmode -#define O_TEXT _O_TEXT +#define umask _umask #define O_BYNARY _O_BINARY +#define O_TEXT _O_TEXT +#define S_IRWXO _S_IREAD | _S_IWRITE | _S_IEXEC +#define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR) #elif defined(__APPLE__) #define _SQUID_APPLE_ Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.12.2.12.2.1 retrieving revision 1.12.2.12.2.2 diff -u -r1.12.2.12.2.1 -r1.12.2.12.2.2 --- squid/src/main.c 2 Jun 2001 12:32:41 -0000 1.12.2.12.2.1 +++ squid/src/main.c 14 Jun 2001 21:57:53 -0000 1.12.2.12.2.2 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.12.2.12.2.1 2001/06/02 12:32:41 serassio Exp $ + * $Id: main.c,v 1.12.2.12.2.2 2001/06/14 21:57:53 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -456,11 +456,10 @@ static void setEffectiveUser(void) { -#if !(defined(USE_WIN32_SERVICE) && (defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_))) leave_suid(); /* Run as non privilegied user */ -#ifdef _SQUID_OS2_ +#if defined(_SQUID_OS2_) || defined(_SQUID_MSWIN_) return; -#endif +#else if (geteuid() == 0) { debug(0, 0) ("Squid is not safe to run as root! If you must\n"); debug(0, 0) ("start Squid as root, then you must configure\n"); @@ -632,9 +631,6 @@ int n; /* # of GC'd objects */ time_t loop_delay; mode_t oldmask; -#if !defined(USE_WIN32_SERVICE) && (defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)) - int WIN32_init_err; -#endif debug_log = stderr; if (FD_SETSIZE < Squid_MaxFD) @@ -646,8 +642,11 @@ return; /* opt_no_daemon=(WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) ? 0 : 1; */ #else - if ((WIN32_init_err = WIN32_Subsystem_Init())) - return WIN32_init_err; + { + int WIN32_init_err; + if ((WIN32_init_err = WIN32_Subsystem_Init())) + return WIN32_init_err; + } #endif #endif @@ -689,7 +688,6 @@ squid_start = current_time; failure_notify = fatal_dump; - #if defined(USE_WIN32_SERVICE) && (defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)) WIN32_svcstatusupdate(SERVICE_START_PENDING); #endif Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.1.50.6.2.1 retrieving revision 1.1.50.6.2.2 diff -u -r1.1.50.6.2.1 -r1.1.50.6.2.2 --- squid/src/win32.c 2 Jun 2001 12:32:41 -0000 1.1.50.6.2.1 +++ squid/src/win32.c 14 Jun 2001 21:57:53 -0000 1.1.50.6.2.2 @@ -33,12 +33,22 @@ static int WIN32_StoreKey(const char *, DWORD, unsigned char *, int); static int WIN32_create_key(void); void WINAPI SquidMain(DWORD, char **); +/* The following code section is part of an EXPERIMENTAL native */ +/* Windows NT/2000 Squid port - Compiles only on MS Visual C++ */ +#if defined(_SQUID_MSWIN_) +static int Win32SockInit(void); +static void Win32SockCleanup(void); +#endif /* End native Windows NT EXPERIMENTAL PORT */ static SERVICE_STATUS svcStatus; static SERVICE_STATUS_HANDLE svcHandle; #define VENDOR "GNU" +#if defined(_SQUID_MSWIN_) +#define SOFTWARE "SquidNT" +#else #define SOFTWARE "Squid" +#endif #define VERSION "2.5" #define REGKEY "SOFTWARE\\" VENDOR "\\" SOFTWARE "\\" VERSION @@ -213,6 +223,9 @@ VOID WIN32_Exit(int ExitStatus) { +#ifdef _SQUID_MSWIN_ + Win32SockCleanup(); +#endif #ifdef USE_WIN32_SERVICE if (ExitStatus) { svcStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; @@ -273,6 +286,9 @@ SetServiceStatus(svcHandle, &svcStatus); } #endif +#ifdef _SQUID_MSWIN_ + Win32SockInit(); +#endif return 0; } @@ -553,4 +569,48 @@ return 0; } #endif + +/* The following code section is part of an EXPERIMENTAL native */ +/* Windows NT/2000 Squid port - Compiles only on MS Visual C++ */ + +#if defined(_SQUID_MSWIN_) +static int s_iInitCount = 0; + +static int Win32SockInit(void) +{ + int iVersionRequested; + WSADATA wsaData; + int err; + + if (s_iInitCount > 0) { + s_iInitCount++; + return (0); + } + else if (s_iInitCount < 0) + return (s_iInitCount); + /* s_iInitCount == 0. Do the initailization */ + iVersionRequested = MAKEWORD(2, 0); + err = WSAStartup((WORD) iVersionRequested, &wsaData); + if (err) { + s_iInitCount = -1; + return (s_iInitCount); + } + if (LOBYTE(wsaData.wVersion) != 2 || + HIBYTE(wsaData.wVersion) != 0) { + s_iInitCount = -2; + WSACleanup(); + return (s_iInitCount); + } + debug(1,1)("Windows sockets initialised"); + s_iInitCount++; + return (s_iInitCount); +} + +static void Win32SockCleanup(void) +{ + if (--s_iInitCount == 0) + WSACleanup(); + return; +} +#endif /* End native Windows NT EXPERIMENTAL PORT */ #endif