From 0115a80f40e5d38fe3c78976475b10603d4dc401 Mon Sep 17 00:00:00 2001 From: Thomas Abraham Date: Thu, 12 Aug 2021 12:33:23 -0400 Subject: [PATCH] external/drac5: don't log empty errors The trap generates log entries on exit even if the temp file is empty. This results in errors being reported for every command -- even when help is requested. Log entries should only be generated if there's something to log and should only be logged as errors if an error is returned --- lib/plugins/stonith/external/drac5.in | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/plugins/stonith/external/drac5.in b/lib/plugins/stonith/external/drac5.in index 218cbd35..9938dca9 100644 --- a/lib/plugins/stonith/external/drac5.in +++ b/lib/plugins/stonith/external/drac5.in @@ -6,19 +6,45 @@ # License: GNU General Public License (GPL) # -trap 'if [ -n "$outf" ]; then ha_log.sh err "`cat $outf`"; rm -f "$outf"; fi' 0 -outf=`mktemp` || { - ha_log.sh err "mktemp failed" - exit 1 +ha_log() { + severity=$1 + outfile=$2 + if [ -n "$outfile" ] + then + if [ -s "$outfile" ] + then + ha_log.sh "$severity" "`cat $outfile`" + fi + fi +} + +cleanup () { + if [ -e "$outf" ] + then + rm -r "$outf" + fi } sshlogin() { + outf=`mktemp` || { + ha_log.sh err "mktemp failed" + return 1 + } + if [ x = "x$ipaddr" -o x = "x$userid" ] then ha_log.sh err "ipaddr or userid missing; check configuration" return 1 fi @SSH@ -q -x -n $userid@$ipaddr racadm serveraction "$1" >$outf 2>&1 + if [ $? -ne 0 ] + then + ha_log err "$outf" + else + ha_log debug "$outf" + fi + + cleanup } drac_reset() {