]> granicus.if.org Git - procps-ng/commitdiff
libprocps-ng: sysinfo.c: truncate the vmstat figure to 32 bits
authorDavid Fries <david@fries.net>
Sat, 2 Apr 2011 17:59:17 +0000 (12:59 -0500)
committerCraig Small <csmall@enc.com.au>
Sun, 18 Dec 2011 11:53:59 +0000 (22:53 +1100)
A patch from Debian.

Bug-Debian: http://bugs.debian.org/620557
Backported-by: Sami Kerola <kerolasa@iki.fi>
proc/sysinfo.c

index a110afa8864a8c5a982da9f88b0c2014b6989ddd..5d17cefa684cbaccbb7d3286e0eabb7b74c3c579 100644 (file)
@@ -778,6 +778,10 @@ void vminfo(void){
   };
   const int vm_table_count = sizeof(vm_table)/sizeof(vm_table_struct);
 
+#if __SIZEOF_LONG__ == 4
+  unsigned long long slotll;
+#endif
+
   vm_pgalloc = 0;
   vm_pgrefill = 0;
   vm_pgscan = 0;
@@ -800,7 +804,15 @@ void vminfo(void){
     );
     head = tail+1;
     if(!found) goto nextline;
+#if __SIZEOF_LONG__ == 4
+    // A 32 bit kernel would have already truncated the value, a 64 bit kernel
+    // doesn't need to.  Truncate here to let 32 bit programs to continue to get
+    // truncated values.  It's that or change the API for a larger data type.
+    slotll = strtoull(head,&tail,10);
+    *(found->slot) = (unsigned long)slotll;
+#else
     *(found->slot) = strtoul(head,&tail,10);
+#endif
 nextline:
 
 //if(found) fprintf(stderr,"%s=%d\n",found->name,*(found->slot));