tags 526360 +patch
thanks

I just built a lenny version of procps which included Daniel Novotny's
patch as debian/patches/65_fix_partition_format.dpatch (and added it to
debian/patches/00list)

I used Novotny's entire patch verbatim with the exception of the last
hunk (around lines 610 of vmstat.c), which i dropped as it is already
handled by debian's version of procps.  I've attached the modified patch
to this message.

The patched procps package appears to work correctly against a 2.6.26
kernel.

        --dkg
#! /bin/sh /usr/share/dpatch/dpatch-run
## 65_fix_partition_format.dpatch by Daniel Novotny (see 
##  https://bugzilla.redhat.com/show_bug.cgi?id=485243 )
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: The contents of /proc/diskstats have changed since 2.6.25

@DPATCH@
diff -urNad procps-3.2.7~/proc/sysinfo.c procps-3.2.7/proc/sysinfo.c
--- procps-3.2.7~/proc/sysinfo.c        2009-05-27 18:33:13.443866133 +0000
+++ procps-3.2.7/proc/sysinfo.c 2009-05-27 18:33:13.735867382 +0000
@@ -780,6 +780,18 @@
 }
 
 /////////////////////////////////////////////////////////////////////////////
+static int is_disk(char *dev)
+{
+  char syspath[PATH_MAX];
+  char *slash;
+
+  while ((slash = strchr(dev, '/')))
+    *slash = '!';
+  snprintf(syspath, sizeof(syspath), "/sys/block/%s", dev);
+  return !(access(syspath, F_OK));
+}
+
+/////////////////////////////////////////////////////////////////////////////
 
 unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat 
**partitions){
   FILE* fd;
@@ -787,6 +799,7 @@
   int cPartition = 0;
   int fields;
   unsigned dummy;
+  char devname[PATH_MAX];
 
   *disks = NULL;
   *partitions = NULL;
@@ -799,8 +812,9 @@
       fclose(fd);
       break;
     }
-    fields = sscanf(buff, " %*d %*d %*s %*u %*u %*u %*u %*u %*u %*u %*u %*u 
%*u %u", &dummy);
-    if (fields == 1){
+    fields = sscanf(buff, " %*d %*d %15s %*u %*u %*u %*u %*u %*u %*u %*u %*u 
%*u %u",
+            &devname, &dummy);
+    if (fields == 2 && is_disk(devname)){
       (*disks) = realloc(*disks, (cDisk+1)*sizeof(struct disk_stat));
       sscanf(buff,  "   %*d    %*d %15s %u %u %llu %u %u %u %llu %u %u %u %u",
         //&disk_major,
@@ -823,7 +837,9 @@
     }else{
       (*partitions) = realloc(*partitions, (cPartition+1)*sizeof(struct 
partition_stat));
       fflush(stdout);
-      sscanf(buff,  "   %*d    %*d %15s %u %llu %u %u",
+      sscanf(buff,  (fields == 2)
+          ? "   %*d    %*d %15s %u %*u %llu %*u %u %*u %llu %*u %*u %*u %*u"
+          : "   %*d    %*d %15s %u %llu %u %llu",
         //&part_major,
         //&part_minor,
         (*partitions)[cPartition].partition_name,
diff -urNad procps-3.2.7~/proc/sysinfo.h procps-3.2.7/proc/sysinfo.h
--- procps-3.2.7~/proc/sysinfo.h        2009-05-27 18:32:49.000000000 +0000
+++ procps-3.2.7/proc/sysinfo.h 2009-05-27 18:33:13.735867382 +0000
@@ -113,7 +113,7 @@
        unsigned           parent_disk;  // index into a struct disk_stat array
        unsigned           reads;
        unsigned           writes;
-       unsigned           requested_writes;
+       unsigned long long requested_writes;
 }partition_stat;
 
 extern unsigned int getpartitions_num(struct disk_stat *disks, int ndisks);
diff -urNad procps-3.2.7~/vmstat.c procps-3.2.7/vmstat.c
--- procps-3.2.7~/vmstat.c      2009-05-27 18:33:13.603867748 +0000
+++ procps-3.2.7/vmstat.c       2009-05-27 18:33:13.735867382 +0000
@@ -286,7 +286,7 @@
     struct disk_stat *disks;
     struct partition_stat *partitions, *current_partition=NULL;
     unsigned long ndisks, j, k, npartitions;
-    const char format[] = "%20u %10llu %10u %10u\n";
+    const char format[] = "%20u %10llu %10u %10llu\n";
 
     fDiskstat=fopen("/proc/diskstats","rb");
     if(!fDiskstat){

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to