From 5c9c7c8b1f92cdc66f6ec0d22990cee5edbf5a78 Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Tue, 11 Jun 2013 12:09:05 +0800 Subject: [PATCH] Fix overflow of "running" value in getstat() It seems in some cases procs_running field of /proc/stat can contain 0 even if vmstat itself is running. At least this can be reproduced on Linux 3.9.3 compiled with BFS scheduler. Since getstat() decrements value of procs_running by 1, we get overflow: $ vmstat 1 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 667732 918996 57376 911260 21 30 36 40 98 45 14 82 4 1 4294967295 0 667728 916716 57376 911264 8 0 8 0 1958 3733 28 7 65 1 0 0 667700 915996 57376 911416 24 0 152 0 1735 3600 23 5 71 1 4294967295 0 667700 915872 57376 911392 0 0 0 0 1528 3165 21 4 76 0 --- proc/sysinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 15cdb831..82de74ba 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -494,7 +494,8 @@ void getstat(jiff *restrict cuse, jiff *restrict cice, jiff *restrict csys, jiff getrunners(running, blocked); } - (*running)--; // exclude vmstat itself + if(*running) + (*running)--; // exclude vmstat itself if(need_vmstat_file){ /* Linux 2.5.40-bk4 and above */ vminfo();