summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJörg Sommer <joerg.sommer@navimatix.de>2023-06-09 10:51:05 +0200
committerSteve Sakoman <steve@sakoman.com>2023-06-26 12:52:01 -1000
commit3f6dacac5f8fb3c4b6b61b3fa125372c8f044795 (patch)
treec656dfe814bd364149a984ed73b89d708367813a /scripts
parent9d51a9f819a0ffdfd273635aa4e2062bf30a1db2 (diff)
downloadopenembedded-core-contrib-3f6dacac5f8fb3c4b6b61b3fa125372c8f044795.tar.gz
runqemu-gen-tapdevs: Refactoring
The changes are mostly about early exit which causes indentation changes; check with `git diff -w`. Another change is the check for ip by simply calling it and deciding upon the exit code, if it's fine or not. Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> (cherry picked from commit 351577761d0712a005eda9dde9215558ca9a1fe9) Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu-gen-tapdevs75
1 files changed, 36 insertions, 39 deletions
diff --git a/scripts/runqemu-gen-tapdevs b/scripts/runqemu-gen-tapdevs
index a6ee4517dad..f2d6cc39c22 100755
--- a/scripts/runqemu-gen-tapdevs
+++ b/scripts/runqemu-gen-tapdevs
@@ -44,6 +44,12 @@ GID=$2
COUNT=$3
STAGING_BINDIR_NATIVE=$4
+# check if COUNT is a number and >= 0
+if ! [ $COUNT -ge 0 ]; then
+ echo "Error: Incorrect count: $COUNT"
+ exit 1
+fi
+
TUNCTL=$STAGING_BINDIR_NATIVE/tunctl
if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then
echo "Error: $TUNCTL is not an executable"
@@ -62,48 +68,39 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then
exit 1
fi
-IFCONFIG=`which ip 2> /dev/null`
-if [ -z "$IFCONFIG" ]; then
- # Is it ever anywhere else?
- IFCONFIG=/sbin/ip
-fi
-if [ ! -x "$IFCONFIG" ]; then
- echo "$IFCONFIG cannot be executed"
- exit 1
+if ! interfaces=`ip link` 2>/dev/null; then
+ echo "Failed to call 'ip link'" >&2
+ exit 1
fi
-if [ $COUNT -ge 0 ]; then
- # Ensure we start with a clean slate
- for tap in `$IFCONFIG link | grep tap | awk '{ print \$2 }' | sed s/://`; do
- echo "Note: Destroying pre-existing tap interface $tap..."
- $TUNCTL -d $tap
- done
- rm -f /etc/runqemu-nosudo
-else
- echo "Error: Incorrect count: $COUNT"
- exit 1
+# Ensure we start with a clean slate
+for tap in `echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'`; do
+ echo "Note: Destroying pre-existing tap interface $tap..."
+ $TUNCTL -d $tap
+done
+rm -f /etc/runqemu-nosudo
+
+if [ $COUNT -eq 0 ]; then
+ exit 0
fi
-if [ $COUNT -gt 0 ]; then
- echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..."
- for ((index=0; index < $COUNT; index++)); do
- echo "Creating tap$index"
- ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1`
- if [ $? -ne 0 ]; then
- echo "Error running tunctl: $ifup"
- exit 1
- fi
- done
+echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..."
+for ((index=0; index < $COUNT; index++)); do
+ echo "Creating tap$index"
+ if ! ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1`; then
+ echo "Error running tunctl: $ifup"
+ exit 1
+ fi
+done
- echo "Note: For systems running NetworkManager, it's recommended"
- echo "Note: that the tap devices be set as unmanaged in the"
- echo "Note: NetworkManager.conf file. Add the following lines to"
- echo "Note: /etc/NetworkManager/NetworkManager.conf"
- echo "[keyfile]"
- echo "unmanaged-devices=interface-name:tap*"
+echo "Note: For systems running NetworkManager, it's recommended"
+echo "Note: that the tap devices be set as unmanaged in the"
+echo "Note: NetworkManager.conf file. Add the following lines to"
+echo "Note: /etc/NetworkManager/NetworkManager.conf"
+echo "[keyfile]"
+echo "unmanaged-devices=interface-name:tap*"
- # The runqemu script will check for this file, and if it exists,
- # will use the existing bank of tap devices without creating
- # additional ones via sudo.
- touch /etc/runqemu-nosudo
-fi
+# The runqemu script will check for this file, and if it exists,
+# will use the existing bank of tap devices without creating
+# additional ones via sudo.
+touch /etc/runqemu-nosudo