Bash ignores exit trap on success when part of a command string
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
bash (Ubuntu) |
Fix Released
|
Critical
|
Matthias Klose |
Bug Description
The MAAS team uses a script, lp:maas-images, which generates the images available at images.maas.io. As part of this process we use the following to convert a SquashFS image to an ext4 image.
sudo bash -ec 'src="$1"; img="$2"; trgmp="$3";
mounts=""
cleanup() { for m in $mounts; do umount "$m"; done; }
trap cleanup EXIT
mount -o loop "$img" "$trgmp"
mounts="$trgmp"
unsquashfs -force -xattrs -dest "$trgmp" "$src"' \
"squashimg-
ret=$?
rm -Rf "$mtmp" || return
return $ret
Prior to 4.4-1ubuntu1 the trap would always cause the cleanup function to always be called. Its now only called on failure. This causes the mount to remain and the following rm to fail. If I add 'false' to the end of the command script or downgrade to 4.3-15ubuntu1 the cleanup occurs.
Per <http:// pubs.opengroup. org/onlinepubs/ 007904975/ utilities/ trap.html> the expected behavior is that an 'EXIT' trap is called at exit from the shell regardless of circumstances. This appears to be a regression in bash.
Matthias, can you follow this up, please?