1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

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 <jarrpa@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Jose A. Rivera 2016-04-21 13:09:21 -05:00 committed by Martin Schwenke
parent ac7974a64e
commit bf3f22315a

View File

@ -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"