-remove_modules ()
-{
- local modules="${@}"
- local ref_cnt
-
- for mod in $modules; do
- ref_cnt=`/sbin/lsmod | awk "$awkprog" "module_name=$mod"`
- if [ $ref_cnt -lt 0 ]; then
- # module not loaded, skip it
- continue
- fi
- if [ $ref_cnt -gt 0 ]; then
- # module in use. maybe it just needs a few seconds
- # after removal of previous modules.
- sleep 5
- ref_cnt=`/sbin/lsmod | awk "$awkprog" module_name=$mod`
- fi
- if [ $ref_cnt -eq 0 ]; then
- # unload the module
- echo "Removing module $mod"
- /sbin/rmmod $mod
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to remove module $mod."
- return 1
- fi
- else
- # boo! module still in use.
- echo "ERROR: Module $mod has non-zero reference count."
- return 1
- fi
- done
-
- return 0
-}
-