]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Avoid dividing by zero in memory calculation
authorJose A. Rivera <jarrpa@samba.org>
Thu, 21 Apr 2016 18:09:21 +0000 (13:09 -0500)
committerStefan Metzmacher <metze@samba.org>
Mon, 24 Oct 2016 08:56:13 +0000 (10:56 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12362

Don't do a percentage calculation for either memtotal or swaptotal if they
are zero.

Signed-off-by: Jose A. Rivera <jarrpa@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
(cherry picked from commit bf3f22315a281fb44a5cd9b075b7915138145d6e)

ctdb/config/events.d/05.system

index 69fcec2e854332ba9ed763cfc2e31734b87c4d77..bfa8e7b4c4e7f97ddf272fbc61e3a0adcfb181f4 100755 (executable)
@@ -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"