diff options
author | Jakub Jankowski <shasta@toxcorp.com> | 2018-01-08 03:30:41 +0100 |
---|---|---|
committer | Robby Workman <rworkman@slackware.com> | 2018-05-24 01:23:40 -0500 |
commit | 63fcb919b0cdefae3ae7cd7f933c70169c454710 (patch) | |
tree | 3b88c0cbfcaf003974017c4a5bb7092d1a5b6f2f | |
parent | 8e3bacf5fe7afc125d57807858d562e05927a714 (diff) | |
download | slacknetsetup-63fcb919b0cdefae3ae7cd7f933c70169c454710.tar.xz |
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 <shasta@toxcorp.com>
-rw-r--r-- | rc.wireless | 6 |
1 files 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 |