---------------------
PatchSet 3296 
Date: 2001/11/01 17:31:07
Author: serassio
Branch: nt-2_3
Tag: (none) 
Log:
Added getrusage() emulation using PSAPI.DLL & synced code with Cygwin branch

Members: 
	include/autoconf.h:1.1.2.8->1.1.2.9 
	include/config.h:1.1.2.7->1.1.2.8 
	include/squid-mswin.h:1.1.2.4->1.1.2.5 
	src/defines.h:1.1.1.3.4.2.2.5->1.1.1.3.4.2.2.6 
	src/enums.h:1.1.1.3.4.2.2.1->1.1.1.3.4.2.2.2 
	src/protos.h:1.1.1.3.4.1.2.8->1.1.1.3.4.1.2.9 
	src/tools.c:1.1.1.3.4.1.2.11->1.1.1.3.4.1.2.12 
	src/win32.c:1.1.2.7->1.1.2.8 

Index: squid/include/autoconf.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/include/Attic/autoconf.h,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- squid/include/autoconf.h	12 Sep 2001 20:21:15 -0000	1.1.2.8
+++ squid/include/autoconf.h	1 Nov 2001 17:31:07 -0000	1.1.2.9
@@ -93,7 +93,7 @@
  * Traffic management via "delay pools".
  */
 #undef DELAY_POOLS
-//#define DELAY_POOLS 1
+#define DELAY_POOLS 1
 
 /*
  * If you want to log User-Agent request header values, define this.
@@ -222,7 +222,7 @@
 #undef HAVE_SETRESUID
 
 /* Define if you have struct rusage */
-#undef HAVE_STRUCT_RUSAGE
+#define HAVE_STRUCT_RUSAGE 1
 
 /* Define if you have PSAPI.DLL on Windows systems */
 #define HAVE_WIN32_PSAPI 1
@@ -284,6 +284,7 @@
  * the dnsserver processes instead.
  */
 #undef USE_DNSSERVERS
+// #define USE_DNSSERVERS 1
 /*
  * we check for the existance of struct mallinfo
  */
@@ -340,7 +341,6 @@
 #undef HAVE_GETRLIMIT
 
 /* Define if you have the getrusage function.  */
-#undef HAVE_GETRUSAGE
 #define HAVE_GETRUSAGE 1
 
 /* Define if you have the getspnam function.  */
Index: squid/include/squid-mswin.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/include/Attic/squid-mswin.h,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- squid/include/squid-mswin.h	15 Sep 2001 12:15:19 -0000	1.1.2.4
+++ squid/include/squid-mswin.h	1 Nov 2001 17:31:07 -0000	1.1.2.5
@@ -1,5 +1,5 @@
 /*
- * $Id: squid-mswin.h,v 1.1.2.4 2001/09/15 12:15:19 serassio Exp $
+ * $Id: squid-mswin.h,v 1.1.2.5 2001/11/01 17:31:07 serassio Exp $
  *
  * AUTHOR: Guido Serassio & Andrey Shorin
  *
@@ -48,6 +48,7 @@
 #define getcwd _getcwd
 #define getpid _getpid
 #define geteuid() 100
+#define getrusage WIN32_getrusage
 #define lseek _lseeki64
 #define memccpy _memccpy
 #define mkdir(p,m) _mkdir(p)
@@ -121,6 +122,7 @@
 #endif
 
 #include <stddef.h>
+#include <process.h>
 /* prevent inclusion of wingdi.h */
 #define NOGDI
 #include <ws2spi.h>
@@ -180,3 +182,25 @@
 #define ignoreErrno(x) WSAignoreErrno(x)
 #define commSetSelect(x,y,z,u,v) commSetSelectS(x,y,z,u,v)
 #endif
+
+#define	RUSAGE_SELF	0		/* calling process */
+#define	RUSAGE_CHILDREN	-1		/* terminated child processes */
+
+struct rusage {
+	struct timeval ru_utime;	/* user time used */
+	struct timeval ru_stime;	/* system time used */
+	long ru_maxrss;			/* integral max resident set size */
+	long ru_ixrss;			/* integral shared text memory size */
+	long ru_idrss;			/* integral unshared data size */
+	long ru_isrss;			/* integral unshared stack size */
+	long ru_minflt;			/* page reclaims */
+	long ru_majflt;			/* page faults */
+	long ru_nswap;			/* swaps */
+	long ru_inblock;		/* block input operations */
+	long ru_oublock;		/* block output operations */
+	long ru_msgsnd;			/* messages sent */
+	long ru_msgrcv;			/* messages received */
+	long ru_nsignals;		/* signals received */
+	long ru_nvcsw;			/* voluntary context switches */
+	long ru_nivcsw;			/* involuntary context switches */
+};
Index: squid/src/defines.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/defines.h,v
retrieving revision 1.1.1.3.4.2.2.5
retrieving revision 1.1.1.3.4.2.2.6
diff -u -r1.1.1.3.4.2.2.5 -r1.1.1.3.4.2.2.6
--- squid/src/defines.h	12 Sep 2001 20:21:15 -0000	1.1.1.3.4.2.2.5
+++ squid/src/defines.h	1 Nov 2001 17:31:07 -0000	1.1.1.3.4.2.2.6
@@ -1,6 +1,6 @@
 
 /*
- * $Id: defines.h,v 1.1.1.3.4.2.2.5 2001/09/12 20:21:15 serassio Exp $
+ * $Id: defines.h,v 1.1.1.3.4.2.2.6 2001/11/01 17:31:07 serassio Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -290,14 +290,6 @@
 
 /* CygWin & Windows NT Port */
 #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
-#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
 #define _WIN_SQUID_SERVICE_CONTROL_STOP SERVICE_CONTROL_STOP
 #define _WIN_SQUID_SERVICE_CONTROL_SHUTDOWN SERVICE_CONTROL_SHUTDOWN
 #define _WIN_SQUID_SERVICE_CONTROL_INTERROGATE SERVICE_CONTROL_INTERROGATE
Index: squid/src/enums.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/enums.h,v
retrieving revision 1.1.1.3.4.2.2.1
retrieving revision 1.1.1.3.4.2.2.2
diff -u -r1.1.1.3.4.2.2.1 -r1.1.1.3.4.2.2.2
--- squid/src/enums.h	6 Jan 2001 12:40:13 -0000	1.1.1.3.4.2.2.1
+++ squid/src/enums.h	1 Nov 2001 17:31:07 -0000	1.1.1.3.4.2.2.2
@@ -1,6 +1,6 @@
 
 /*
- * $Id: enums.h,v 1.1.1.3.4.2.2.1 2001/01/06 12:40:13 hno Exp $
+ * $Id: enums.h,v 1.1.1.3.4.2.2.2 2001/11/01 17:31:07 serassio Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -664,3 +664,17 @@
     SWAPDIR_ASYNCUFS,
     SWAPDIR_MAX
 } swapdir_t;
+
+/* CygWin & Windows NT Port */
+#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
+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
\ No newline at end of file
Index: squid/src/protos.h
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/protos.h,v
retrieving revision 1.1.1.3.4.1.2.8
retrieving revision 1.1.1.3.4.1.2.9
diff -u -r1.1.1.3.4.1.2.8 -r1.1.1.3.4.1.2.9
--- squid/src/protos.h	16 Sep 2001 08:59:53 -0000	1.1.1.3.4.1.2.8
+++ squid/src/protos.h	1 Nov 2001 17:31:08 -0000	1.1.1.3.4.1.2.9
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.1.1.3.4.1.2.8 2001/09/16 08:59:53 serassio Exp $
+ * $Id: protos.h,v 1.1.1.3.4.1.2.9 2001/11/01 17:31:08 serassio Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -1241,5 +1241,6 @@
 extern void WIN32_SetServiceCommandLine(void);
 extern void WIN32_InstallService(void);
 extern void WIN32_RemoveService(void);
+extern int WIN32_getrusage(int, struct rusage *);
 #endif
 
Index: squid/src/tools.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/tools.c,v
retrieving revision 1.1.1.3.4.1.2.11
retrieving revision 1.1.1.3.4.1.2.12
diff -u -r1.1.1.3.4.1.2.11 -r1.1.1.3.4.1.2.12
--- squid/src/tools.c	16 Sep 2001 08:59:53 -0000	1.1.1.3.4.1.2.11
+++ squid/src/tools.c	1 Nov 2001 17:31:08 -0000	1.1.1.3.4.1.2.12
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tools.c,v 1.1.1.3.4.1.2.11 2001/09/16 08:59:53 serassio Exp $
+ * $Id: tools.c,v 1.1.1.3.4.1.2.12 2001/11/01 17:31:08 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 <windows.h>
-#include <psapi.h>
-#include <process.h>
+
+/* 
+   Temporary hack to fix Cygwin lacks of process
+   memory informations
+   
+ */
+#if defined(_SQUID_CYGWIN_)
+#undef getrusage
+#define getrusage WIN32_getrusage
 #endif
 
 #define DEAD_MSG "\
@@ -179,50 +184,15 @@
 squid_getrusage(struct rusage *r)
 {
     memset(r, '\0', sizeof(struct rusage));
-#if (HAVE_GETRUSAGE && defined(RUSAGE_SELF)) || defined(_SQUID_MSWIN_)
+#if (HAVE_GETRUSAGE && defined(RUSAGE_SELF))
 #ifdef _SQUID_SOLARIS_
     /* 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.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- squid/src/win32.c	12 Sep 2001 20:21:15 -0000	1.1.2.7
+++ squid/src/win32.c	1 Nov 2001 17:31:08 -0000	1.1.2.8
@@ -21,11 +21,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 <windows.h>
+#include <psapi.h>
+#include <process.h>
 
 static unsigned int GetOSVersion();
 void WIN32_svcstatusupdate(DWORD);
@@ -54,15 +59,15 @@
 #else
 #define SOFTWARENAME "Squid"
 #endif
-#define VERSION  "2.3-STABLE-5"
+#define WIN32_VERSION  "2.3-STABLE-5"
 #define COMMANDLINE "CommandLine"
 #define CONFIGFILE  "ConfigFile"
-static char REGKEY[256]="SOFTWARE\\"VENDOR"\\"SOFTWARENAME"\\"VERSION"\\";
+static char REGKEY[256]="SOFTWARE\\"VENDOR"\\"SOFTWARENAME"\\"WIN32_VERSION"\\";
 static char *keys[] = { 
     "SOFTWARE",	    /* key[0] */
     VENDOR,	    /* key[1] */
     SOFTWARENAME,   /* key[2] */
-    VERSION,	    /* key[3] */
+    WIN32_VERSION,  /* key[3] */
     NULL,	    /* key[4] */
     NULL	    /* key[5] */
 };
@@ -672,6 +677,57 @@
 }
 #endif
 
+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;
+}
+
 /* The following code section is part of an EXPERIMENTAL native */
 /* Windows NT/2000 Squid port - Compiles only on MS Visual C++  */
 
@@ -716,3 +772,5 @@
 }
 #endif /* End native Windows NT EXPERIMENTAL PORT */
 #endif
+
+#endif /* WIN32_C */
