From 63fcb919b0cdefae3ae7cd7f933c70169c454710 Mon Sep 17 00:00:00 2001 From: Jakub Jankowski Date: Mon, 8 Jan 2018 03:30:41 +0100 Subject: is_wireless_device: fix UUoC and reorder There's no need to $(cat .../uevent | grep DEVTYPE) and then compare it to what we're looking for. grep can do all of it for us ("Useless Use of Cat"). While at it, if we have three ways of checking whether a device is wireless, let's order them from least expensive (checking dir is only one stat()) to most expensive (iwconfig | grep). Proof of correctness: if "iwconfig | grep" is returning true and the other two methods are not, we will still reach "iwconfig | grep" in the series of if/elif. Signed-off-by: Jakub Jankowski --- rc.wireless | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc.wireless b/rc.wireless index e7a35b8..d742ae1 100644 --- a/rc.wireless +++ b/rc.wireless @@ -89,11 +89,11 @@ IFCOMMAND="/sbin/ip link set dev ${INTERFACE}" is_wireless_device () { # Return 0 for a wireless interface, or 1 for a non-wireless interface. - if LC_ALL=C $IWPATH/iwconfig $1 2>&1 | grep -q "IEEE 802.11" ; then + if [ -d /sys/class/net/${1}/wireless ]; then return 0 - elif [ -d /sys/class/net/${1}/wireless ]; then + elif grep -Fxq 'DEVTYPE=wlan' /sys/class/net/${1}/uevent 2>/dev/null; then return 0 - elif [ "$(cat /sys/class/net/${1}/uevent | grep DEVTYPE)" = "DEVTYPE=wlan" ]; then + elif LC_ALL=C $IWPATH/iwconfig $1 2>&1 | grep -q "IEEE 802.11" ; then return 0 else # all tests failed, assume the device is not wireless (or add a better test :) return 1 -- cgit v1.2.3