2006-12-19 16:57:00 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# alsasound This shell script takes care of starting and stopping
|
|
|
|
# the ALSA sound driver.
|
|
|
|
#
|
|
|
|
# This script requires /usr/sbin/alsactl program from alsa-utils package.
|
|
|
|
#
|
|
|
|
# Copyright (c) by Jaroslav Kysela <perex@suse.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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# For RedHat 5.0+:
|
|
|
|
# chkconfig: 2345 87 14
|
|
|
|
# description: ALSA driver
|
|
|
|
#
|
|
|
|
# modified to visually fit into SuSE 6.0+ by Philipp Thomas <pthomas@suse.de>
|
|
|
|
# further improvements by Bernd Kaindl, Olaf Hering and Takashi Iwai.
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: alsasound
|
2011-07-08 12:01:13 +02:00
|
|
|
# Required-Start: $local_fs
|
2006-12-19 16:57:00 +01:00
|
|
|
# Should-Start: $remote_fs resmgr
|
2011-07-11 10:58:05 +02:00
|
|
|
# Required-Stop: $local_fs
|
2006-12-19 16:57:00 +01:00
|
|
|
# Should-Stop: $remote_fs resmgr
|
|
|
|
# Default-Start: 2 3 5
|
|
|
|
# Default-Stop:
|
2007-06-22 00:17:57 +02:00
|
|
|
# Short-Description: Set up ALSA sound system
|
2006-12-19 16:57:00 +01:00
|
|
|
# Description: Loading ALSA drivers and store/restore the current setting
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
. /etc/rc.status
|
|
|
|
. /etc/sysconfig/sound
|
|
|
|
|
|
|
|
# Shell functions sourced from /etc/rc.status:
|
|
|
|
# rc_check check and set local and overall rc status
|
|
|
|
# rc_status check and set local and overall rc status
|
|
|
|
# rc_status -v ditto but be verbose in local rc status
|
|
|
|
# rc_status -v -r ditto and clear the local rc status
|
|
|
|
# rc_failed set local and overall rc status to failed
|
|
|
|
# rc_reset clear local rc status (overall remains)
|
|
|
|
# rc_exit exit appropriate to overall rc status
|
|
|
|
|
|
|
|
# First reset status of this service
|
|
|
|
rc_reset
|
|
|
|
|
|
|
|
alsactl=/usr/sbin/alsactl
|
2011-03-31 15:03:56 +02:00
|
|
|
asoundcfg=/var/lib/alsa/asound.state
|
2006-12-19 16:57:00 +01:00
|
|
|
aconnect=/usr/bin/aconnect
|
|
|
|
|
|
|
|
get_drivers() {
|
2009-11-03 09:15:25 +01:00
|
|
|
/sbin/modprobe -c | \
|
2011-03-24 12:32:59 +01:00
|
|
|
grep -E "^[[:space:]]*alias[[:space:]]+snd-card-[[:digit:]]" | sort -u | \
|
2006-12-19 16:57:00 +01:00
|
|
|
while read a b card; do
|
|
|
|
echo $card
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# insert all sound modules
|
|
|
|
#
|
|
|
|
load_modules() {
|
|
|
|
module_loaded=0
|
|
|
|
c=""
|
|
|
|
drivers=`get_drivers`
|
|
|
|
for i in $drivers; do
|
|
|
|
if [ $i != off ]; then
|
|
|
|
if [ x$c = x ]; then
|
|
|
|
echo -n ": "
|
|
|
|
c=1
|
|
|
|
fi
|
|
|
|
echo -n " ${i##snd-}"
|
|
|
|
/sbin/modprobe $i && module_loaded=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rc_status -v -r
|
|
|
|
test $module_loaded -eq 0 && return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# rest of start action
|
|
|
|
#
|
|
|
|
|
|
|
|
# manual load and force to store the status
|
|
|
|
start_all() {
|
|
|
|
echo -n "Starting sound driver"
|
2012-06-29 16:29:00 +02:00
|
|
|
load_modules
|
2010-05-06 16:27:49 +02:00
|
|
|
rc_status -r
|
2006-12-19 16:57:00 +01:00
|
|
|
}
|
|
|
|
|
2009-05-06 18:31:09 +02:00
|
|
|
do_kill() {
|
2009-08-13 17:31:01 +02:00
|
|
|
fuser $* /dev/admmidi* /dev/adsp* /dev/amidi* /dev/audio* /dev/dmfm* \
|
2006-12-19 16:57:00 +01:00
|
|
|
/dev/dmmidi* /dev/dsp* /dev/dspW* /dev/midi* /dev/mixer* /dev/music \
|
|
|
|
/dev/patmgr* /dev/sequencer* /dev/sndstat >/dev/null 2>&1
|
|
|
|
if [ -d /dev/snd ]; then
|
2009-08-13 17:31:01 +02:00
|
|
|
fuser $* /dev/snd/* >/dev/null 2>&1
|
2006-12-19 16:57:00 +01:00
|
|
|
fi
|
2009-05-06 18:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
terminate() {
|
|
|
|
#
|
|
|
|
# Kill processes holding open sound devices
|
|
|
|
#
|
2009-08-13 17:31:01 +02:00
|
|
|
do_kill -TERM -k
|
2009-05-06 18:31:09 +02:00
|
|
|
sleep 1
|
|
|
|
do_kill -k
|
|
|
|
|
2006-12-19 16:57:00 +01:00
|
|
|
#
|
|
|
|
# remove all sequencer connections if any
|
|
|
|
#
|
|
|
|
if [ -f /proc/asound/seq/clients -a -x $aconnect ]; then
|
|
|
|
$aconnect --removeall
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# mute master to avoid clicks at unload/shutdown
|
2009-08-06 17:50:57 +02:00
|
|
|
mute_system() {
|
2006-12-19 16:57:00 +01:00
|
|
|
/usr/bin/amixer set Master mute >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# remove all sound modules
|
|
|
|
#
|
|
|
|
unload_modules() {
|
2009-08-06 17:50:57 +02:00
|
|
|
mute_system
|
2008-12-05 15:02:55 +01:00
|
|
|
mod=$(grep -m1 -E '^(snd[^ ]*|ac97_bus) [0-9]+ 0' /proc/modules)
|
|
|
|
while [ -n "$mod" ]; do
|
|
|
|
mod=${mod%% *}
|
|
|
|
/sbin/modprobe -r $mod
|
|
|
|
mod=$(grep -m1 -E '^(snd[^ ]*|ac97_bus) [0-9]+ 0' /proc/modules)
|
2006-12-19 16:57:00 +01:00
|
|
|
done
|
2008-12-05 15:02:55 +01:00
|
|
|
rc_failed 0
|
2006-12-19 16:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unload_all() {
|
|
|
|
echo -n "Shutting down sound driver"
|
|
|
|
terminate
|
|
|
|
unload_modules
|
|
|
|
rc_status -v
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_all() {
|
|
|
|
if [ -d /proc/asound ]; then
|
2008-11-03 11:53:39 +01:00
|
|
|
$alsactl -g -f $asoundcfg store
|
2006-12-19 16:57:00 +01:00
|
|
|
unload_all
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# See how we were called.
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2011-03-24 12:32:59 +01:00
|
|
|
if test "$PREVLEVEL" = "N" -a -d /proc/asound ; then
|
2011-07-05 14:57:41 +02:00
|
|
|
# re-run alsactl when /var is a seprate partition (bnc#700781)
|
|
|
|
case $asoundcfg in
|
|
|
|
/var/*)
|
|
|
|
grep -q " /var " /proc/mounts && \
|
|
|
|
$alsactl -F -f $asoundcfg restore >/dev/null 2>&1
|
|
|
|
;;
|
|
|
|
esac
|
2006-12-19 16:57:00 +01:00
|
|
|
else
|
|
|
|
start_all
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stop)
|
2009-01-14 17:47:19 +01:00
|
|
|
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" ]; then
|
2006-12-19 16:57:00 +01:00
|
|
|
if [ -d /proc/asound ]; then
|
|
|
|
$alsactl -f $asoundcfg store
|
2009-08-06 17:50:57 +02:00
|
|
|
# kill pulseaudio before muting the system (bnc#499445)
|
2009-09-02 18:23:10 +02:00
|
|
|
if killall -q -TERM pulseaudio; then
|
2009-08-06 17:50:57 +02:00
|
|
|
usleep 200
|
|
|
|
fi
|
|
|
|
mute_system
|
2006-12-19 16:57:00 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
stop_all
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
unload)
|
|
|
|
test -d /proc/asound && unload_all
|
|
|
|
;;
|
|
|
|
reload|restart)
|
|
|
|
stop_all
|
|
|
|
start_all
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
if [ -d /proc/asound ]; then
|
|
|
|
echo -n "ALSA sound driver loaded."
|
|
|
|
rc_status -v
|
|
|
|
else
|
|
|
|
echo -n "ALSA sound driver not loaded."
|
|
|
|
rc_status -u
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart|reload|unload|status}"
|
|
|
|
exit 1
|
2008-10-22 17:31:24 +02:00
|
|
|
;;
|
2006-12-19 16:57:00 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
rc_exit
|