1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-11-04 14:05:41 -07:00

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.
This commit is contained in:
aabacchus 2022-07-17 19:16:33 +01:00 committed by git-bruh
parent 363fcaf71c
commit c6c851b645

View File

@ -57,7 +57,9 @@ main() {
[ -d "$1" ] || die Given path does not exist [ -d "$1" ] || die Given path does not exist
[ "$(id -u)" = 0 ] || die Script needs to be run as root [ "$(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; { log Mounting host paths; {
mmount "$1/dev" -o bind /dev mmount "$1/dev" -o bind /dev