[arch-projects] [netcfg] [PATCH] Take rfkill switches attached to PHYs into account.

Dave Reisner d at falconindy.com
Tue Oct 2 13:57:41 EDT 2012


On Tue, Oct 02, 2012 at 09:47:05PM +0400, Ivan Shapovalov wrote:
> I have rfkill switches under path
> "/sys/class/net/$INTERFACE/phy80211/rfkill*"
> but not
> "/sys/class/net/$INTERFACE/rfkill"
> on two systems with iwlagn and ath9k drivers. Guess someone else also
> has these.
> 
> Signed-off-by: Ivan Shapovalov <intelfx100 at gmail.com>
> ---
>  src/rfkill | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/src/rfkill b/src/rfkill
> index 12e1832..330544b 100644
> --- a/src/rfkill
> +++ b/src/rfkill
> @@ -29,10 +29,18 @@ get_rf_path() {
>          report_fail "no rfkill switch with name $RFKILL_NAME"
>      else
>          path="/sys/class/net/$INTERFACE/rfkill"
> +
> +        # There may be many rfkill switches attached to a single PHY
> +        # For now take the first of them
> +        path_phy=( $(find "/sys/class/net/$INTERFACE/phy80211/" -type d -name 
> 'rfkill*') )
> +

Is find really needed here? Can't this just be a glob, or do you really
not know the depth of the rfkill* directory?

  path_phy=("/sys/class/net/$INTERFACE/phy80211/rfkill"*)

If it isn't, this still isn't the proper way to read the results of a
command into an array. Not sure if there's other bash4 syntax in netcfg,
but I'd do something like:

  mapfile -t path_phy < <(find ....)

else:

  IFS=$'\n' read -rd '' -a path_phy < <(find ....)

>          if [[ -d "$path" ]]; then
>              echo "$path"
>              return 0
> -        fi
> +        elif [[ -n "${path_phy[0]}" ]]; then

And in combination with the globbing advice:

  elif [[ ${path_phy[0]} && -e ${path_phy[0]} ]]; then

this saves you from having to enable nullglob.

> +            echo "${path_phy[0]}"
> +            return 0
> +		fi
>          report_fail "no rfkill switch available on interface $INTERFACE"
>      fi
>      return 1
> -- 
> 1.7.12.2
> 


More information about the arch-projects mailing list