]> git.pld-linux.org Git - packages/alsa-utils.git/blobdiff - alsasound.init
- fixed force-reload, added try-restart
[packages/alsa-utils.git] / alsasound.init
index 3a964829a7f59eef5f27d27b02482f4235792676..0710174bd1d9c9bd46902cd08b94e881c149335e 100644 (file)
@@ -5,7 +5,7 @@
 #
 # This script requires /usr/sbin/alsactl program from alsa-utils package.
 #
-# Copyright (c) by Jaroslav Kysela <perex@jcu.cz> 
+# Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 # Source function library.
 . /etc/rc.d/init.d/functions
 
-alsactl=/usr/sbin/alsactl
-
-if [ $(kernelverser) = "002006" ]; then
-       MODULES_CONF=/etc/modprobe.conf
-elif [ -r /etc/modules.conf ]; then
-       MODULES_CONF=/etc/modules.conf
-else
-       MODULES_CONF=/etc/conf.modules
-fi
-
 driver_start()
 {
   #
   # insert all sound modules
   #
-  if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
-       /sbin/loglevel 1
-  fi
-  awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $2}' < $MODULES_CONF | \
+  modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $3}' | \
     while read line; do \
       msg_starting "sound driver: $line"
       busy
       /sbin/modprobe $line
       ok
     done
-  awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \
+  modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $3}' | \
     while read line; do \
       msg_starting "sound driver: $line"
       busy
       /sbin/modprobe $line
       ok
     done
-  if [ -n "$OLDLOGLEV" ]; then
-       /sbin/loglevel "$OLDLOGLEV"
-  fi
-  #
+
   # restore driver settings
   #
-  if [ -x $alsactl ]; then
+  if [ -x /usr/sbin/alsactl ]; then
     if [ -f /etc/asound.state ]; then
-      $alsactl restore
+      if [ "$(kernelver)" -lt "002006012" ]; then
+       for i in 1 2 3 4; do
+         [ -a /dev/snd/controlC0 ] && break
+         sleep 1
+       done
+      fi
+      /usr/sbin/alsactl restore
     fi
   else
     show "ERROR: alsactl not found"; fail
@@ -82,8 +72,8 @@ detect_stop()
   #
   # remove all sound modules
   #
-  /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \
-     /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
+  /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $1 }' | while read module; do \
+     /sbin/rmmod $module
   done
 }
 
@@ -92,8 +82,8 @@ driver_stop()
   #
   # store driver settings
   #
-  if [ -x $alsactl ]; then
-    $alsactl store
+  if [ -x /usr/sbin/alsactl ]; then
+    /usr/sbin/alsactl store
   else
     show '!!!alsactl not found!!!'; fail
   fi
@@ -111,10 +101,8 @@ detect_start()
   /sbin/modprobe snd-detect
 }
 
-# See how we were called.
-case "$1" in
-  start)
-       # Start driver.
+# Start driver.
+start() {
        if [ ! -d /proc/asound ]; then
                driver_start
                if [ -d /proc/asound ]; then
@@ -124,7 +112,7 @@ case "$1" in
                fi
        else
                if [ -f /proc/asound/detect ]; then
-                       show "Shutting down sound detect module:"
+                       show "Shutting down sound detect module"
                        detect_stop
                        ok
                        driver_start
@@ -137,11 +125,12 @@ case "$1" in
                        msg_already_running "ALSA driver"
                fi
        fi
-       ;;
-  stop)
-       # Stop daemons.
+}
+
+# Stop daemons.
+stop() {
        if [ -d /proc/asound ]; then
-               show "Shutting down sound driver:"
+               show "Shutting down sound driver"
                busy
                if [ -f /proc/asound/detect ]; then
                        detect_stop
@@ -156,17 +145,42 @@ case "$1" in
        else
                msg_not_running "ALSA driver"
        fi
+}
+
+condrestart() {
+       if [ -f /var/lock/subsys/alsasound ]; then
+               stop
+               start
+       else
+               msg_not_running "ALSA driver"
+               RETVAL=$1
+       fi
+}
+
+
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
+       ;;
+  restart)
+       stop
+       start
+       ;;
+  try-restart)
+       condrestart 0
        ;;
-  restart|force-reload)
-       $0 stop
-       $0 start
-       exit $?
+  force-reload)
+       condrestart 7
        ;;
   status)
        # TODO
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|force-reload|status}"
+       msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
        exit 3
 esac
 
This page took 0.134985 seconds and 4 git commands to generate.