poky.lists.yoctoproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jörg Sommer" <joerg.sommer@navimatix.de>
To: poky@lists.yoctoproject.org, openembedded-core@lists.openembedded.org
Cc: "Jörg Sommer" <joerg.sommer@navimatix.de>
Subject: [PATCH 1/2] runqemu-gen-tapdevs: Refactoring
Date: Fri,  9 Jun 2023 10:51:05 +0200	[thread overview]
Message-ID: <ee3b417ac5a2acf9c8bd5bbe149794e313bfdaad.1686300665.git.joerg.sommer@navimatix.de> (raw)

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>
---
 scripts/runqemu-gen-tapdevs | 77 ++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 40 deletions(-)

diff --git a/scripts/runqemu-gen-tapdevs b/scripts/runqemu-gen-tapdevs
index a6ee4517da..f2d6cc39c2 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
-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"
+if ! interfaces=`ip link` 2>/dev/null; then
+	echo "Failed to call 'ip link'" >&2
 	exit 1
 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
+# 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
 
-	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
+if [ $COUNT -eq 0 ]; then
+	exit 0
 fi
+
+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*"
+
+# 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
-- 
2.34.1



             reply	other threads:[~2023-06-09  8:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  8:51 Jörg Sommer [this message]
2023-06-09  8:51 ` [PATCH 2/2] runqemu-ifupdown/get-tapdevs: Add support for ip tuntap Jörg Sommer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee3b417ac5a2acf9c8bd5bbe149794e313bfdaad.1686300665.git.joerg.sommer@navimatix.de \
    --to=joerg.sommer@navimatix.de \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=poky@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).