--- /etc/init.d/alsasound.orig 2009-04-22 12:15:54.000000000 +1000 +++ /etc/init.d/alsasound 2009-04-22 12:15:59.000000000 +1000 @@ -105,14 +105,19 @@ } unload_modules_26() { - # First of all, remove the snd module and all the modules depending - # on it, this should remove already most of ALSA modules. - lsmod | grep -q "^snd[[:space:]]" && unload_modules_recursive snd - - # Then find the remaining ones, and handle them too. - for module in $(lsmod | sed -n -e 's/^\(snd[^ ]*\) .*/\1/p'); do - unload_modules_recursive "${module}" + # First of all, remove all snd* modules that have 0 + # references currently + ZERO_REF_MODS=`lsmod | sed -n -e 's/^\(snd[^ ]*\)[[:space:]]*\([0-9]*\)[[:space:]]*\([0-9]*\).*$/\3 \1/p' | grep "^0" | sed -n -e 's/^\([0-9]*\) \(.*\)/\2/p'` + while [ "a${ZERO_REF_MODS}" != "a" ] + do + for i in ${ZERO_REF_MODS} ; do + rmmod --wait $i + done + # Check which modules have 0 references now + ZERO_REF_MODS=`lsmod | sed -n -e 's/^\(snd[^ ]*\)[[:space:]]*\([0-9]*\)[[:space:]]*\([0-9]*\).*$/\3 \1/p' | grep "^0" | sed -n -e 's/^\([0-9]*\) \(.*\)/\2/p'` done + # as there are no modules left that have 0 references, we have removed + # all modules that could possibly be removed. lsmod | grep -vq "^snd" }