Changeset 2518

Show
Ignore:
Timestamp:
06/26/07 00:17:31 (2 years ago)
Author:
proski
Message:

Improve error reporting, use rmmod, run sync before and after unload

Don't allow root to run the script. Check that /proc/modules is
readable. Exit with non-zero exit code if some module could not be
unloaded. Report errors to stderr.

Use rmmod to unload the modules, as modprobe can unload more than one
module at a time, which can trigger some bugs. Run sync before and
after rmmod to minimize chances of filesystem corruption in case of
kernel panic.

Simplify the pattern. Unload all modules starting with "ath_" and
"wlan_", as well as "wlan". Use expr to match the pattern.

Don't try to unload the modules that have state other that Live,
non-zero use count or named dependencies.

Try unloading ten times in a loop. During the last run, report the
modules that still have to be skipped.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/scripts/madwifi-unload.bash

    r2505 r2518  
    11#!/bin/bash 
    22 
    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 
     3PATTERN='^\(ath_.*\|wlan_.*\|wlan\)$' 
     4 
     5MAX_TRIES=10 
     6 
     7fatal() 
     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 
     16tries="$MAX_TRIES" 
     17while [ "$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)) 
    745done 
     46 
     47if [ "$skipped" = "1" ]; then 
     48        echo "Error - some modules could not be unloaded" >&2 
     49        exit 1 
     50fi 
     51 
     52exit 0