1 |
ssuominen 09/08/02 11:27:27 |
2 |
|
3 |
Added: alsasound.initd-r4 |
4 |
Log: |
5 |
Fix init script wrt #259861, thanks to Lars Wendler for patch. |
6 |
(Portage version: 2.2_rc33/cvs/Linux x86_64) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 media-sound/alsa-utils/files/alsasound.initd-r4 |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-sound/alsa-utils/files/alsasound.initd-r4?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-sound/alsa-utils/files/alsasound.initd-r4?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: alsasound.initd-r4 |
15 |
=================================================================== |
16 |
#!/sbin/runscript |
17 |
# $Header: /var/cvsroot/gentoo-x86/media-sound/alsa-utils/files/alsasound.initd-r4,v 1.1 2009/08/02 11:27:26 ssuominen Exp $ |
18 |
# Copyright 2007 Gentoo Foundation |
19 |
# Distributed under the terms of the GNU General Public License v2 |
20 |
|
21 |
alsastatedir=/var/lib/alsa |
22 |
alsascrdir=/etc/alsa.d |
23 |
|
24 |
opts="save restore" |
25 |
|
26 |
depend() { |
27 |
need localmount |
28 |
after bootmisc modules isapnp coldplug hotplug |
29 |
} |
30 |
|
31 |
load_modules() { |
32 |
# List of drivers for each card. |
33 |
local DRIVERS="$(modprobe -c | sed -n -e 's/^alias \(snd-card-[[:digit:]]\+\) .*/\1/p')" |
34 |
|
35 |
# Fall back on the automated aliases if we don't have ALSA configured properly... |
36 |
if [ -z "${DRIVERS}" ] && \ |
37 |
( [ ! -r /proc/asound/cards ] || grep -q ' no soundcards ' /proc/asound/cards 2>/dev/null ) ; then |
38 |
ewarn "Could not detect custom ALSA settings. Loading all detected alsa drivers." |
39 |
DRIVERS="$(modprobe -c | sed -n -e '/^alias pci:.* snd.*/ s/^alias pci:[^ ]* \(.*\)/\1/p' | sort | uniq)" |
40 |
if [ -z "${DRIVERS}" ] ; then |
41 |
eerror "Unable to find any ALSA drivers. Have you compiled alsa-drivers correctly?" |
42 |
fi |
43 |
fi |
44 |
|
45 |
if [ "${ENABLE_OSS_EMUL}" = "yes" ] ; then |
46 |
DRIVERS="${DRIVERS} $(modprobe -l | sed -n -e '/snd.*oss/ s:.*\/\([[:alnum:]_-]\+\).ko:\1:p')" |
47 |
fi |
48 |
|
49 |
# We want to ensure snd-seq is loaded as it is needed for things like |
50 |
# timidity even if we don't use a real sequencer. |
51 |
DRIVERS="${DRIVERS} $(modprobe -l | sed -n -e '/snd.seq\./ s:.*\/\([[:alnum:]_-]\+\).ko:\1:p')" |
52 |
|
53 |
# We want to ensure snd-ioctl32 is loaded as it is needed for 32bit |
54 |
# compatibility |
55 |
DRIVERS="${DRIVERS} $(modprobe -l | sed -n -e '/snd.ioctl32\./ s:.*\/\([[:alnum:]_-]\+\).ko:\1:p')" |
56 |
|
57 |
local DRIVER= DMOD= |
58 |
for DRIVER in ${DRIVERS} ; do |
59 |
[ "${DRIVER}" = "off" ] && continue |
60 |
DMOD="$(echo "${DRIVER}" | sed -e 's/-/_/g')" |
61 |
if ! grep -q "^${DMOD} " /proc/modules ; then |
62 |
ebegin "Loading: ${DRIVER}" |
63 |
modprobe ${DRIVER} |
64 |
eend $? |
65 |
fi |
66 |
done |
67 |
|
68 |
if [ -f /proc/asound/seq/drivers ] ; then |
69 |
local SEQUENCERS="$(sed -n -e 's/\([^,]*\),empty,.*/\1/p' /proc/asound/seq/drivers)" |
70 |
local SEQUENCER |
71 |
for SEQUENCER in ${SEQUENCERS} ; do |
72 |
DMOD="$(echo "${SEQUENCER}" | sed -e 's/-/_/g')" |
73 |
if ! grep -q "^${DMOD} " /proc/modules ; then |
74 |
ebegin "Loading: ${SEQUENCER}" |
75 |
modprobe ${SEQUENCER} |
76 |
eend $? |
77 |
fi |
78 |
done |
79 |
fi |
80 |
|
81 |
for DRIVER in ${DRIVERS} |
82 |
do |
83 |
local TMP=${DRIVER##snd-} |
84 |
TMP=${TMP##snd_} |
85 |
if [ -x "${alsascrdir}/${TMP}" ] ; then |
86 |
ebegin "Running: ${alsascrdir}/${TMP}" |
87 |
"${alsascrdir}/${TMP}" |
88 |
eend $? |
89 |
fi |
90 |
done |
91 |
|
92 |
if [ ! -d /proc/asound ] || grep -q ' no soundcards ' /proc/asound/cards ; then |
93 |
eerror "ERROR: Failed to load necessary drivers" |
94 |
return 1 |
95 |
fi |
96 |
} |
97 |
|
98 |
unload_modules_24() { |
99 |
local LOADED_MODULES="$(lsmod | sed -n -e 's/^\(snd[^ ]*\) .*/\1/p')" |
100 |
local MODULE |
101 |
for MODULE in ${LOADED_MODULES} ; do |
102 |
rmmod "${MODULE}" |
103 |
done |
104 |
rmmod soundcore 2>/dev/null |
105 |
rmmod gameport 2>/dev/null |
106 |
|
107 |
lsmod | grep -vq '^snd' |
108 |
} |
109 |
|
110 |
unload_modules_recursive() { |
111 |
local revdeps="$(lsmod | sed -n -e "s/,/ /g" -e "s/^$1 *[0-9]* *[0-9]* \(.*\)/\1/p")" |
112 |
|
113 |
for module in ${revdeps} ; do |
114 |
unload_modules_recursive "${module}" |
115 |
done |
116 |
|
117 |
vebegin "Unloading: $1" |
118 |
rmmod --wait "$1" |
119 |
veend $? |
120 |
} |
121 |
|
122 |
unload_modules_26() { |
123 |
# First of all, remove the snd module and all the modules depending |
124 |
# on it, this should remove already most of ALSA modules. |
125 |
lsmod | grep -q "^snd[[:space:]]" && unload_modules_recursive snd |
126 |
|
127 |
# Then find the remaining ones, and handle them too. |
128 |
for module in $(lsmod | sed -n -e 's/^\(snd[^ ]*\) .*/\1/p'); do |
129 |
unload_modules_recursive "${module}" |
130 |
done |
131 |
|
132 |
lsmod | grep -vq "^snd" |
133 |
} |
134 |
|
135 |
terminate() { |
136 |
# |
137 |
# Kill processes holding open sound devices |
138 |
# |
139 |
# DEVS=`find /dev/ -follow -type c -maxdepth 1 -print 2>/dev/null | xargs ls -dils | grep "1*1[46]," | cut -d: -f2 | cut -d" " -f2; echo /proc/asound/dev/*` |
140 |
local ossdevs="/dev/admmidi* /dev/adsp* /dev/amidi* /dev/audio* /dev/dmfm* \ |
141 |
/dev/dmmidi* /dev/dsp* /dev/dspW* /dev/midi0* /dev/mixer* /dev/music \ |
142 |
/dev/patmgr* /dev/sequencer* /dev/sndstat" |
143 |
local alsadevs="/proc/asound/dev/* /dev/sound/* /dev/snd/*" |
144 |
fuser -k ${ossdevs} ${alsadevs} >/dev/null 2>/dev/null |
145 |
|
146 |
# remove all sequencer connections if any |
147 |
[ -f /proc/asound/seq/clients ] && type aconnect >/dev/null 2>/dev/null && aconnect --removeall |
148 |
} |
149 |
|
150 |
restore() { |
151 |
ebegin "Restoring Mixer Levels" |
152 |
|
153 |
if [ ! -r "${alsastatedir}/asound.state" ] ; then |
154 |
ewarn "No mixer config in ${alsastatedir}/asound.state, you have to unmute your card!" |
155 |
eend 0 |
156 |
return 0 |
157 |
fi |
158 |
|
159 |
local cards="$(sed -n -e 's/ *\([[:digit:]]*\) .*/\1/p' /proc/asound/cards)" |
160 |
local CARDNUM |
161 |
for cardnum in ${cards}; do |
162 |
[ -e /dev/snd/controlC${cardnum} ] || sleep 2 |
163 |
[ -e /dev/snd/controlC${cardnum} ] || sleep 2 |
164 |
[ -e /dev/snd/controlC${cardnum} ] || sleep 2 |
165 |
[ -e /dev/snd/controlC${cardnum} ] || sleep 2 |
166 |
alsactl -f "${alsastatedir}/asound.state" restore ${cardnum} \ |
167 |
|| ewarn "Errors while restoring defaults, ignoring" |
168 |
done |
169 |
|
170 |
for ossfile in "${alsastatedir}"/oss/card*_pcm* ; do |
171 |
[ -e "${ossfile}" ] || continue |
172 |
# We use cat because I'm not sure if cp works properly on /proc |
173 |
local procfile=${ossfile##${alsastatedir}/oss} |
174 |
procfile="$(echo "${procfile}" | sed -e 's,_,/,g')" |
175 |
if [ -e /proc/asound/"${procfile}"/oss ] ; then |
176 |
cat "${ossfile}" > /proc/asound/"${procfile}"/oss |
177 |
fi |
178 |
done |
179 |
|
180 |
eend 0 |
181 |
} |
182 |
|
183 |
save() { |
184 |
ebegin "Storing ALSA Mixer Levels" |
185 |
|
186 |
mkdir -p "${alsastatedir}" |
187 |
if ! alsactl -f "${alsastatedir}/asound.state" store; then |
188 |
eerror "Error saving levels." |
189 |
eend 1 |
190 |
return 1 |
191 |
fi |
192 |
|
193 |
for ossfile in /proc/asound/card*/pcm*/oss; do |
194 |
[ -e "${ossfile}" ] || continue |
195 |
local device=${ossfile##/proc/asound/} ; device=${device%%/oss} |
196 |
device="$(echo "${device}" | sed -e 's,/,_,g')" |
197 |
mkdir -p "${alsastatedir}/oss/" |
198 |
cp "${ossfile}" "${alsastatedir}/oss/${device}" |
199 |
done |
200 |
|
201 |
eend 0 |
202 |
} |
203 |
|
204 |
start() { |
205 |
if [ -f /proc/modules ] && [ "${LOAD_ON_START}" = "yes" ]; then |
206 |
ebegin "Loading ALSA modules" |
207 |
eindent |
208 |
load_modules |
209 |
eoutdent |
210 |
eend $? || return 1 |
211 |
fi |
212 |
|
213 |
if [ ! -d /proc/asound ]; then |
214 |
eerror "ALSA failed to load." |
215 |
eend 1 |
216 |
return 1 |
217 |
elif [ "${RESTORE_ON_START}" = "yes" ]; then |
218 |
restore |
219 |
fi |
220 |
|
221 |
return 0 |
222 |
} |
223 |
|
224 |
stop() { |
225 |
if [ ! -d /proc/asound ] ; then |
226 |
eerror "ALSA is not loaded" |
227 |
return 0 |
228 |
fi |
229 |
|
230 |
[ "${SAVE_ON_STOP}" = "yes" ] && save |
231 |
|
232 |
return 0 |
233 |
} |