From b2134145a2e97452268351a91dde661acfe11a6f Mon Sep 17 00:00:00 2001 From: Gerrit Sere Date: Tue, 5 Jan 2021 00:30:06 +0100 Subject: [PATCH] bastille cmd exit code not respected #272 --- usr/local/share/bastille/cmd.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/usr/local/share/bastille/cmd.sh b/usr/local/share/bastille/cmd.sh index 3ebc1ad3..28ce03b1 100644 --- a/usr/local/share/bastille/cmd.sh +++ b/usr/local/share/bastille/cmd.sh @@ -45,8 +45,29 @@ if [ $# -eq 0 ]; then usage fi +COUNT=0 +RETURN=0 + for _jail in ${JAILS}; do + COUNT=$(($COUNT+1)) info "[${_jail}]:" jexec -l "${_jail}" "$@" + ERROR_CODE=$? + info "[${_jail} - Return code]: ${ERROR_CODE}" + + if [ "$COUNT" -eq 1 ]; then + RETURN=$ERROR_CODE + else + RETURN=$(($RETURN+$ERROR_CODE)) + fi + echo done + +# Check when a command is executed in all running jails. (bastille cmd ALL ...) + +if [ "$COUNT" -gt 1 ] && [ "$RETURN" -gt 0 ]; then + RETURN=1 +fi + +return "$RETURN"