runqemu: Fix TAP='TUNSETGROUP: Invalid argument' by falling back to tunctl -u

By default the runqemu script tries to set the group permissions on any
tap device it creates.  The TUNSETGROUP ioctl is not implemented on some
popular host enterprise linux distributions.

Internally the script will exit as follows:

++ /opt/qemux86/bitbake_build/tmp/sysroots/x86_64-linux/usr/bin/tunctl -b -g 100
+ TAP='TUNSETGROUP: Invalid argument'
+ STATUS=1
+ '[' 1 -ne 0 ']'
+ echo 'tunctl failed:'
tunctl failed:
+ echo TUNSETGROUP: Invalid argument

This patch implements a fallback to using the userid as the owner of
the tap device which is supported by all 2.6 kernels, the default remains
to try and use the groupid first.

(From OE-Core rev: 3af2bc59776fb738bd795160512a2f3f49ce6d32)

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Jason Wessel 2012-05-02 06:30:46 -05:00 committed by Richard Purdie
parent e8005eb936
commit 76551e02ed
2 changed files with 16 additions and 9 deletions

View File

@ -34,7 +34,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
usage() { usage() {
echo "sudo $(basename $0) <gid> <native-sysroot-basedir>" echo "sudo $(basename $0) <uid> <gid> <native-sysroot-basedir>"
} }
if [ $EUID -ne 0 ]; then if [ $EUID -ne 0 ]; then
@ -42,13 +42,14 @@ if [ $EUID -ne 0 ]; then
exit 1 exit 1
fi fi
if [ $# -ne 2 ]; then if [ $# -ne 3 ]; then
usage usage
exit 1 exit 1
fi fi
GROUP="-g $1" USERID="-u $1"
NATIVE_SYSROOT_DIR=$2 GROUP="-g $2"
NATIVE_SYSROOT_DIR=$3
TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl
if [ ! -x "$TUNCTL" ]; then if [ ! -x "$TUNCTL" ]; then
@ -59,9 +60,14 @@ fi
TAP=`$TUNCTL -b $GROUP 2>&1` TAP=`$TUNCTL -b $GROUP 2>&1`
STATUS=$? STATUS=$?
if [ $STATUS -ne 0 ]; then if [ $STATUS -ne 0 ]; then
echo "tunctl failed:" # If tunctl -g fails, try using tunctl -u, for older host kernels
echo $TAP # which do not support the TUNSETGROUP ioctl
exit 1 TAP=`$TUNCTL -b $USERID 2>&1`
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "tunctl failed:"
exit 1
fi
fi fi
IFCONFIG=`which ifconfig 2> /dev/null` IFCONFIG=`which ifconfig 2> /dev/null`

View File

@ -173,13 +173,14 @@ if [ "$TAP" = "" ]; then
fi fi
GROUPID=`id -g` GROUPID=`id -g`
USERID=`id -u`
echo "Setting up tap interface under sudo" echo "Setting up tap interface under sudo"
# Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
# but inactive. This looks scary but is harmless # but inactive. This looks scary but is harmless
tap=`sudo $QEMUIFUP $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null` tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null`
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# Re-run standalone to see verbose errors # Re-run standalone to see verbose errors
sudo $QEMUIFUP $GROUPID $OECORE_NATIVE_SYSROOT sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT
return return
fi fi
LOCKFILE="$LOCKDIR/$tap" LOCKFILE="$LOCKDIR/$tap"