2.1.107 breaks vmstat (procps)

Mike Black (mblack@csihq.com)
Thu, 25 Jun 1998 07:41:50 -0400


Linux 2.1.107 causes vmstat to get s SIGSEG due to changes in /proc/stat
format.

The fix for procps-1.7 is to change vmstat.c, line 224 and 225 to:

b = strstr(buff, "CPU ");
sscanf(b, "CPU %u %u %u %lu", cuse, cice, csys, cide);

Also would seem nice to add some error checking in the getstat routine to
detect format changes...something like:

char *mystrstr(char *haystack,char *needle)
{
char *p;
p = strstr(haystack,needle);
if (p==0) {
fprintf(stderr,"Error in /proc/stat finding '%s'\n",needle);
exit(EXIT_FAILURE);
}
return p;
}

#define errchk(n1,n2,msg) if (n1 != n2) fprintf(stderr,msg)

void getstat(unsigned *cuse, unsigned *cice, unsigned *csys, unsigned long
*cide,
unsigned *pin, unsigned *pout, unsigned *sin, unsigned *sout,
unsigned *itot, unsigned *i1, unsigned *ct) {
static int stat;
int n;

if ((stat=open("/proc/stat", O_RDONLY, 0)) != -1) {
char* b;
buff[BUFFSIZE-1] = 0; /* ensure null termination in buffer */
read(stat,buff,BUFFSIZE-1);
close(stat);
*itot = 0;
*i1 = 1; /* ensure assert below will fail if the sscanf bombs */
b = mystrstr(buff, "CPU ");
n = sscanf(b, "CPU %u %u %u %lu", cuse, cice, csys, cide);
errchk(4,n,"Error parsing CPU in /proc/stat\n");
b = mystrstr(buff, "page ");
n = sscanf(b, "page %u %u", pin, pout);
errchk(2,n,"Error parsing page in /proc/stat\n");
b = mystrstr(buff, "swap ");
n = sscanf(b, "swap %u %u", sin, sout);
errchk(2,n,"Error parsing swap in /proc/stat\n");
b = mystrstr(buff, "intr ");
n = sscanf(b, "intr %u %u", itot, i1);
errchk(2,n,"Error parsing intr in /proc/stat\n");
b = mystrstr(buff, "ctxt ");
n = sscanf(b, "ctxt %u", ct);
errchk(1,n,"Error parsing ctxt in /proc/stat\n");
assert(*itot>*i1);
}
else {
crash("/proc/stat");
}
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu