]> granicus.if.org Git - procps-ng/commitdiff
Check for presence of disks in vmstat
authorCraig Small <csmall@enc.com.au>
Wed, 29 Jan 2014 11:22:11 +0000 (22:22 +1100)
committerCraig Small <csmall@enc.com.au>
Wed, 29 Jan 2014 11:22:11 +0000 (22:22 +1100)
vmstat -d or vmstat -p would crash mysteriously under different
circumstances. The problem was eventually tracked down to /sys not
being mounted which meant is_disk() always returned false.
The partition would then be attempted to be linked to a non-existent
disk causing a segfault.

vmstat will now not link to a disk if none exists.
The change in testing will skip those tests when /sys/block doesn't
exist.

Many thanks to Daniel Schepler for his analysis and suggestions.

Bug-Debian: http://bugs.debian.org/736628

proc/sysinfo.c
testsuite/vmstat.test/vmstat.exp

index f318376cb34debf9ce87168820f9ad7df0304433..1680cc4a7182f59d72dabf8de2d714efed888268 100644 (file)
@@ -938,8 +938,11 @@ unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **parti
         &(*partitions)[cPartition].writes,
         &(*partitions)[cPartition].requested_writes
       );
-      (*partitions)[cPartition++].parent_disk = cDisk-1;
-      (*disks)[cDisk-1].partitions++;
+
+      if (cDisk > 0) {
+        (*partitions)[cPartition++].parent_disk = cDisk-1;
+        (*disks)[cDisk-1].partitions++;
+      }
     }
   }
 
index fb5de14903ffdbcb87dd147f735ed6825dabfe7d..f470afc3eb829c5038b07d61efbf9bb8259a11e9 100644 (file)
@@ -26,15 +26,23 @@ expect_pass "$test" "^Cache\\s+Num\\s+Total\\s+Size\\s+Pages\\s+\(\[\(\)A-Za-z0-
 }
 
 set test "vmstat disk information (-d option)"
-spawn $vmstat -d
-expect_pass "$test" "^disk\[ -\]+reads\[ -\]+writes\[ -\]+IO\[ -\]+\\s+total\\s+merged\\s+sectors\\s+ms\\s+total\\s+merged\\s+sectors\\s+ms\\s+cur\\s+sec\\s+"
+if { [ file readable "/sys/block" ] == 0 }  {
+    unsupported "$test /sys/block not readable"
+} else {
+    spawn $vmstat -d
+    expect_pass "$test" "^disk\[ -\]+reads\[ -\]+writes\[ -\]+IO\[ -\]+\\s+total\\s+merged\\s+sectors\\s+ms\\s+total\\s+merged\\s+sectors\\s+ms\\s+cur\\s+sec\\s+"
+}
 
 # Need a partition
 set diskstats [ exec cat /proc/diskstats ]
-if [ regexp "\\s+\\d+\\s+\\d+\\s+\(\[a-z\]+\\d+\)\\s+\[0-9\]\[0-9\]+" $diskstats line partition == 1 ] {
-    set test "vmstat partition (using $partition)"
-    spawn $vmstat -p $partition
-    expect_pass "$test" "^${partition}\\s+reads"
+if { [ file readable "/sys/block" ] == 0 }  {
+    unsupported "vmstat partition /sys/block not readable"
 } else {
-    unsupported "vmstat partition (cannot find partition)"
+  if [ regexp "\\s+\\d+\\s+\\d+\\s+\(\[a-z\]+\\d+\)\\s+\[0-9\]\[0-9\]+" $diskstats line partition == 1 ] {
+      set test "vmstat partition (using $partition)"
+      spawn $vmstat -p $partition
+      expect_pass "$test" "^${partition}\\s+reads"
+  } else {
+      unsupported "vmstat partition (cannot find partition)"
+  }
 }