There's probably a way to filter out the existing ones, but it's likely
to be pretty painful and isn't immediately necessary.

(I hit this case on Android cloud x86 devices.)
---
 tests/losetup.test | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
From bf8b34b50290a16f59d48501ea508940219c8900 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 26 Jul 2019 16:00:38 -0700
Subject: [PATCH] losetup.test: bail out if loopback devices are already in
 use.

There's probably a way to filter out the existing ones, but it's likely
to be pretty painful and isn't immediately necessary.

(I hit this case on Android cloud x86 devices.)
---
 tests/losetup.test | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/losetup.test b/tests/losetup.test
index 7968ecd9..2f72b920 100755
--- a/tests/losetup.test
+++ b/tests/losetup.test
@@ -2,13 +2,18 @@
 
 [ -f testing.sh ] && . testing.sh
 
-if [ "$(id -u)" -ne 0 ]
-then
+if [ "$(id -u)" -ne 0 ]; then
   echo "$SHOWSKIP: losetup (not root)"
   return 2>/dev/null
   exit
 fi
 
+if [ "$(losetup -a | wc -l)" -ne 0 ]; then
+  echo "$SHOWSKIP: losetup (devices already in use)"
+  return 2>/dev/null
+  exit
+fi
+
 # Android's loopback devices are only in /dev/block/loop*.
 # Debian has symlinks like /dev/block/7:0 back to ../loop*.
 if [ -b /dev/block/sda ]; then
-- 
2.22.0.709.g102302147b-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to