[Bug 1641832] Re: Bash ignores exit trap on success when part of a command string
Steve Langasek
steve.langasek at canonical.com
Tue Nov 15 18:15:32 UTC 2016
The following seems like it should be a non-destructive reproducer case
for the bug, based tightly on the original example, but it also doesn't
let me reproduce the problem - the 'cleanup' trap definitely still
triggers.
$ sudo bash -ec 'src="$1"; img="$2"; trgmp="$3";
mounts=""
cleanup() { for m in $mounts; do echo umount "$m"; done; }
trap cleanup EXIT
echo mount -o loop "$img" "$trgmp"
mounts="$trgmp"
echo unsquashfs -force -xattrs -dest "$trgmp" "$src"' "squashimg-to-image" foo bar baz
mount -o loop bar baz
unsquashfs -force -xattrs -dest baz foo
umount baz
$
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to bash in Ubuntu.
https://bugs.launchpad.net/bugs/1641832
Title:
Bash ignores exit trap on success when part of a command string
Status in bash package in Ubuntu:
Triaged
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-to-image" "$squashimg" "$output" "$trgmp"
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.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1641832/+subscriptions
More information about the foundations-bugs
mailing list