diff options
author | Jörg Sommer <joerg.sommer@navimatix.de> | 2023-06-09 10:51:05 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-13 22:10:32 +0100 |
commit | 177886950ea29fcc0496ebcfd7478d694dd72704 (patch) | |
tree | 7cdd683aff86e33f32de10296e12144c22e81721 /scripts | |
parent | 96f64c469bb3717e1e1d420719ac11cb75c927be (diff) | |
download | poky-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-x | scripts/runqemu-gen-tapdevs | 75 |
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 | |||
44 | COUNT=$3 | 44 | COUNT=$3 |
45 | STAGING_BINDIR_NATIVE=$4 | 45 | STAGING_BINDIR_NATIVE=$4 |
46 | 46 | ||
47 | # check if COUNT is a number and >= 0 | ||
48 | if ! [ $COUNT -ge 0 ]; then | ||
49 | echo "Error: Incorrect count: $COUNT" | ||
50 | exit 1 | ||
51 | fi | ||
52 | |||
47 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 53 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl |
48 | if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then | 54 | if [[ ! -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 |
63 | fi | 69 | fi |
64 | 70 | ||
65 | IFCONFIG=`which ip 2> /dev/null` | 71 | if ! interfaces=`ip link` 2>/dev/null; then |
66 | if [ -z "$IFCONFIG" ]; then | 72 | echo "Failed to call 'ip link'" >&2 |
67 | # Is it ever anywhere else? | 73 | exit 1 |
68 | IFCONFIG=/sbin/ip | ||
69 | fi | ||
70 | if [ ! -x "$IFCONFIG" ]; then | ||
71 | echo "$IFCONFIG cannot be executed" | ||
72 | exit 1 | ||
73 | fi | 74 | fi |
74 | 75 | ||
75 | if [ $COUNT -ge 0 ]; then | 76 | # Ensure we start with a clean slate |
76 | # Ensure we start with a clean slate | 77 | for 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 | 80 | done |
80 | done | 81 | rm -f /etc/runqemu-nosudo |
81 | rm -f /etc/runqemu-nosudo | 82 | |
82 | else | 83 | if [ $COUNT -eq 0 ]; then |
83 | echo "Error: Incorrect count: $COUNT" | 84 | exit 0 |
84 | exit 1 | ||
85 | fi | 85 | fi |
86 | 86 | ||
87 | if [ $COUNT -gt 0 ]; then | 87 | echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." |
88 | echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..." | 88 | for ((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 | 94 | done |
95 | fi | ||
96 | done | ||
97 | 95 | ||
98 | echo "Note: For systems running NetworkManager, it's recommended" | 96 | echo "Note: For systems running NetworkManager, it's recommended" |
99 | echo "Note: that the tap devices be set as unmanaged in the" | 97 | echo "Note: that the tap devices be set as unmanaged in the" |
100 | echo "Note: NetworkManager.conf file. Add the following lines to" | 98 | echo "Note: NetworkManager.conf file. Add the following lines to" |
101 | echo "Note: /etc/NetworkManager/NetworkManager.conf" | 99 | echo "Note: /etc/NetworkManager/NetworkManager.conf" |
102 | echo "[keyfile]" | 100 | echo "[keyfile]" |
103 | echo "unmanaged-devices=interface-name:tap*" | 101 | echo "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 | 106 | touch /etc/runqemu-nosudo |
109 | fi | ||