This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
10 changed files
with
46 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters