From: Jose A. Rivera Date: Thu, 21 Apr 2016 18:09:21 +0000 (-0500) Subject: ctdb-scripts: Avoid dividing by zero in memory calculation X-Git-Tag: talloc-2.1.7~211 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf3f22315a281fb44a5cd9b075b7915138145d6e;p=thirdparty%2Fsamba.git ctdb-scripts: Avoid dividing by zero in memory calculation Don't do a percentage calculation for either memtotal or swaptotal if they are zero. Signed-off-by: Jose A. Rivera Reviewed-by: Martin Schwenke --- diff --git a/ctdb/config/events.d/05.system b/ctdb/config/events.d/05.system index 69fcec2e854..bfa8e7b4c4e 100755 --- a/ctdb/config/events.d/05.system +++ b/ctdb/config/events.d/05.system @@ -144,8 +144,8 @@ $1 == "SwapFree:" { swapfree = $2 } $1 == "SwapTotal:" { swaptotal = $2 } END { if (memavail != 0) { memfree = memavail ; } - print int((memtotal - memfree) / memtotal * 100), - int((swaptotal - swapfree) / swaptotal * 100) + if (memtotal != 0) { print int((memtotal - memfree) / memtotal * 100) ; } else { print 0 ; } + if (swaptotal != 0) { print int((swaptotal - swapfree) / swaptotal * 100) ; } else { print 0 ; } }') _mem_usage="$1" _swap_usage="$2"