[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[monit-dev] [monit] r240 committed - fix division by zero when 'monit st
From: |
monit |
Subject: |
[monit-dev] [monit] r240 committed - fix division by zero when 'monit status' is called immediately after m... |
Date: |
Wed, 15 Sep 2010 12:25:54 +0000 |
Revision: 240
Author: martin2812
Date: Wed Sep 15 05:24:38 2010
Log: fix division by zero when 'monit status' is called immediately after
monit start before blocks are initialized
http://code.google.com/p/monit/source/detail?r=240
Modified:
/trunk/http/cervlet.c
/trunk/validate.c
/trunk/xml.c
=======================================
--- /trunk/http/cervlet.c Wed Sep 15 04:10:05 2010
+++ /trunk/http/cervlet.c Wed Sep 15 05:24:38 2010
@@ -1075,7 +1075,7 @@
out_print(res,
"<td align=\"right\">%.1f%% [%.1f MB]</td>",
s->inf->space_percent/10.,
- (float)s->inf->space_total / (float)1048576 *
(float)s->inf->f_bsize);
+ s->inf->f_bsize > 0 ? ((float)s->inf->space_total / (float)1048576
* (float)s->inf->f_bsize) : 0);
if(s->inf->f_files > 0) {
@@ -2077,20 +2077,20 @@
out_print(res,
"<tr><td>Blocks total</td><td>%ld [%.1f MB]</td></tr>",
s->inf->f_blocks,
- (float) s->inf->f_blocks/1048576*s->inf->f_bsize);
+ s->inf->f_bsize > 0 ? ((float)
s->inf->f_blocks/1048576*s->inf->f_bsize) : 0);
out_print(res,
"<tr><td>Blocks free for non superuser</td>"
"<td>%ld [%.1f MB] [%.1f%%]</td></tr>",
s->inf->f_blocksfree,
- (float)s->inf->f_blocksfree / (float)1048576 *
(float)s->inf->f_bsize,
- (float)100 * (float)s->inf->f_blocksfree /
(float)s->inf->f_blocks);
+ s->inf->f_bsize > 0 ? ((float)s->inf->f_blocksfree /
(float)1048576 * (float)s->inf->f_bsize) : 0,
+ s->inf->f_blocks > 0 ? ((float)100 * (float)s->inf->f_blocksfree /
(float)s->inf->f_blocks) : 0);
out_print(res,
"<tr><td>Blocks free total</td>"
"<td><font%s>%ld [%.1f MB] [%.1f%%]</font></td></tr>",
(s->error & Event_Resource)?" color='#ff0000'":"",
s->inf->f_blocksfreetotal,
- (float)s->inf->f_blocksfreetotal / (float)1048576 *
(float)s->inf->f_bsize,
- (float)100 * (float)s->inf->f_blocksfreetotal /
(float)s->inf->f_blocks);
+ s->inf->f_bsize > 0 ? ((float)s->inf->f_blocksfreetotal /
(float)1048576 * (float)s->inf->f_bsize) : 0,
+ s->inf->f_blocks > 0 ? ((float)100 *
(float)s->inf->f_blocksfreetotal / (float)s->inf->f_blocks) : 0);
out_print(res,
"<tr><td>Block size</td><td>%ld B</td></tr>", s->inf->f_bsize);
@@ -2398,20 +2398,15 @@
s->inf->f_bsize,
"blocks total",
s->inf->f_blocks,
- ((float)s->inf->f_blocks/(float)1048576*
- (float)s->inf->f_bsize),
+ s->inf->f_bsize > 0 ? ((float)s->inf->f_blocks /
(float)1048576* (float)s->inf->f_bsize) : 0,
"blocks free for non superuser",
s->inf->f_blocksfree,
- ((float)s->inf->f_blocksfree/(float)1048576*
- (float)s->inf->f_bsize),
- ((float)100*(float)s->inf->f_blocksfree/
- (float)s->inf->f_blocks),
+ s->inf->f_bsize > 0 ? ((float)s->inf->f_blocksfree /
(float)1048576* (float)s->inf->f_bsize) : 0,
+ s->inf->f_blocks > 0 ? ((float)100 *
(float)s->inf->f_blocksfree / (float)s->inf->f_blocks) : 0,
"blocks free total",
s->inf->f_blocksfreetotal,
- ((float)s->inf->f_blocksfreetotal/(float)1048576*
- (float)s->inf->f_bsize),
- ((float)100*(float)s->inf->f_blocksfreetotal/
- (float)s->inf->f_blocks));
+ s->inf->f_bsize > 0 ?
((float)s->inf->f_blocksfreetotal/(float)1048576* (float)s->inf->f_bsize) :
0,
+ s->inf->f_blocks > 0 ? ((float)100 *
(float)s->inf->f_blocksfreetotal / (float)s->inf->f_blocks) : 0);
if(s->inf->f_files > 0) {
out_print(res,
" %-33s %ld\n"
@@ -2420,8 +2415,7 @@
s->inf->f_files,
"inodes free",
s->inf->f_filesfree,
- ((float)100*(float)s->inf->f_filesfree/
- (float)s->inf->f_files));
+ ((float)100*(float)s->inf->f_filesfree/
(float)s->inf->f_files));
}
}
if(s->type == TYPE_PROCESS) {
=======================================
--- /trunk/validate.c Wed Sep 15 04:54:33 2010
+++ /trunk/validate.c Wed Sep 15 05:24:38 2010
@@ -276,8 +276,8 @@
Event_post(s, Event_Data, STATE_FAILED, s->action_DATA, "unable to
read filesystem %s state", p);
return FALSE;
}
- s->inf->inode_percent = (int)((1000.0 * (s->inf->f_files -
s->inf->f_filesfree)) / (float)s->inf->f_files);
- s->inf->space_percent = (int)((1000.0 * (s->inf->f_blocks -
s->inf->f_blocksfree)) / (float)s->inf->f_blocks);
+ s->inf->inode_percent = s->inf->f_files > 0 ? (int)((1000.0 *
(s->inf->f_files - s->inf->f_filesfree)) / (float)s->inf->f_files) : 0;
+ s->inf->space_percent = s->inf->f_blocks > 0 ? (int)((1000.0 *
(s->inf->f_blocks - s->inf->f_blocksfree)) / (float)s->inf->f_blocks) : 0;
s->inf->inode_total = s->inf->f_files - s->inf->f_filesfree;
s->inf->space_total = s->inf->f_blocks - s->inf->f_blocksfreetotal;
Event_post(s, Event_Data, STATE_SUCCEEDED, s->action_DATA, "succeeded
getting filesystem statistic for %s", p);
=======================================
--- /trunk/xml.c Wed Sep 15 04:10:05 2010
+++ /trunk/xml.c Wed Sep 15 05:24:38 2010
@@ -297,8 +297,8 @@
"</block>",
S->inf->flags,
S->inf->space_percent/10.,
- (float)S->inf->space_total / (float)1048576 *
(float)S->inf->f_bsize,
- (float)S->inf->f_blocks / (float)1048576 *
(float)S->inf->f_bsize);
+ S->inf->f_bsize > 0 ? (float)S->inf->space_total / (float)1048576 *
(float)S->inf->f_bsize : 0,
+ S->inf->f_bsize > 0 ? (float)S->inf->f_blocks /
(float)1048576 * (float)S->inf->f_bsize : 0);
if(S->inf->f_files > 0) {
Util_stringbuffer(B,
"<inode>"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [monit-dev] [monit] r240 committed - fix division by zero when 'monit status' is called immediately after m...,
monit <=