You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 29, 2018. It is now read-only.
cartridge control scripts: Fix exit value handling
Fix some problems with how we handle exit values in control scripts.
Most control scripts have `#!/bin/bash -e` or `set -e` so that they exit
immediately if a command exits with a non-zero return value if that
command is not part of a compound command or conditional statement.
Thus if we anticipate that a command may fail, we must put it in a compound
command or a conditional statement. This commit makes the following
changes:
• Replace `foo; [ $? -eq 0 ] && bar` with `local rc=0; foo || rc=$?;
[[ "$rc" = 0 ]] && bar` where foo is an especially long command.
• Replace `foo; [ $? -eq 0 ] || bar` with `if ! foo; then bar; fi`.
• Replace `foo; ret=$?; if [ $ret -eq 0 ]; then` with `if foo; then`.
• Replace `foo; ret=$?; if [ $ret -ne 0 ]; then` with `if ! foo; then`.
• Replace `foo; bar $?` with `local rc=0; foo || rc=$?; bar "$rc"`.
• Replace `foo; return $?` with `local ret=0; foo || ret=$?; return
$ret`.
• If a script runs with `/bin/bash -e` and ends with `exit $?`, delete
the `exit $?` because it is redundant.
Moreover, several control scripts had inverted logic around the
/bin/kill command: These scripts would run /bin/kill, check its exit
value, and retry /bin/kill if the first attempt returned 0. However,
an exit value of 0 from /bin/kill means that it succeeded, so this code
was retrying exactly when it did not need to do so. This commit fixes
this logic.
0 commit comments