Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 May 1999 14:47:55 +0200
From:      Sheldon Hearn <sheldonh@uunet.co.za>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/11833: [PATCH] Fix xosview's SwapMeter for 4.0-CURRENT
Message-ID:  <90719.927377275@axl.noc.iafrica.com>

next in thread | raw e-mail | index | archive | help

>Number:         11833
>Category:       ports
>Synopsis:       [PATCH] Fix xosview's SwapMeter for 4.0-CURRENT
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 22 05:50:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Sheldon Hearn
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
UUNET South Africa
>Environment:

	
	FreeBSD 4.0-CURRENT #3: Wed May 19 11:19:10 SAST 1999 i386

>Description:

	xosview's SwapMeter has been broken for 4.0-CURRENT since Matt
	started working on the VM subsystem.

>How-To-Repeat:

	Compile and run xosview on 4.0-CURRENT, paying attention to the
	STDERR text it spits out.

>Fix:

	Make use of the function kvm_getswapinfo() provided by Matt for
	querying swap usage in 4.0-CURRENT.

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/sysutils/xosview/Makefile,v
retrieving revision 1.15
diff -u -d -r1.15 Makefile
--- Makefile	1999/05/10 16:33:50	1.15
+++ Makefile	1999/05/22 12:36:35
@@ -19,6 +19,4 @@
 GNU_CONFIGURE=	yes
 MAN1=		xosview.1
 
-# BROKEN=	SwapMeter broken for 4.0+
-
 .include <bsd.port.mk>
Index: patches/patch-af
===================================================================
RCS file: patch-af
diff -N patch-af
--- /dev/null	Sat May 22 14:32:47 1999
+++ patch-af	Sat May 22 14:31:03 1999
@@ -0,0 +1,21 @@
+--- configure.orig	Thu Feb 25 19:13:19 1999
++++ configure	Sat May 22 14:30:39 1999
+@@ -1785,6 +1785,18 @@
+     echo host_dir is $host_dir
+     host_os=netbsd ;;
+ 
++freebsd4*)
++        EXTRALIBS="-lkvm $XPMLIB $DEVSTATLIB"
++        INSTALL_ARGS='-s -g kmem -m 02555'
++	cat >> confdefs.h <<\EOF
++#define XOSVIEW_FREEBSD 1
++#define USE_KVM_GETSWAPINFO 1
++EOF
++
++
++			host_dir=bsd
++	host_os=freebsd ;;
++
+ freebsd*) 
+         EXTRALIBS="-lkvm $XPMLIB $DEVSTATLIB"
+         INSTALL_ARGS='-s -g kmem -m 02555'
Index: patches/patch-ag
===================================================================
RCS file: patch-ag
diff -N patch-ag
--- /dev/null	Sat May 22 14:32:47 1999
+++ patch-ag	Sat May 22 14:23:48 1999
@@ -0,0 +1,99 @@
+--- bsd/swapinternal.cc.orig	Fri Sep 18 17:38:56 1998
++++ bsd/swapinternal.cc	Sat May 22 14:22:21 1999
+@@ -77,6 +77,9 @@
+ #endif
+ #include <stdlib.h>		/*  For malloc().  */
+ #include <string.h>		/*  For bzero().  */
++#ifdef USE_KVM_GETSWAPINFO
++#include <unistd.h>		/*  For getpagesize().  */
++#endif
+ 
+ 
+ 
+@@ -91,6 +94,11 @@
+ #define swap_kd kd
+ extern kvm_t*	swap_kd;
+ 
++#ifdef USE_KVM_GETSWAPINFO
++static struct kvm_swap kvmsw[16];
++static int kvnsw;
++static int pagesize;
++#else /* USE_KVM_GETSWAPINFO */
+ struct nlist syms[] = {
+         { "_swdevt" },  /* list of swap devices and sizes */
+ #define VM_SWDEVT       0
+@@ -134,14 +142,25 @@
+                 printf("cannot read %s: %s", msg, kvm_geterr(swap_kd)); \
+                 return (0); \
+         }
++#endif /* USE_KVM_GETSWAPINFO */
+ 
+ int
+ BSDInitSwapInfo()
+ {
+         static int once = 0;
+-        u_long ptr;
++#ifdef USE_KVM_GETSWAPINFO
++	char msgbuf[BUFSIZ];
++	struct kvm_swap dummy;
+ 
++	if (kvm_getswapinfo(kd, &dummy, 1, 0) < 0) {
++		snprintf(msgbuf, sizeof(msgbuf),
++		    "xosview: swap: kvm_getswapinfo failed");
++	}
++	pagesize = getpagesize();
++#else /* USE_KVM_GETSWAPINFO */
++        u_long ptr;
+ 	(void) ptr;	//  Avoid gcc warnings.
++
+         if (once)
+                 return (1);
+         if (kvm_nlist(swap_kd, syms)) {
+@@ -185,6 +204,7 @@
+         }
+         KGET1(VM_SWDEVT, sw, (signed) (nswdev * sizeof(*sw)), "swdevt");
+ #endif /* XOSVIEW_FREEBSD */
++#endif /* USE_KVM_GETSWAPINFO */
+         once = 1;
+         return (1);
+ }
+@@ -194,6 +214,7 @@
+ int
+ fetchswap()
+ {
++#ifndef USE_KVM_GETSWAPINFO
+ 	struct rlist head;
+ 	struct rlist *swapptr;
+ 
+@@ -236,6 +257,9 @@
+ 
+ 		swapptr = head.rl_next;
+ 	}
++#else /* USE_KVM_GETSWAPINFO */
++	kvnsw = kvm_getswapinfo(kd, kvmsw, 1, 0);
++#endif /* USE_KVM_GETSWAPINFO */
+ 	return 0;
+ 
+ }
+@@ -308,6 +332,15 @@
+         int i, avail, npfree, used=0, xsize, xfree;
+ 
+ 	fetchswap();
++#ifdef USE_KVM_GETSWAPINFO
++	avail = used = 0;
++	if (kvnsw == 0) {
++		avail += pagesize * kvmsw[0].ksw_total;
++		used += pagesize * kvmsw[0].ksw_used;
++	}
++        *total = avail;
++        *free = avail - used;
++#else /* USE_KVM_GETSWAPINFO */
+         avail = npfree = 0;
+         for (i = 0; i < nswdev; i++) {
+                 /*
+@@ -350,4 +383,5 @@
+ 	  /*  Convert from 512-byte blocks to bytes.  */
+         *total = 512*avail;
+         *free = 512*(avail-used);
++#endif /* USE_KVM_GETSWAPINFO */
+ }

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?90719.927377275>