On 02/23/2012 12:22 PM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:13:53PM -0300, Gerardo Exequiel Pozzi wrote:
On 02/23/2012 11:55 AM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:30:50AM -0300, Gerardo Exequiel Pozzi wrote:
* Add libraries from /usr/lib and /sbin/losetup.
* Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi<[email protected]>
---
archiso/archiso_shutdown | 13 +++++--------
archiso/hooks/archiso_shutdown | 10 +++++-----
2 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown
index 26220a6..c430014 100644
--- a/archiso/archiso_shutdown
+++ b/archiso/archiso_shutdown
@@ -10,10 +10,8 @@ umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r)
# Remove all dm-snapshot devices.
dmsetup remove_all
-# Remove all loopback devices made for dm-snapshots devices
-# other misc loops like used for pure squashfs images
-# and unmount/detach *.fs.sfs images.
-for _lup in $(ls -r /dev/loop[1-9][0-9][0-9]); do
+# Remove all loopback devices.
+for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do
Eek. Please don't do this. I have bad experiences with tac, particularly
in initscripts on shutdown, because there was nowhere for tac to write
to (it creates a temporary file when it reads from a pipe). "for" is no
way to iterate over lines of output, either. It's a little more long
winded, but I'm always in favor of doing this "correctly":
mapfile -t loopdevs</oldrun/archiso/used_block_devices
for (( i=${loopdevs[*]}-1; i>=0; i-- )); do
if [[ ${loopdevs[i]} = /dev/loop* ]]&& ! loosetup -d "${loopdevs[i]}"
2>/dev/null; then
umount -d "${loopdevs[i]}"
fi
done
unset loopdevs i
True about tac (from coreutils) but tac (from busybox) looks like
does not use tempfile [#1]
The problem here is that such shell code is for bash, here is ash
from busybox.
Thanks for review.
derp. carry on.
Hehe, anyway, in a future, I want to use losetup --detach-all (new in
2.21), then umount -d, without looking at the list. For now, this code
just works and makes posible to use current losetup (booting with
extra/workaround bootparams of course).
Thanks you.
--
Gerardo Exequiel Pozzi
\cos^2\alpha + \sin^2\alpha = 1