--------------------- PatchSet 3243 Date: 2001/10/21 19:30:25 Author: serassio Branch: cygwin Tag: (none) Log: Changed PSAPI code and Windows OS defines Members: configure.in:1.8.2.21->1.8.2.22 src/defines.h:1.3.22.15->1.3.22.16 src/enums.h:1.6.10.6->1.6.10.7 src/protos.h:1.9.2.18->1.9.2.19 src/tools.c:1.7.2.20->1.7.2.21 src/win32.c:1.1.50.14->1.1.50.15 Index: squid/configure.in =================================================================== RCS file: /cvsroot/squid-sf//squid/configure.in,v retrieving revision 1.8.2.21 retrieving revision 1.8.2.22 diff -u -r1.8.2.21 -r1.8.2.22 --- squid/configure.in 19 Oct 2001 19:35:03 -0000 1.8.2.21 +++ squid/configure.in 21 Oct 2001 19:30:25 -0000 1.8.2.22 @@ -3,7 +3,7 @@ dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.8.2.21 2001/10/19 19:35:03 serassio Exp $ +dnl $Id: configure.in,v 1.8.2.22 2001/10/21 19:30:25 serassio Exp $ dnl dnl dnl @@ -11,7 +11,7 @@ AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE(Squid, 2.5-DEVEL) AM_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.8.2.21 $)dnl +AC_REVISION($Revision: 1.8.2.22 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -60,7 +60,7 @@ ;; esac -dnl check for PSAPI.DLL on cygwin32 platform and add win32.o to squid objects +dnl Check for PSAPI.DLL on cygwin32 platform case "$host_os" in cygwin|cygwin32) AC_PATH_PROG(WIN32_PSAPI, psapi.dll, none) Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.3.22.15 retrieving revision 1.3.22.16 diff -u -r1.3.22.15 -r1.3.22.16 --- squid/src/defines.h 19 Oct 2001 19:05:10 -0000 1.3.22.15 +++ squid/src/defines.h 21 Oct 2001 19:30:25 -0000 1.3.22.16 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.3.22.15 2001/10/19 19:05:10 serassio Exp $ + * $Id: defines.h,v 1.3.22.16 2001/10/21 19:30:25 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -302,14 +302,6 @@ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) #define _WIN_HOSTS_FILENAME "\\hosts" #define _WIN95_NETWORK_DB_HOSTS "%WINDIR%" -#define _WIN_OS_UNKNOWN 0 -#define _WIN_OS_WIN32S 1 -#define _WIN_OS_WIN95 2 -#define _WIN_OS_WIN98 3 -#define _WIN_OS_WINME 4 -#define _WIN_OS_WINNT 5 -#define _WIN_OS_WIN2K 6 -#define _WIN_OS_WINXP 7 #endif #endif /* SQUID_DEFINES_H */ Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.6.10.6 retrieving revision 1.6.10.7 diff -u -r1.6.10.6 -r1.6.10.7 --- squid/src/enums.h 19 Oct 2001 19:05:10 -0000 1.6.10.6 +++ squid/src/enums.h 21 Oct 2001 19:30:25 -0000 1.6.10.7 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.6.10.6 2001/10/19 19:05:10 serassio Exp $ + * $Id: enums.h,v 1.6.10.7 2001/10/21 19:30:25 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -727,4 +727,21 @@ VARY_CANCEL }; +/* CygWin & Windows NT Port */ +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) +/* + * Supported Windows OS types codes + */ +enum { + _WIN_OS_UNKNOWN, + _WIN_OS_WIN32S, + _WIN_OS_WIN95, + _WIN_OS_WIN98, + _WIN_OS_WINME, + _WIN_OS_WINNT, + _WIN_OS_WIN2K, + _WIN_OS_WINXP +}; +#endif + #endif /* SQUID_ENUMS_H */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.9.2.18 retrieving revision 1.9.2.19 diff -u -r1.9.2.18 -r1.9.2.19 --- squid/src/protos.h 20 Oct 2001 08:16:18 -0000 1.9.2.18 +++ squid/src/protos.h 21 Oct 2001 19:30:25 -0000 1.9.2.19 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.9.2.18 2001/10/20 08:16:18 serassio Exp $ + * $Id: protos.h,v 1.9.2.19 2001/10/21 19:30:25 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1318,6 +1318,7 @@ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) extern int WIN32_Subsystem_Init(void); extern void WIN32_Exit(void); +extern int WIN32_getrusage(int, struct rusage *); #endif #endif /* SQUID_PROTOS_H */ Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.7.2.20 retrieving revision 1.7.2.21 diff -u -r1.7.2.20 -r1.7.2.21 --- squid/src/tools.c 20 Oct 2001 08:33:18 -0000 1.7.2.20 +++ squid/src/tools.c 21 Oct 2001 19:30:25 -0000 1.7.2.21 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.7.2.20 2001/10/20 08:33:18 serassio Exp $ + * $Id: tools.c,v 1.7.2.21 2001/10/21 19:30:25 serassio Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -34,10 +34,15 @@ */ #include "squid.h" -#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) -#include -#include -#include + +/* + Temporary hack to fix Cygwin lacks of process + memory informations + + */ +#if defined(_SQUID_CYGWIN_) +#undef getrusage +#define getrusage WIN32_getrusage #endif #define DEAD_MSG "\ @@ -181,45 +186,10 @@ /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */ enter_suid(); #endif -#ifndef _SQUID_MSWIN_ getrusage(RUSAGE_SELF, r); -#endif #ifdef _SQUID_SOLARIS_ leave_suid(); #endif -#if HAVE_WIN32_PSAPI && (defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)) - if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K) - || (WIN32_OS_version == _WIN_OS_WINXP)) - { - /* 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()); -#if defined (_SQUID_MSWIN_) - { - /* Microsoft Visual C++ 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)) - { - LONGLONG tUser64 = *(LONGLONG *)&ftUser; - LONGLONG tKernel64 = *(LONGLONG *)&ftKernel; - r->ru_utime.tv_usec =(DWORD)(tUser64 / 10); - r->ru_stime.tv_usec =(DWORD)(tKernel64 / 10); - } - } -#endif - if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) - { - r->ru_maxrss=(DWORD)(pmc.WorkingSetSize /1024); - r->ru_majflt=pmc.PageFaultCount; - } - CloseHandle( hProcess ); - } -#endif #endif } Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.1.50.14 retrieving revision 1.1.50.15 diff -u -r1.1.50.14 -r1.1.50.15 --- squid/src/win32.c 20 Oct 2001 10:42:44 -0000 1.1.50.14 +++ squid/src/win32.c 21 Oct 2001 19:30:25 -0000 1.1.50.15 @@ -22,11 +22,16 @@ * */ +#ifndef WIN32_C +#define WIN32_C + #include "squid.h" /* This code compiles only CygWin & Windows NT Port */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) #include +#include +#include static unsigned int GetOSVersion(); static void Set_sys_network_db_hosts(); @@ -152,5 +157,58 @@ Set_sys_network_db_hosts(); return 0; } + +int WIN32_getrusage(int who, struct rusage *usage) +{ +#ifdef _SQUID_CYGWIN_ + getrusage(who, usage); #endif +#if HAVE_WIN32_PSAPI + if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K) + || (WIN32_OS_version == _WIN_OS_WINXP)) + { + /* 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()); +#if defined (_SQUID_MSWIN_) + { + /* Microsoft Visual C++ 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)) + { + LONGLONG tUser64 = *(LONGLONG *)&ftUser; + LONGLONG tKernel64 = *(LONGLONG *)&ftKernel; + usage->ru_utime.tv_usec =(DWORD)(tUser64 / 10); + usage->ru_stime.tv_usec =(DWORD)(tKernel64 / 10); + } + else + { + CloseHandle( hProcess ); + return -1; + } + } +#endif + if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) + { + usage->ru_maxrss=(DWORD)(pmc.WorkingSetSize /1024); + usage->ru_majflt=pmc.PageFaultCount; + } + else + { + CloseHandle( hProcess ); + return -1; + } + CloseHandle( hProcess ); + } +#endif + return 0; +} +#endif + +#endif /* WIN32_C */