--------------------- PatchSet 7943 Date: 2006/05/24 17:24:54 Author: serassio Branch: nt Tag: (none) Log: Ran indent Members: src/win32.c:1.7.8.3->1.7.8.4 Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.7.8.3 retrieving revision 1.7.8.4 diff -u -r1.7.8.3 -r1.7.8.4 --- squid/src/win32.c 22 May 2006 19:54:37 -0000 1.7.8.3 +++ squid/src/win32.c 24 May 2006 17:24:54 -0000 1.7.8.4 @@ -58,7 +58,7 @@ void WINAPI WIN32_svcHandler(DWORD); static int WIN32_StoreKey(const char *, DWORD, unsigned char *, int); static int WIN32_create_key(void); -static void WIN32_build_argv (char *); +static void WIN32_build_argv(char *); void WINAPI SquidMain(DWORD, char **); /* The following code section is part of an EXPERIMENTAL native */ @@ -74,8 +74,8 @@ static SERVICE_STATUS svcStatus; static SERVICE_STATUS_HANDLE svcHandle; static int WIN32_argc; -static char ** WIN32_argv; -static char * WIN32_module_name; +static char **WIN32_argv; +static char *WIN32_module_name; static int Squid_Aborting = 0; #define VENDOR "GNU" @@ -84,27 +84,32 @@ #else #define SOFTWARENAME "Squid" #endif -#define WIN32_VERSION "2.5" +#define WIN32_VERSION "2.6" #define COMMANDLINE "CommandLine" #define CONFIGFILE "ConfigFile" #undef ChangeServiceConfig2 -typedef BOOL (WINAPI * PFChangeServiceConfig2) (SC_HANDLE, DWORD, LPVOID); +typedef BOOL(WINAPI * PFChangeServiceConfig2) (SC_HANDLE, DWORD, LPVOID); #ifdef UNICODE #define CHANGESERVICECONFIG2 "ChangeServiceConfig2W" #else #define CHANGESERVICECONFIG2 "ChangeServiceConfig2A" #endif -static SC_ACTION Squid_SCAction[] = { { SC_ACTION_RESTART, 60000 } }; -static SERVICE_DESCRIPTION Squid_ServiceDescription = { SOFTWARENAME " " VERSION " WWW Proxy Server" }; -static SERVICE_FAILURE_ACTIONS Squid_ServiceFailureActions = { INFINITE, NULL, NULL, 1, Squid_SCAction }; -static char REGKEY[256]="SOFTWARE\\"VENDOR"\\"SOFTWARENAME"\\"WIN32_VERSION"\\"; -static char *keys[] = { - "SOFTWARE", /* key[0] */ - VENDOR, /* key[1] */ - SOFTWARENAME, /* key[2] */ - WIN32_VERSION, /* key[3] */ - NULL, /* key[4] */ - NULL /* key[5] */ +static SC_ACTION Squid_SCAction[] = +{ + {SC_ACTION_RESTART, 60000}}; +static SERVICE_DESCRIPTION Squid_ServiceDescription = +{SOFTWARENAME " " VERSION " WWW Proxy Server"}; +static SERVICE_FAILURE_ACTIONS Squid_ServiceFailureActions = +{INFINITE, NULL, NULL, 1, Squid_SCAction}; +static char REGKEY[256] = "SOFTWARE\\" VENDOR "\\" SOFTWARENAME "\\" WIN32_VERSION "\\"; +static char *keys[] = +{ + "SOFTWARE", /* key[0] */ + VENDOR, /* key[1] */ + SOFTWARENAME, /* key[2] */ + WIN32_VERSION, /* key[3] */ + NULL, /* key[4] */ + NULL /* key[5] */ }; /* ====================================================================== */ @@ -283,14 +288,15 @@ } /* Build argv, argc from string passed from Windows. */ -static void WIN32_build_argv(char *cmd) +static void +WIN32_build_argv(char *cmd) { int argvlen = 0; char *word; WIN32_argc = 1; - WIN32_argv = (char **) xmalloc ((WIN32_argc+1) * sizeof (char *)); - WIN32_argv[0]=xstrdup(WIN32_module_name); + WIN32_argv = (char **) xmalloc((WIN32_argc + 1) * sizeof(char *)); + WIN32_argv[0] = xstrdup(WIN32_module_name); /* Scan command line until there is nothing left. */ while (*cmd) { /* Ignore spaces */ @@ -306,11 +312,11 @@ break; } if (*cmd) - *cmd++ = '\0'; /* Terminate `word' */ + *cmd++ = '\0'; /* Terminate `word' */ /* See if we need to allocate more space for argv */ if (WIN32_argc >= argvlen) { argvlen = WIN32_argc + 1; - WIN32_argv = (char **) xrealloc (WIN32_argv, (1 + argvlen) * sizeof (char *)); + WIN32_argv = (char **) xrealloc(WIN32_argv, (1 + argvlen) * sizeof(char *)); } /* Add word to argv file. */ WIN32_argv[WIN32_argc++] = word; @@ -341,10 +347,10 @@ #endif #if USE_WIN32_SERVICE if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) { - if (!Squid_Aborting) { + if (!Squid_Aborting) { svcStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(svcHandle, &svcStatus); - } + } } #endif #ifdef _SQUID_MSWIN_ @@ -356,9 +362,11 @@ } #if USE_WIN32_SERVICE -int WIN32_Subsystem_Init(int * argc, char *** argv) +int +WIN32_Subsystem_Init(int *argc, char ***argv) #else -int WIN32_Subsystem_Init() +int +WIN32_Subsystem_Init() #endif { WIN32_OS_version = GetOSVersion(); @@ -380,7 +388,7 @@ return 1; /* Set Process work dir to directory cointaining squid.exe */ GetModuleFileName(NULL, path, 512); - WIN32_module_name=xstrdup(path); + WIN32_module_name = xstrdup(path); path[strlen(path) - 10] = '\0'; if (SetCurrentDirectory(path) == 0) return 1; @@ -433,7 +441,7 @@ #endif #ifdef _SQUID_MSWIN_ if (Win32SockInit() < 0) - return 1; + return 1; #endif return 0; } @@ -569,7 +577,7 @@ char ServicePath[512]; char szPath[512]; int lenpath; - + if (!WIN32_Service_name) WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME); strcat(REGKEY, WIN32_Service_name); @@ -583,27 +591,25 @@ NULL, /* database (NULL == default) */ SC_MANAGER_ALL_ACCESS /* access required */ ); - if (!schSCManager) { + if (!schSCManager) { fprintf(stderr, "OpenSCManager failed\n"); exit(1); - } - else { - schService = CreateService(schSCManager, /* SCManager database */ - WIN32_Service_name, /* name of service */ - WIN32_Service_name, /* name to display */ - SERVICE_ALL_ACCESS, /* desired access */ - SERVICE_WIN32_OWN_PROCESS, /* service type */ - SERVICE_AUTO_START, /* start type */ - SERVICE_ERROR_NORMAL, /* error control type */ - (const char *) szPath, /* service's binary */ - NULL, /* no load ordering group */ - NULL, /* no tag identifier */ - "Tcpip\0AFD\0", /* dependencies */ - NULL, /* LocalSystem account */ - NULL); /* no password */ + } else { + schService = CreateService(schSCManager, /* SCManager database */ + WIN32_Service_name, /* name of service */ + WIN32_Service_name, /* name to display */ + SERVICE_ALL_ACCESS, /* desired access */ + SERVICE_WIN32_OWN_PROCESS, /* service type */ + SERVICE_AUTO_START, /* start type */ + SERVICE_ERROR_NORMAL, /* error control type */ + (const char *) szPath, /* service's binary */ + NULL, /* no load ordering group */ + NULL, /* no tag identifier */ + "Tcpip\0AFD\0", /* dependencies */ + NULL, /* LocalSystem account */ + NULL); /* no password */ if (schService) { - if (WIN32_OS_version > _WIN_OS_WINNT) - { + if (WIN32_OS_version > _WIN_OS_WINNT) { HMODULE ADVAPI32Handle; PFChangeServiceConfig2 ChangeServiceConfig2; DWORD dwInfoLevel = SERVICE_CONFIG_DESCRIPTION; @@ -613,7 +619,7 @@ ChangeServiceConfig2(schService, dwInfoLevel, &Squid_ServiceDescription); dwInfoLevel = SERVICE_CONFIG_FAILURE_ACTIONS; ChangeServiceConfig2(schService, dwInfoLevel, &Squid_ServiceFailureActions); - } + } CloseServiceHandle(schService); /* Now store the config file location in the registry */ if (!ConfigFile) @@ -692,7 +698,7 @@ exit(1); } else { /* Send a control value to the service. */ - if (!ControlService(schService, /* handle of service */ + if (!ControlService(schService, /* handle of service */ fdwControl, /* control value to send */ &ssStatus)) { /* address of status info */ fprintf(stderr, "%s: ERROR: Could not Control Service %s\n", @@ -715,36 +721,38 @@ CloseServiceHandle(schSCManager); } -int main(int argc, char **argv) +int +main(int argc, char **argv) { - SERVICE_TABLE_ENTRY DispatchTable[] = { + SERVICE_TABLE_ENTRY DispatchTable[] = + { {NULL, SquidMain}, {NULL, NULL} }; char *c; char stderr_path[256]; - if ((argc == 2) && strstr(argv[1], _WIN_SQUID_SERVICE_OPTION)){ - strcpy(stderr_path, argv[0]); - strcat(stderr_path,".log"); - freopen(stderr_path, "w", stderr); - setmode(fileno(stderr), O_TEXT); + if ((argc == 2) && strstr(argv[1], _WIN_SQUID_SERVICE_OPTION)) { + strcpy(stderr_path, argv[0]); + strcat(stderr_path, ".log"); + freopen(stderr_path, "w", stderr); + setmode(fileno(stderr), O_TEXT); WIN32_run_mode = _WIN_SQUID_RUN_MODE_SERVICE; - if (!(c=strchr(argv[1],':'))){ + if (!(c = strchr(argv[1], ':'))) { fprintf(stderr, "Bad Service Parameter: %s\n", argv[1]); return 1; } - WIN32_Service_name = xstrdup(c+1); - DispatchTable[0].lpServiceName=WIN32_Service_name; + WIN32_Service_name = xstrdup(c + 1); + DispatchTable[0].lpServiceName = WIN32_Service_name; strcat(REGKEY, WIN32_Service_name); keys[4] = WIN32_Service_name; - if (!StartServiceCtrlDispatcher(DispatchTable)) { + if (!StartServiceCtrlDispatcher(DispatchTable)) { fprintf(stderr, "StartServiceCtrlDispatcher error = %ld\n", GetLastError()); return 1; } } else { - WIN32_run_mode = _WIN_SQUID_RUN_MODE_INTERACTIVE; + WIN32_run_mode = _WIN_SQUID_RUN_MODE_INTERACTIVE; SquidMain(argc, argv); } return 0; @@ -757,11 +765,12 @@ #if defined(_SQUID_MSWIN_) static int s_iInitCount = 0; -int WIN32_pipe(int handles[2]) +int +WIN32_pipe(int handles[2]) { int new_socket; fde *F = NULL; - + struct sockaddr_in serv_addr; int len = sizeof(serv_addr); u_short handle1_port; @@ -770,7 +779,7 @@ statCounter.syscalls.sock.sockets++; if ((new_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) - return -1; + return -1; memset((void *) &serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; @@ -779,16 +788,13 @@ if (bind(new_socket, (SOCKADDR *) & serv_addr, len) < 0 || listen(new_socket, 1) < 0 || getsockname(new_socket, (SOCKADDR *) & serv_addr, &len) < 0 || - (handles[1] = socket(PF_INET, SOCK_STREAM, 0)) < 0) - { + (handles[1] = socket(PF_INET, SOCK_STREAM, 0)) < 0) { closesocket(new_socket); return -1; } - handle1_port = ntohs(serv_addr.sin_port); if (connect(handles[1], (SOCKADDR *) & serv_addr, len) < 0 || - (handles[0] = accept(new_socket, (SOCKADDR *) & serv_addr, &len)) < 0) - { + (handles[0] = accept(new_socket, (SOCKADDR *) & serv_addr, &len)) < 0) { closesocket(handles[1]); handles[1] = -1; closesocket(new_socket); @@ -808,55 +814,50 @@ return 0; } -int WIN32_getrusage(int who, struct rusage *usage) +int +WIN32_getrusage(int who, struct rusage *usage) { #if HAVE_WIN32_PSAPI if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K) - || (WIN32_OS_version == _WIN_OS_WINXP) || (WIN32_OS_version == _WIN_OS_WINNET)) - { - /* On Windows NT/2000 call PSAPI.DLL for process Memory */ - /* informations -- Guido Serassio */ - HANDLE hProcess; - PROCESS_MEMORY_COUNTERS pmc; + || (WIN32_OS_version == _WIN_OS_WINXP) || (WIN32_OS_version == _WIN_OS_WINNET)) { + /* On Windows NT/2000 call PSAPI.DLL for process Memory */ + /* informations -- Guido Serassio */ + HANDLE hProcess; + PROCESS_MEMORY_COUNTERS pmc; hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId()); { - /* Microsoft CRT doesn't have getrusage function, */ - /* so we get process CPU time information from PSAPI.DLL. */ + /* Microsoft CRT doesn't have getrusage function, */ + /* so we get process CPU time information from PSAPI.DLL. */ FILETIME ftCreate, ftExit, ftKernel, ftUser; - if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) - { - int64_t tUser64 = (*(int64_t *)&ftUser / 10); - int64_t tKernel64 = (*(int64_t *)&ftKernel / 10); - usage->ru_utime.tv_sec =(long)(tUser64 / 1000000); - usage->ru_stime.tv_sec =(long)(tKernel64 / 1000000); - usage->ru_utime.tv_usec =(long)(tUser64 % 1000000); - usage->ru_stime.tv_usec =(long)(tKernel64 % 1000000); - } - else - { - CloseHandle( hProcess ); + if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) { + int64_t tUser64 = (*(int64_t *) & ftUser / 10); + int64_t tKernel64 = (*(int64_t *) & ftKernel / 10); + usage->ru_utime.tv_sec = (long) (tUser64 / 1000000); + usage->ru_stime.tv_sec = (long) (tKernel64 / 1000000); + usage->ru_utime.tv_usec = (long) (tUser64 % 1000000); + usage->ru_stime.tv_usec = (long) (tKernel64 % 1000000); + } else { + CloseHandle(hProcess); return -1; } } - if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) - { - usage->ru_maxrss=(DWORD)(pmc.WorkingSetSize / getpagesize()); - usage->ru_majflt=pmc.PageFaultCount; - } - else - { - CloseHandle( hProcess ); + if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) { + usage->ru_maxrss = (DWORD) (pmc.WorkingSetSize / getpagesize()); + usage->ru_majflt = pmc.PageFaultCount; + } else { + CloseHandle(hProcess); return -1; } - CloseHandle( hProcess ); + CloseHandle(hProcess); } #endif return 0; } -static int Win32SockInit(void) +static int +Win32SockInit(void) { int iVersionRequested; WSADATA wsaData; @@ -867,8 +868,7 @@ if (s_iInitCount > 0) { s_iInitCount++; return (0); - } - else if (s_iInitCount < 0) + } else if (s_iInitCount < 0) return (s_iInitCount); /* s_iInitCount == 0. Do the initailization */ iVersionRequested = MAKEWORD(2, 0); @@ -883,67 +883,71 @@ WSACleanup(); return (s_iInitCount); } - if (WIN32_OS_version !=_WIN_OS_WINNT) { - if (getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&opt, &optlen)) { + if (WIN32_OS_version != _WIN_OS_WINNT) { + if (getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &opt, &optlen)) { s_iInitCount = -3; WSACleanup(); return (s_iInitCount); - } else { - opt = opt | SO_SYNCHRONOUS_NONALERT; - if (setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &opt, optlen)) { - s_iInitCount = -3; - WSACleanup(); - return (s_iInitCount); - } - } + } else { + opt = opt | SO_SYNCHRONOUS_NONALERT; + if (setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &opt, optlen)) { + s_iInitCount = -3; + WSACleanup(); + return (s_iInitCount); + } + } } WIN32_Socks_initialized = 1; s_iInitCount++; return (s_iInitCount); } -static void Win32SockCleanup(void) +static void +Win32SockCleanup(void) { if (--s_iInitCount == 0) WSACleanup(); return; } -LONG CALLBACK WIN32_ExceptionHandler(EXCEPTION_POINTERS* ep) +LONG CALLBACK +WIN32_ExceptionHandler(EXCEPTION_POINTERS * ep) { - EXCEPTION_RECORD* er; + EXCEPTION_RECORD *er; er = ep->ExceptionRecord; switch (er->ExceptionCode) { - case EXCEPTION_ACCESS_VIOLATION: - raise(SIGSEGV); - break; - case EXCEPTION_DATATYPE_MISALIGNMENT: - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: - case EXCEPTION_IN_PAGE_ERROR: - death(SIGBUS); - break; - default: - break; + case EXCEPTION_ACCESS_VIOLATION: + raise(SIGSEGV); + break; + case EXCEPTION_DATATYPE_MISALIGNMENT: + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + case EXCEPTION_IN_PAGE_ERROR: + death(SIGBUS); + break; + default: + break; } return EXCEPTION_CONTINUE_SEARCH; } -void WIN32_ExceptionHandlerInit() +void +WIN32_ExceptionHandlerInit() { #if !defined(_DEBUG) if (Win32_Old_ExceptionHandler == NULL) - Win32_Old_ExceptionHandler = SetUnhandledExceptionFilter(WIN32_ExceptionHandler); + Win32_Old_ExceptionHandler = SetUnhandledExceptionFilter(WIN32_ExceptionHandler); #endif } -void WIN32_ExceptionHandlerCleanup() +void +WIN32_ExceptionHandlerCleanup() { if (Win32_Old_ExceptionHandler != NULL) - SetUnhandledExceptionFilter(Win32_Old_ExceptionHandler); + SetUnhandledExceptionFilter(Win32_Old_ExceptionHandler); } #endif /* End native Windows NT EXPERIMENTAL PORT */