]> git.pld-linux.org Git - packages/alsa-utils.git/blob - alsasound.init
- use functions to avoid reexec for restart
[packages/alsa-utils.git] / alsasound.init
1 #!/bin/sh
2 #
3 # alsasound     This shell script takes care of starting and stopping \
4 #               ALSA sound driver.
5 #
6 # This script requires /usr/sbin/alsactl program from alsa-utils package.
7 #
8 # Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
9 #
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.
14 #
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.
19 #
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.
23 #
24 #
25 # For PLD Linux Distribution:
26 # chkconfig:    2345 87 14
27 # description:  ALSA driver
28 #
29
30 # Source function library.
31 . /etc/rc.d/init.d/functions
32
33 alsactl=/usr/sbin/alsactl
34
35 if [ $(kernelverser) = "002006" ]; then
36         MODULES_CONF=/etc/modprobe.conf
37 elif [ -r /etc/modules.conf ]; then
38         MODULES_CONF=/etc/modules.conf
39 else
40         MODULES_CONF=/etc/conf.modules
41 fi
42
43 driver_start()
44 {
45   #
46   # insert all sound modules
47   #
48   if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
49         /sbin/loglevel 1
50   fi
51   awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $2}' < $MODULES_CONF | \
52     while read line; do \
53       msg_starting "sound driver: $line"
54       busy
55       /sbin/modprobe $line
56       ok
57     done
58   awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \
59     while read line; do \
60       msg_starting "sound driver: $line"
61       busy
62       /sbin/modprobe $line
63       ok
64     done
65   if [ -n "$OLDLOGLEV" ]; then
66         /sbin/loglevel "$OLDLOGLEV"
67   fi
68   #
69   # restore driver settings
70   #
71   if [ -x $alsactl ]; then
72     if [ -f /etc/asound.state ]; then
73       if [ "$(kernelver)" -lt "002006012" ]; then
74         for i in 1 2 3 4; do
75           [ -a /dev/snd/controlC0 ] && break
76           sleep 1
77         done
78       fi
79       $alsactl restore
80     fi
81   else
82     show "ERROR: alsactl not found"; fail
83   fi
84 }
85
86 detect_stop()
87 {
88   #
89   # remove all sound modules
90   #
91   /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \
92      /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
93   done
94 }
95
96 driver_stop()
97 {
98   #
99   # store driver settings
100   #
101   if [ -x $alsactl ]; then
102     $alsactl store
103   else
104     show '!!!alsactl not found!!!'; fail
105   fi
106   #
107   # remove all sound modules
108   #
109   detect_stop
110 }
111
112 detect_start()
113 {
114   #
115   # run only detect module
116   #
117   /sbin/modprobe snd-detect
118 }
119
120 # Start driver.
121 start() {
122         if [ ! -d /proc/asound ]; then
123                 driver_start
124                 if [ -d /proc/asound ]; then
125                         touch /var/lock/subsys/alsasound
126                 else
127                         exit 1
128                 fi
129         else
130                 if [ -f /proc/asound/detect ]; then
131                         show "Shutting down sound detect module"
132                         detect_stop
133                         ok
134                         driver_start
135                         if [ -d /proc/asound ]; then
136                                 touch /var/lock/subsys/alsasound
137                         else
138                                 exit 1
139                         fi
140                 else
141                         msg_already_running "ALSA driver"
142                 fi
143         fi
144 }
145
146 # Stop daemons.
147 stop() {
148         if [ -d /proc/asound ]; then
149                 show "Shutting down sound driver"
150                 busy
151                 if [ -f /proc/asound/detect ]; then
152                         detect_stop
153                 else
154                         driver_stop
155                 fi
156                 (rmmod isapnp; rmmod soundcore) 2> /dev/null
157                 if [ -d /var/lock/subsys ]; then
158                         rm -f /var/lock/subsys/alsasound
159                 fi
160                 ok
161         else
162                 msg_not_running "ALSA driver"
163         fi
164 fi
165
166 # See how we were called.
167 case "$1" in
168   start)
169         start
170         ;;
171   stop)
172         stop
173         ;;
174   restart|force-reload)
175         stop
176         start
177         ;;
178   status)
179         # TODO
180         ;;
181   *)
182         msg_usage "$0 {start|stop|restart|force-reload|status}"
183         exit 3
184 esac
185
186 exit 0
This page took 0.043561 seconds and 4 git commands to generate.