From c6c851b64583c0e926711688638c6e5fa264bbdf Mon Sep 17 00:00:00 2001 From: aabacchus Date: Sun, 17 Jul 2022 19:16:33 +0100 Subject: [PATCH] kiss-chroot: fix trap If the chroot is exited with nonzero status, kiss-chroot runs `die chroot failed`. Then, die runs `exit 1` which causes the trap to execute. However, in this scope, "$@" is "chroot failed", so the trap evaluates $1 to be "chroot" rather than the mountpoint given to the kiss-chroot script. Then, the trap tries to unmount "chroot/dev" etc rather than the true mountpoint. This patch uses double quotes rather than single when setting the trap, so that $1 is expanded then and the mountpoint is stored for when the trap is called. --- contrib/kiss-chroot | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/kiss-chroot b/contrib/kiss-chroot index 7440892..f82ab2e 100755 --- a/contrib/kiss-chroot +++ b/contrib/kiss-chroot @@ -57,7 +57,9 @@ main() { [ -d "$1" ] || die Given path does not exist [ "$(id -u)" = 0 ] || die Script needs to be run as root - trap 'clean "${1%"${1##*[!/]}"}"' EXIT INT + # Intended behaviour. + # shellcheck disable=SC2064 + trap "clean ${1%"${1##*[!/]}"}" EXIT INT log Mounting host paths; { mmount "$1/dev" -o bind /dev