]> git.pld-linux.org Git - packages/alsa-utils.git/blobdiff - alsasound.init
up to 1.2.1
[packages/alsa-utils.git] / alsasound.init
index 2401aa78ab01f9bd8a363b05c9df33ada8291249..6c66b7e5bd8fd4c5d638e0b9a8a944fb9abaf7f6 100644 (file)
@@ -1,11 +1,9 @@
 #!/bin/sh
 #
-# alsasound     This shell script takes care of starting and stopping
-#               ALSA sound driver.
+# alsasound    This shell script takes care of starting and stopping \
+#              ALSA sound driver.
 #
-# 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
 #
 #
 # For PLD Linux Distribution:
-# chkconfig: 2345 87 14
-# description: ALSA driver
+# chkconfig:   2345 87 14
+# description: ALSA driver
 #
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 
-alsactl=/usr/sbin/alsactl
-
-if [ -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]$/ || $2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \
+  modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $3}' | \
     while read line; do \
-      show "Starting sound driver: $line"
+      msg_starting "sound driver: $line"
+      busy
+      /sbin/modprobe $line
+      ok
+    done
+  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
-    $alsactl restore
-  else
-    show "ERROR: alsactl not found"; fail
-  fi
 }
 
 detect_stop()
@@ -71,21 +54,13 @@ 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
 }
 
 driver_stop()
 {
-  #
-  # store driver settings
-  #
-  if [ -x $alsactl ]; then
-    $alsactl store
-  else
-    show '!!!alsactl not found!!!'; fail
-  fi
   #
   # remove all sound modules
   #
@@ -100,55 +75,92 @@ 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 ] && [ -d /var/lock/subsys ]; then
-           touch /var/lock/subsys/alsasound
-         fi
+               driver_start
+               if [ -d /proc/asound ]; then
+                       touch /var/lock/subsys/alsasound
+               else
+                       exit 1
+               fi
        else
-         if [ -f /proc/asound/detect ]; then
-           show "Shutting down sound detect module:"
-           detect_stop
-           ok
-           driver_start
-           if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then
-             touch /var/lock/subsys/alsasound
-           fi
-          else
-           show "ALSA driver is already running"; fail
-         fi
+               if [ -f /proc/asound/detect ]; then
+                       show "Shutting down sound detect module"
+                       detect_stop
+                       ok
+                       driver_start
+                       if [ -d /proc/asound ]; then
+                               touch /var/lock/subsys/alsasound
+                       else
+                               exit 1
+                       fi
+               else
+                       msg_already_running "ALSA driver"
+               fi
        fi
-        ;;
-  stop)
-        # Stop daemons.
+       # "restore" is handled via udev if running; if not, do it manually
+       if is_no "$START_UDEV" && [ -f /var/lib/alsa/asound.state ]; then
+               sleep 1
+               /sbin/alsactl restore
+       fi
+}
+
+# Stop daemons.
+stop() {
        if [ -d /proc/asound ]; then
-          show "Shutting down sound driver:"
-         busy
-         if [ -f /proc/asound/detect ]; then
-           detect_stop
-         else
-           driver_stop
-         fi
-         (rmmod isapnp; rmmod soundcore) 2> /dev/null
-         if [ -d /var/lock/subsys ]; then
-           rm -f /var/lock/subsys/alsasound
-         fi
-         ok
+               show "Shutting down sound driver"
+               busy
+               if [ -f /proc/asound/detect ]; then
+                       detect_stop
+               else
+                       driver_stop
+               fi
+               (rmmod isapnp; rmmod soundcore) 2> /dev/null
+               if [ -d /var/lock/subsys ]; then
+                       rm -f /var/lock/subsys/alsasound
+               fi
+               ok
+       else
+               msg_not_running "ALSA driver"
+       fi
+}
+
+condrestart() {
+       if [ -f /var/lock/subsys/alsasound ]; then
+               stop
+               start
        else
-         show "ALSA driver isn't running "; fail
+               msg_not_running "ALSA driver"
+               RETVAL=$1
        fi
-        ;;
+}
+
+
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
+       ;;
   restart)
-       $0 stop
-       $0 start
+       stop
+       start
+       ;;
+  try-restart)
+       condrestart 0
+       ;;
+  force-reload)
+       condrestart 7
+       ;;
+  status)
+       # TODO
        ;;
   *)
-        echo "Usage: $0 {start|stop|restart}"
-        exit 1
+       msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+       exit 3
 esac
 
 exit 0
This page took 0.042133 seconds and 4 git commands to generate.