| 3 | | for module in ath_{pci,rate_{amrr,minstrel,onoe,sample}} \ |
|---|
| 4 | | wlan_{wep,tkip,ccmp,acl,xauth,scan_{sta,ap}} ath_hal wlan |
|---|
| 5 | | do |
|---|
| 6 | | grep -q ^$module /proc/modules && modprobe -r $module || true |
|---|
| | 3 | PATTERN='^\(ath_.*\|wlan_.*\|wlan\)$' |
|---|
| | 4 | |
|---|
| | 5 | MAX_TRIES=10 |
|---|
| | 6 | |
|---|
| | 7 | fatal() |
|---|
| | 8 | { |
|---|
| | 9 | echo "FATAL: $1" >&2 |
|---|
| | 10 | exit 1 |
|---|
| | 11 | } |
|---|
| | 12 | |
|---|
| | 13 | [ "$UID" = 0 ] || fatal "You must be root to run this script" |
|---|
| | 14 | [ -r /proc/modules ] || fatal "Cannot read /proc/modules" |
|---|
| | 15 | |
|---|
| | 16 | tries="$MAX_TRIES" |
|---|
| | 17 | while [ "$tries" != "0" ]; do |
|---|
| | 18 | skipped=0 |
|---|
| | 19 | cat /proc/modules | while true; do |
|---|
| | 20 | read -r name size use_count use_name state trailer || \ |
|---|
| | 21 | exit "$skipped" |
|---|
| | 22 | |
|---|
| | 23 | expr "$name" : "$PATTERN" >/dev/null || continue |
|---|
| | 24 | |
|---|
| | 25 | # Compatibility for Linux 2.4.x |
|---|
| | 26 | [ "$state" = "" ] && { use_name="-"; state="Live"; } |
|---|
| | 27 | |
|---|
| | 28 | if [ "$state" != "Live" ] || [ "$use_count" != "0" ] || \ |
|---|
| | 29 | [ "$use_name" != "-" ]; then |
|---|
| | 30 | skipped=1 |
|---|
| | 31 | if [ "$tries" = "1" ]; then |
|---|
| | 32 | echo "Cannot unload \"$name\"" >&2 |
|---|
| | 33 | fi |
|---|
| | 34 | continue |
|---|
| | 35 | fi |
|---|
| | 36 | |
|---|
| | 37 | echo "Unloading \"$name\"" |
|---|
| | 38 | sync # to be safe |
|---|
| | 39 | /sbin/rmmod "$name" || fatal "cannot unload module \"$name\"" |
|---|
| | 40 | sync # to be even safer |
|---|
| | 41 | done |
|---|
| | 42 | skipped="$?" |
|---|
| | 43 | [ "$skipped" = "0" ] && break |
|---|
| | 44 | tries=$(($tries - 1)) |
|---|