3 # alsasound This shell script takes care of starting and stopping
6 # This script requires /usr/sbin/alsactl program from alsa-utils package.
8 # Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # For Polish Linux Distribution:
26 # chkconfig: 2345 87 14
27 # description: ALSA driver
30 # Source function library.
31 . /etc/rc.d/init.d/functions
33 alsactl=/usr/sbin/alsactl
35 if [ -r /etc/modules.conf ]; then
36 MODULES_CONF=/etc/modules.conf
38 MODULES_CONF=/etc/conf.modules
44 # insert all sound modules
46 if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
49 awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/ || $2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \
51 show "Starting sound driver: $line"
57 # set (non-)blocking state of pcm devices
59 for card in /proc/asound/[0-9]; do
60 card=`echo $card | awk '{ sub(/^.*\//, ""); print $0 }'`
61 for dev in /proc/asound/$card/pcmD[0-9]o; do
62 dev=`echo $dev | awk '{ sub(/^.*pcmD/, ""); sub(/o$/, ""); print $0 }'`
63 show "Setting up blocking state for card $card device $dev"
65 echo "Playback erase" > /proc/asound/$card/pcmD${dev}o
66 echo "Capture erase" > /proc/asound/$card/pcmD${dev}o
67 awk -v CARD=$card '($1 ~ CARD || $1 ~ /\*/) { $1 = ""; sub(/^ /, ""); print $0}' < /etc/sysconfig/alsa-oss-pcm > /proc/asound/$card/pcmD${dev}o
71 if [ -n "$OLDLOGLEV" ]; then
72 /sbin/loglevel "$OLDLOGLEV"
75 # restore driver settings
77 if [ -x $alsactl ]; then
80 show "ERROR: alsactl not found"; fail
87 # remove all sound modules
89 /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \
90 /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
97 # store driver settings
99 if [ -x $alsactl ]; then
102 show '!!!alsactl not found!!!'; fail
105 # remove all sound modules
113 # run only detect module
115 /sbin/modprobe snd-detect
118 # See how we were called.
122 if [ ! -d /proc/asound ]; then
124 if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then
125 touch /var/lock/subsys/alsasound
128 if [ -f /proc/asound/detect ]; then
129 show "Shutting down sound detect module:"
133 if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then
134 touch /var/lock/subsys/alsasound
137 show "ALSA driver is already running"; fail
143 if [ -d /proc/asound ]; then
144 show "Shutting down sound driver:"
146 if [ -f /proc/asound/detect ]; then
151 (rmmod isapnp; rmmod soundcore) 2> /dev/null
152 if [ -d /var/lock/subsys ]; then
153 rm -f /var/lock/subsys/alsasound
157 show "ALSA driver isn't running "; fail
165 # Start driver only in detect mode.
166 if [ -d /proc/asound ]; then
167 if [ -f /proc/asound/detect ]; then
168 show "ALSA is already running detection mode"; fail
171 show "Shutting down sound driver:"
176 show "Starting sound detect module:"
179 if [ -d /var/lock/subsys ]; then
180 touch /var/lock/subsys/alsasound
184 echo "Usage: $0 {start|stop|restart|detect}"