[Pkg-alsa-devel] Re: patch for several bugs

Bob McElrath bob+debian@mcelrath.org
Sat, 11 Sep 2004 15:18:04 -0700


--pvezYHf7grwyp3Bc
Content-Type: multipart/mixed; boundary="UugvWAfsgieZRqgk"
Content-Disposition: inline


--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

...with files attached now.

Bob McElrath [bob+debian@mcelrath.org] wrote:
> Attached are new versions of /etc/init.d/alsa and /etc/default/alsa for
> the alsa-base package.
> 
> This fixes several bugs that I just discovered are marked "pending
> upload".  Does that mean you have already fixed them?  Anyway, look at
> my solution, use it if you like it.
> 
> Also I have added support in these files for saving the contents of
>     /proc/asound/card[0-9]/pcm[0-9][pc]/oss
> which should contain something like:
>     quake2 0 0 direct
>     wine 0 0 direct
>     wine-preloader 0 0 direct
> and is necessary to get sound working with these programs.
> 
> I suggest that the alsa folks add these entries somewhere at install
> time, or get the maintainers of the relevant debian packages (quake2,
> wine) to add them.
> 
> --
> Cheers,
> Bob McElrath [Univ. of California at Davis, Department of Physics]
>     
>     It is unpatriotic to question the Kleptocracy.


--
Cheers,
Bob McElrath [Univ. of California at Davis, Department of Physics]
    
    It is unpatriotic to question the Kleptocracy.

--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="etc.default.alsa"

# Example configuration file for alsa-base.

# Set as true if you want the OSS compatibility layer
# to be automatically loaded as well.
startosslayer=true

# Save and restore the contents of /proc/asound/card?/pcm0?/oss
# (for setting quake, wine compatibility)
saveoss=true

# Set as true if you want to unload alsa modules before 
# your system suspends. This is currently useful if your
# machine hangs after resuming.
force_stop_modules_before_suspend=forcibly-unload-driver

# Should we save card and mixer settings using alsactl?
alsactl_store_on_shutdown=true

# Should we restore card and mixer settings using alsactl on startup?
alsactl_restore_on_startup=true

# Uncomment if you always want to stop alsa modules forcibly in
# /etc/init.d/alsa stop or restart by killing all of running
# applications which use sound devices.
#ALSA_KILL_MODE="force"

--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="etc.init.d.alsa"

#!/bin/sh

set -e

PATH=/usr/local/sbin:/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin

if [ "$(id -u)" != "0" ] && [ "$1" != "--help" ] &&
   [ "$1" != "help" ] && [ ! -z "$1" ]; then
    echo "$0: To $1 ALSA, you must be root."
    exit 1
fi

# Default settings
alsactl_store_on_shutdown="false"
alsactl_restore_on_startup="false"
runlevels_save='[2-5]'

[ -e /etc/default/alsa ] && . /etc/default/alsa

get_procs_using_sound() {
  $(lsof +D /dev -F rt | awk '/^p/ {pid=$1} /^t/ {type=$1} /^r0x(74|e)..$/ && type == "tCHR" {print pid}' | cut -c 2- | uniq)
}

case "$1" in
    start)
	printf "Restoring ALSA mixer settings ... "
        if [ "$alsactl_restore_on_startup" = "true" ]; then
            if alsactl restore > /dev/null 2>&1; then
                echo "done."
            else
                echo "failed:"
                echo "       You may want to run 'alsactl restore' manually to view any errors."
                exit 1
            fi
        fi
        if [ "$startosslayer" != "true" -o "$saveoss" = "true" ]; then
            modprobe snd_pcm_oss snd_mixer_oss snd_seq_oss
        fi
        if [ "$saveoss" = "true" ]; then
            printf "Restoring oss settings ... "
            for card in $(cd /proc/asound; ls -d card[0-9]); do
                for device in $(cd /proc/asound/$card; ls -d pcm*); do
                    if [ -f /etc/alsa/$card/$device/oss \
                         -a -f /proc/asound/$card/$device/oss ]; then
                        cat /etc/alsa/$card/$device/oss \
                            > /proc/asound/$card/$device/oss
                    fi
                done
            done
            echo "done."
        fi
	;;
    stop)
	if [ "$alsactl_store_on_shutdown" = "true" ]; then
	    if runlevel | grep -E "^$runlevels_save " > /dev/null 2>&1 \
	    || runlevel | grep -E " $runlevels_save\$" > /dev/null 2>&1; then
		printf "Storing ALSA mixer settings ... "
		if alsactl store > /dev/null 2>&1; then
		    sleep 1
		    echo "done."
		else
		    echo "failed"
		fi
            fi
            if [ "$saveoss" = "true" ]; then
                printf "Storing oss settings ... "
                for card in $(cd /proc/asound; ls -d card[0-9]); do
                    for device in $(cd /proc/asound/$card; ls -d pcm*); do
                        if [ ! -d /etc/alsa ]; then
                            mkdir /etc/alsa
                        fi
                        if [ ! -d /etc/alsa/$card ]; then
                            mkdir /etc/alsa/$card
                        fi
                        if [ ! -d /etc/alsa/$card/$device ]; then
                            mkdir /etc/alsa/$card/$device
                        fi
                        cat /proc/asound/$card/$device/oss \
                            > /etc/alsa/$card/$device/oss
                    done
                done
                echo "done."
	    fi
	fi
	;;
    force-stop|force-reload)
        printf "Terminating processes using sound ... "
        for SIGNAL in 15 9; do
            procs_using_sound=$(get_procs_using_sound)
            if [ ! -z "$procs_using_sound" ]; then
                kill -$SIGNAL $procs_using_sound
                sleep 2
            fi
	done
        echo "done"
	$0 stop
	rmmod=""
	case "$(modprobe --version 2>&1)" in
	    modprobe*)
		rmmod="rmmod -r"
		;;
	    module-init-tools*)
		rmmod="modprobe -r"
		;;
	esac
	printf "Unloading modules ... "
	for i in $(lsmod | awk '/^snd/ {print $1}'); do
	    $rmmod $i >/dev/null 2>&1 || :
	done
	echo "done"
	;;
    restart|reload)
	$0 stop && $0 start
	;;
    *)
	echo "Usage: /etc/init.d/alsa {start|stop|restart|reload|force-stop|force-reload}"
	exit 1
	;;
esac

--UugvWAfsgieZRqgk--

--pvezYHf7grwyp3Bc
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBQ3mcjwioWRGe9K0RAroNAKDytF8Vft7Dgn2Fe2D/ixQkMg5tWgCfTitz
oZCjSbQg/7TMb2o23KINIiA=
=mDMy
-----END PGP SIGNATURE-----

--pvezYHf7grwyp3Bc--