From eb6a4fc1a4a6e32cd35e76771fe8687b64e9122f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 28 Sep 2014 02:42:33 +0200 Subject: devcons: avoid division by zero reading Qsysstat alexchandel got the kernel to crash with divide error on qemu 2.1.2/macosx at this location. probably caused by perfticks()/tsc being wrong or accounttime() not having been called yet from timer interrupt yet for some reason. --- sys/src/9/port/devcons.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/src/9/port/devcons.c b/sys/src/9/port/devcons.c index 339845a1d..0db1a0e9a 100644 --- a/sys/src/9/port/devcons.c +++ b/sys/src/9/port/devcons.c @@ -581,13 +581,14 @@ consread(Chan *c, void *buf, long n, vlong off) bp += NUMSIZE; readnum(0, bp, NUMSIZE, mp->load, NUMSIZE); bp += NUMSIZE; + l = mp->perf.period; + if(l == 0) + l = 1; readnum(0, bp, NUMSIZE, - (mp->perf.avg_inidle*100)/mp->perf.period, - NUMSIZE); + (mp->perf.avg_inidle*100)/l, NUMSIZE); bp += NUMSIZE; readnum(0, bp, NUMSIZE, - (mp->perf.avg_inintr*100)/mp->perf.period, - NUMSIZE); + (mp->perf.avg_inintr*100)/l, NUMSIZE); bp += NUMSIZE; *bp++ = '\n'; } -- cgit v1.2.3