Date: Mon, 26 Feb 2001 14:33:06 -0500 From: Andrew Gallatin <gallatin@cs.duke.edu> To: Robert Watson <rwatson@FreeBSD.org> 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> In-Reply-To: <200102231852.f1NIqcs45296@freefall.freebsd.org>; from rwatson@FreeBSD.org on Fri, Feb 23, 2001 at 10:52:38AM -0800 References: <200102231852.f1NIqcs45296@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010226143305.B8842>