]> granicus.if.org Git - procps-ng/commitdiff
handle Linux 2.5.xx ABI
authoralbert <>
Sun, 6 Oct 2002 17:13:29 +0000 (17:13 +0000)
committeralbert <>
Sun, 6 Oct 2002 17:13:29 +0000 (17:13 +0000)
vmstat.c

index 1300bfca20794488024f53b32c189de05ef5df3e..924a8a80bbdb4d3b61dc2506ba928aba0b20a651 100644 (file)
--- a/vmstat.c
+++ b/vmstat.c
@@ -87,30 +87,39 @@ static void getstat(jiff *cuse, jiff *cice, jiff *csys, jiff long *cide, jiff lo
             unsigned *pin, unsigned *pout, unsigned *s_in, unsigned *sout,
             unsigned *itot, unsigned *i1, unsigned *ct) {
   static int Stat;
+  int need_extra_file = 0;
+  char* b;
+  buff[BUFFSIZE-1] = 0;  /* ensure null termination in buffer */
 
-  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 */
-    *ciow = 0;  /* not separated out until the 2.5.41 kernel */
-    b = strstr(buff, "cpu ");
-    if(b) sscanf(b,  "cpu  %lu %lu %lu %lu %lu", cuse, cice, csys, cide, ciow);
-    b = strstr(buff, "page ");
-    if(b) sscanf(b,  "page %u %u", pin, pout);
-    b = strstr(buff, "swap ");
-    if(b) sscanf(b,  "swap %u %u", s_in, sout);
-    b = strstr(buff, "intr ");
-    if(b) sscanf(b,  "intr %u %u", itot, i1);
-    b = strstr(buff, "ctxt ");
-    if(b) sscanf(b,  "ctxt %u", ct);
+  if(Stat){
+    lseek(Stat, 0L, SEEK_SET);
+  }else{
+    Stat = open("/proc/stat", O_RDONLY, 0);
+    if(Stat == -1) crash("/proc/stat");
   }
-  else {
-    crash("/proc/stat");
-  }
-  if(1){
+  read(Stat,buff,BUFFSIZE-1);
+  *itot = 0; 
+  *i1 = 1;   /* ensure assert below will fail if the sscanf bombs */
+  *ciow = 0;  /* not separated out until the 2.5.41 kernel */
+
+  b = strstr(buff, "cpu ");
+  if(b) sscanf(b,  "cpu  %lu %lu %lu %lu %lu", cuse, cice, csys, cide, ciow);
+
+  b = strstr(buff, "page ");
+  if(b) sscanf(b,  "page %u %u", pin, pout);
+  else need_extra_file = 1;
+
+  b = strstr(buff, "swap ");
+  if(b) sscanf(b,  "swap %u %u", s_in, sout);
+  else need_extra_file = 1;
+
+  b = strstr(buff, "intr ");
+  if(b) sscanf(b,  "intr %u %u", itot, i1);
+
+  b = strstr(buff, "ctxt ");
+  if(b) sscanf(b,  "ctxt %u", ct);
+
+  if(need_extra_file){  /* 2.5.40-bk4 and above */
     vminfo();
     *pin  = vm_pgpgout;
     *pout = vm_pgpgin;