From owner-cvs-all Mon Feb 26 11:33:51 2001 Delivered-To: cvs-all@freebsd.org Received: from duke.cs.duke.edu (duke.cs.duke.edu [152.3.140.1]) by hub.freebsd.org (Postfix) with ESMTP id 6269837B401; Mon, 26 Feb 2001 11:33:37 -0800 (PST) (envelope-from gallatin@cs.duke.edu) Received: from grasshopper.cs.duke.edu (grasshopper.cs.duke.edu [152.3.145.30]) by duke.cs.duke.edu (8.9.3/8.9.3) with ESMTP id OAA21085; Mon, 26 Feb 2001 14:33:36 -0500 (EST) Received: (from gallatin@localhost) by grasshopper.cs.duke.edu (8.11.2/8.9.1) id f1QJX6096492; Mon, 26 Feb 2001 14:33:06 -0500 (EST) (envelope-from gallatin@cs.duke.edu) Date: Mon, 26 Feb 2001 14:33:06 -0500 From: Andrew Gallatin To: Robert Watson Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/top machine.c Message-ID: <20010226143305.B8842@grasshopper.cs.duke.edu> References: <200102231852.f1NIqcs45296@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200102231852.f1NIqcs45296@freefall.freebsd.org>; from rwatson@FreeBSD.org on Fri, Feb 23, 2001 at 10:52:38AM -0800 X-Operating-System: FreeBSD 4.2-STABLE on an i386 Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Robert Watson [rwatson@FreeBSD.org] wrote: > rwatson 2001/02/23 10:52:38 PST > > Modified files: > usr.bin/top machine.c > Log: > Adapt the top utility to not use kmem_read to retrieve variables now > available via sysctl(). As a result, top should now be able to run without > setgid kmem. Hurray! Unfortunately, this commit breaks the alpha. top now says: top: sysctl(vm.loadavg...) failed: Cannot allocate memory This is happening because 4 32-bit ints making up avenrun don't work for the alpha because fscale is a long (which is 64-bits on alpha). The appended patch gets top working on the alpha & cleans up a few int/long warnings (sizeof gives you a long on alpha)... Can you review this, please? Thanks, Drew Index: machine.c =================================================================== RCS file: /home/ncvs/src/usr.bin/top/machine.c,v retrieving revision 1.37 diff -u -r1.37 machine.c --- machine.c 2001/02/23 18:52:37 1.37 +++ machine.c 2001/02/26 19:24:30 @@ -58,7 +58,7 @@ #include "screen.h" #include "utils.h" -static void getsysctl __P((char *, void *, int)); +static void getsysctl __P((char *, void *, size_t)); #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) @@ -204,7 +204,7 @@ { register int pagesize; - int modelen; + size_t modelen; struct passwd *pw; modelen = sizeof(smpmode); @@ -285,36 +285,28 @@ { long total; - load_avg avenrun[4]; /* 3 values and FSCALE. */ + struct loadavg sysload; int mib[2]; struct timeval boottime; size_t bt_size; /* get the cp_time array */ GETSYSCTL("kern.cp_time", cp_time); - GETSYSCTL("vm.loadavg", avenrun); + GETSYSCTL("vm.loadavg", sysload); GETSYSCTL("kern.lastpid", lastpid); /* convert load averages to doubles */ { register int i; register double *infoloadp; - load_avg *avenrunp; -#ifdef notyet - struct loadavg sysload; - int size; - getkerninfo(KINFO_LOADAVG, &sysload, &size, 0); -#endif - infoloadp = si->load_avg; - avenrunp = avenrun; for (i = 0; i < 3; i++) { #ifdef notyet *infoloadp++ = ((double) sysload.ldavg[i]) / sysload.fscale; #endif - *infoloadp++ = loaddouble(*avenrunp++); + *infoloadp++ = loaddouble(sysload.ldavg[i]); } } @@ -595,10 +587,10 @@ char *name; void *ptr; -int len; +size_t len; { - int nlen = len; + size_t nlen = len; if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) { fprintf(stderr, "top: sysctl(%s...) failed: %s\n", name, strerror(errno)); -- ------------------------------------------------------------------------------ Andrew Gallatin, Sr Systems Programmer http://www.cs.duke.edu/~gallatin Duke University Email: gallatin@cs.duke.edu Department of Computer Science Phone: (919) 660-6590 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message