1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#
# A set of common functions used by alsa-base scripts.
# Copyright (c) 2000. Masato Taruishi. All rights reserved.
# 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.
update_modutils_conf() {
if [ ! -f /etc/modutils/alsa ] || [ -L /etc/modutils/alsa ]; then
if [ ! /etc/alsa/modutils/$alsa_major_version -ef /etc/modutils/alsa ]; then
rm -f /etc/modutils/alsa
if [ -f /etc/alsa/modutils/$alsa_major_version ]; then
ln -s /etc/alsa/modutils/$alsa_major_version /etc/modutils/alsa
fi
/sbin/update-modules
elif [ ! -f /etc/alsa/modutils/$alsa_major_version ]; then
rm /etc/modutils/alsa
/sbin/update-modules
fi
fi
}
get_alsa_version() {
if [ ! -d /proc/asound ]; then
if ! modprobe snd 2> /dev/null; then
/sbin/update-modules > /dev/null 2>&1
if ! modprobe snd 2> /dev/null; then
alsa_version="none"
alsa_major_version="none"
return
fi
fi
load=1
fi
alsa_version=`cat /proc/asound/version | head -1 | cut -d' ' -f 7 | cut -d. -f -3`
alsa_major_version=`echo $alsa_version | cut -d. -f -2`
if [ "$load" = "1" ]; then
modprobe -r snd 2> /dev/null || true
fi
}
get_alsactl()
{
if [ -x /usr/sbin/alsactl ]; then
alsactl_major_version=`alsactl -v | cut -d' ' -f 3 | cut -d. -f-2`
if [ "$alsa_major_version" = "$alsactl_major_version" ]; then
alsactl=/usr/sbin/alsactl
fi
fi
if [ "x$alsactl" = "x" ] &&
[ -x "/usr/sbin/alsactl-$alsa_major_version" ]; then
alsactl=/usr/sbin/alsactl-$alsa_major_version
fi
}
get_sound_devs() {
sound_devs_dev=`find /dev -type c 2> /dev/null | xargs ls -l 2> /dev/null | awk -F' ' '{print $5,$10;}' | awk '/^14,/ || /^116,/ {printf "%s\n", $2;}'|sort|uniq|tr '\n' ' '`
}
get_sound_devs_proc() {
sound_devs_dev_proc=`find /proc/asound/dev -type c 2> /dev/null | xargs ls -l 2> /dev/null | awk -F' ' '{print $5,$10;}' | awk '/^14,/ || /^116,/ {printf "%s\n", $2;}'|sort|uniq|tr '\n' ' '`
}
get_procs_using_sound_devs() {
procs_using_sound_devs=`echo $sound_devs_dev $sound_devs_dev_proc | xargs fuser 2> /dev/null | awk -F' ' '{print $2}'|sort|uniq|tr '\n' ' '`
}
kill_procs_using_sound_devs() {
get_procs_using_sound_devs
if [ -n "$procs_using_sound_devs" ]; then # There are procs to kill
sleep 1 # Wait a sec: they might release the device
get_procs_using_sound_devs
if [ -n "$procs_using_sound_devs" ]; then # There are still procs to kill
echo -n "but first, terminating (SIGTERM) pid ${procs_using_sound_devs}"
kill -TERM $procs_using_sound_devs >> /dev/null
echo -n "."
sleep 1
echo -n "."
sleep 1
echo -n ". "
get_procs_using_sound_devs
if [ -n "$procs_using_sound_devs" ]; then # There are still procs to kill
echo -n "and killing (SIGKILL) pid ${procs_using_sound_devs}... "
kill -KILL $procs_using_sound_devs >> /dev/null
fi
fi
fi
}
# kill -STOPing processes using sound devicces.
stop_procs_using_sound_devs() {
get_procs_using_sound_devs
if [ -n "$procs_using_sound_devs" ] && [ ! -f /var/lib/alsa-base/alsa-suspend-list ]; then
procs_using_sound_devs=`ps --no-headers $procs_using_sound_devs | awk -F' ' '$3 ~ /[^T]/ { print $1;}'`
for proc in $procs_using_sound_devs
do
kill -STOP $proc >> /dev/null && echo -n " $proc" >> /var/lib/alsa-base/alsa-suspend-list
done
chmod 600 /var/lib/alsa-base/alsa-suspend-list
fi
}
# kill -CONTing processes using sound devicces.
cont_procs_using_sound_devs() {
if [ -O /var/lib/alsa-base/alsa-suspend-list ]; then
for proc in `cat /var/lib/alsa-base/alsa-suspend-list`
do
kill -CONT $proc >> /dev/null || true
done
fi
rm -f /var/lib/alsa-base/alsa-suspend-list
}
disable_sound_devs() {
if [ -z "$ALSA_KEEP_DEV_PERMS" ]; then
for file in $sound_devs_dev; do
if [ -e $file ]; then
perm=`perl -e "printf \"%04o\", (stat(\"$file\"))[2] & 07777;"`
install -d /var/lib/alsa-base/`dirname $file`
test -e /var/lib/alsa-base/$file || echo $perm > /var/lib/alsa-base/$file
chmod 000 $file
fi
done
fi
}
enable_sound_devs() {
if [ -z "$ALSA_KEEP_DEV_PERMS" ]; then
for file in $sound_devs_dev; do
if [ -O /var/lib/alsa-base/$file ] && [ -e $file ]; then
perm=`cat /var/lib/alsa-base/$file`
rm /var/lib/alsa-base/$file
chmod $perm $file
fi
done
fi
}
disable_esd() {
esduser=`ps -o %U --no-heading -C esd` || return 0
[ -n "$esduser" ] && (echo -n 'muting esd ... ' && su $esduser --command='esdctl standby standbymode') | logger -t $0
}
enable_esd() {
esduser=`ps -o %U --no-heading -C esd` || return 0
[ -n "$esduser" ] && (echo -n 'unmuting esd ... ' && su $esduser --command='esdctl resume standbymode') | logger -t $0
}
|