Skip to content

Commit

Permalink
Set trap only after option parsing (openSUSE#22)
Browse files Browse the repository at this point in the history
If we set the cleanup function for every exit, even a simple
"toolbox -h" will run the cleanup function. But since there is nothing
to cleanup, this will lead to a wrong error exit code.
  • Loading branch information
thkukuk committed Feb 26, 2021
1 parent 5c541c8 commit daeb191
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

set -eo pipefail

trap cleanup EXIT

# Defaults
REGISTRY=registry.opensuse.org
IMAGE=opensuse/toolbox
Expand Down Expand Up @@ -337,6 +335,10 @@ main() {
esac
done

# Don't call trap before, else we will cleanup stuff
# where nothing is to cleanup and report wrong error
trap cleanup EXIT

# Let's rebuild the image URI (this means that command
# line, if present, overrides config file)
TOOLBOX_IMAGE=$(echo "${REGISTRY}"/"${IMAGE}" | sed 's/^\///g')
Expand Down

0 comments on commit daeb191

Please sign in to comment.