summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJörg Sommer <joerg.sommer@navimatix.de>2023-06-09 10:51:05 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-06-13 22:10:32 +0100
commit177886950ea29fcc0496ebcfd7478d694dd72704 (patch)
tree7cdd683aff86e33f32de10296e12144c22e81721 /scripts
parent96f64c469bb3717e1e1d420719ac11cb75c927be (diff)
downloadpoky-177886950ea29fcc0496ebcfd7478d694dd72704.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. (From OE-Core rev: 351577761d0712a005eda9dde9215558ca9a1fe9) Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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 a6ee4517da..f2d6cc39c2 100755
--- a/scripts/runqemu-gen-tapdevs
+++ b/scripts/runqemu-gen-tapdevs
@@ -44,6 +44,12 @@ GID=$2
44COUNT=$3 44COUNT=$3
45STAGING_BINDIR_NATIVE=$4 45STAGING_BINDIR_NATIVE=$4
46 46
47# check if COUNT is a number and >= 0
48if ! [ $COUNT -ge 0 ]; then
49 echo "Error: Incorrect count: $COUNT"
50 exit 1
51fi
52
47TUNCTL=$STAGING_BINDIR_NATIVE/tunctl 53TUNCTL=$STAGING_BINDIR_NATIVE/tunctl
48if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then 54if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then
49 echo "Error: $TUNCTL is not an executable" 55 echo "Error: $TUNCTL is not an executable"
@@ -62,48 +68,39 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then
62 exit 1 68 exit 1
63fi 69fi
64 70
65IFCONFIG=`which ip 2> /dev/null` 71if ! interfaces=`ip link` 2>/dev/null; then
66if [ -z "$IFCONFIG" ]; then 72 echo "Failed to call 'ip link'" >&2
67 # Is it ever anywhere else? 73 exit 1
68 IFCONFIG=/sbin/ip
69fi
70if [ ! -x "$IFCONFIG" ]; then
71 echo "$IFCONFIG cannot be executed"
72 exit 1
73fi 74fi
74 75
75if [ $COUNT -ge 0 ]; then 76# Ensure we start with a clean slate
76 # Ensure we start with a clean slate 77for tap in `echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'`; do
77 for tap in `$IFCONFIG link | grep tap | awk '{ print \$2 }' | sed s/://`; do 78 echo "Note: Destroying pre-existing tap interface $tap..."
78 echo "Note: Destroying pre-existing tap interface $tap..." 79 $TUNCTL -d $tap
79 $TUNCTL -d $tap 80done
80 done 81rm -f /etc/runqemu-nosudo
81 rm -f /etc/runqemu-nosudo 82
82else 83if [ $COUNT -eq 0 ]; then
83 echo "Error: Incorrect count: $COUNT" 84 exit 0
84 exit 1
85fi 85fi
86 86
87if [ $COUNT -gt 0 ]; then 87echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..."
88 echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." 88for ((index=0; index < $COUNT; index++)); do
89 for ((index=0; index < $COUNT; index++)); do 89 echo "Creating tap$index"
90 echo "Creating tap$index" 90 if ! ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1`; then
91 ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1` 91 echo "Error running tunctl: $ifup"
92 if [ $? -ne 0 ]; then 92 exit 1
93 echo "Error running tunctl: $ifup" 93 fi
94 exit 1 94done
95 fi
96 done
97 95
98 echo "Note: For systems running NetworkManager, it's recommended" 96echo "Note: For systems running NetworkManager, it's recommended"
99 echo "Note: that the tap devices be set as unmanaged in the" 97echo "Note: that the tap devices be set as unmanaged in the"
100 echo "Note: NetworkManager.conf file. Add the following lines to" 98echo "Note: NetworkManager.conf file. Add the following lines to"
101 echo "Note: /etc/NetworkManager/NetworkManager.conf" 99echo "Note: /etc/NetworkManager/NetworkManager.conf"
102 echo "[keyfile]" 100echo "[keyfile]"
103 echo "unmanaged-devices=interface-name:tap*" 101echo "unmanaged-devices=interface-name:tap*"
104 102
105 # The runqemu script will check for this file, and if it exists, 103# The runqemu script will check for this file, and if it exists,
106 # will use the existing bank of tap devices without creating 104# will use the existing bank of tap devices without creating
107 # additional ones via sudo. 105# additional ones via sudo.
108 touch /etc/runqemu-nosudo 106touch /etc/runqemu-nosudo
109fi