[Pkg-alsa-devel] [Debian ALSA CVS] debian/alsa-driver/debian (3 files)

Thomas Hood jdthood-guest@haydn.debian.org
Thu, 02 Sep 2004 04:49:01 -0600


    Date: Thursday, September 2, 2004 @ 04:49:00
  Author: jdthood-guest
    Path: /cvsroot/pkg-alsa/debian/alsa-driver/debian

Modified: alsa-base.conf alsa-base.init changelog

Upgrade initscript; improve comments in conf; update changelog accordingly


----------------+
 alsa-base.conf |   38 +++++++++++---------
 alsa-base.init |  103 ++++++++++++++++++++++++++++++++++++-------------------
 changelog      |   13 ++++++
 3 files changed, 102 insertions(+), 52 deletions(-)


Index: debian/alsa-driver/debian/alsa-base.conf
diff -u debian/alsa-driver/debian/alsa-base.conf:1.6 debian/alsa-driver/debian/alsa-base.conf:1.7
--- debian/alsa-driver/debian/alsa-base.conf:1.6	Tue Aug 31 21:16:40 2004
+++ debian/alsa-driver/debian/alsa-base.conf	Thu Sep  2 04:49:00 2004
@@ -1,21 +1,25 @@
-# Example configuration file for alsa-base.
-# Don't edit this file directly! Use dpkg-reconfigure alsa-base to change 
-# the values in this file.
+# Configuration file for alsa-base.
 
-# alsactl_store_on_shutdown is used to determine when alsactl store will be
-# run. If the setting is 'autosave always', the mixer settings will be saved
-# shutdown. If the setting is 'autosave once at next shutdown', the mixer
-# settings will be saved on the next shutdown, and never again. If the setting
-# is 'never autosave', the settings will never be saved.
+# alsactl_store_on_shutdown is used to determine when "alsactl store" will
+# be executed. If the setting is 'autosave always' then the command will
+# be executed on shutdown (if the setting of the runlevels_save variable
+# permits this). If the setting is 'autosave once at next shutdown' then
+# the command will be executed on the next shutdown and never again (if
+# the setting of the runlevels_save variable permits this). If the setting
+# is 'never autosave' then the command will not be executed.
 alsactl_store_on_shutdown="always autosave"
 
-# runlevels_save is used to determine in which runlevels (and from which
-# runlevels) mixer settings will be saved. The default value of '[2-5]' will
-# cause mixer settings to be saved whenever the system is in any regular
-# runlevel (2 through 5), or when the last runlevel was any regular runlevel.
-# The end result of this is that mixer settings won't be saved if you're
-# rebooting your system from single-user mode (which is a good thing as all
-# the mixer levels will be 0, resulting in muted sound on the next reboot).
-# Valid syntax same as a regular expression character range, with the
-# restriction that only valid runlevels are allowed.
+# On entering a runlevel in which alsa is configured as stopped (normally
+# runlevels 0, 1 and 6), the initscript "stop" method is executed.
+# Using the runlevels_save variable you can restrict the execution of
+# the "alsactl store" command to those occasions when the previous
+# runlevel was one of the runlevels matching the value of the variable.
+# Thus, the default value of '[2-5]' will cause mixer settings to be
+# saved when the system leaves any regular runlevel (2 through 5) to
+# enter a non-normal runlevel (0, 1 or 6).
+#
+# The point of this is to prevent the saving of mixer settings if you are
+# rebooting your system from single-user mode (which is a good thing as
+# all the mixer levels will be 0, resulting in muted sound on the next
+# reboot). The syntax is that of regular expression character range.
 runlevels_save='[2-5]'
Index: debian/alsa-driver/debian/alsa-base.init
diff -u debian/alsa-driver/debian/alsa-base.init:1.49 debian/alsa-driver/debian/alsa-base.init:1.50
--- debian/alsa-driver/debian/alsa-base.init:1.49	Thu Sep  2 03:15:36 2004
+++ debian/alsa-driver/debian/alsa-base.init	Thu Sep  2 04:49:00 2004
@@ -17,64 +17,97 @@
 alsactl_store_on_shutdown="always autosave"
 runlevels_save='[2-5]'
 
-[ -e /etc/default/alsa ] && . /etc/default/alsa
+[ -f /etc/default/alsa ] && . /etc/default/alsa
 
-case "$1" in
-    start)
-	printf "Restoring ALSA mixer settings ... "
+start()
+{
+	# ALSA mixer settings should be restored via the module loader
+	# For now, continue to do it manually
+	printf "Restoring ALSA mixer settings..."
 	sleep 5
 	if alsactl restore > /dev/null 2>&1; then
 	    echo "done."
+	    return 0
 	else
-	    echo "failed:"
-	    echo "       You may want to run 'alsactl restore' manually to view any errors."
-	    exit 1
+	    echo "failed. Run 'alsactl restore' manually to view error messages."
+	    return 1
 	fi
-	;;
-    stop)
+}
+
+stop()
+{
 	if [ "$alsactl_store_on_shutdown" != "never autosave" ]; 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 ... "
+		printf "Storing ALSA mixer settings..."
 		if alsactl store > /dev/null 2>&1; then
 		    sleep 1
 		    echo "done."
+		    return 0
 		else
-		    echo "failed"
+		    echo "failed."
+		    return 1
 		fi
 	    fi
 	fi
-	;;
-    force-stop|force-reload)
-	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)"
-	if [ ! -z "$procs_using_sound" ]; then
-	    printf "Terminating processes ... "
-	    kill $procs_using_sound
-	    sleep 2
-	    kill -9 $procs_using_sound
-	    echo "done"
+}
+
+force_stop()
+{
+	set_procs_using_sound() {
+	    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)"
+	}
+	set_procs_using_sound
+	if [ "$procs_using_sound" ] ; then
+	    printf "Terminating processes: "
+	    for attempt in 1 2 3 ; do
+		printf "${procs_using_sound}..."
+		kill $procs_using_sound || :
+		sleep 1
+		set_procs_using_sound
+		[ "$procs_using_sound" ] || break
+	    done
+	    # Either no more procs using sound or attempts ran out
+	    if [ "$procs_using_sound" ] ; then
+		printf "(with SIGKILL) ${procs_using_sound}..."
+		kill -9 $procs_using_sound || :
+		sleep 1
+	    fi
+	    set_procs_using_sound
+	    if [ "$procs_using_sound" ] ; then
+		echo "failed."
+		return 1
+	    fi
+	    echo "done."
 	fi
-	$0 stop
+	stop || :
 	rmmod=""
 	case "$(modprobe --version 2>&1)" in
-	    modprobe*)
-		rmmod="rmmod -r"
-		;;
-	    module-init-tools*)
-		rmmod="modprobe -r"
-		;;
+	    modprobe*) rmmod="rmmod -r" ;;
+	    module-init-tools*) rmmod="modprobe -r" ;;
 	esac
-	printf "Unloading modules ... "
+	printf "Unloading sound driver 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
-	;;
+	if [ "$(lsmod | awk '/^snd/ {print $1}')" ] ; then
+	    echo "failed."
+	    return 1
+	else
+	    echo "done."
+	    return 0
+	fi
+}
+
+case "$1" in
+    start) start ;;
+    stop) stop ;;
+    force-stop) force_stop ;;
+    restart) stop ; start ;;
+    reload) stop && start ;;
+    force-reload) force-stop && start ;;
     *)
-	echo "Usage: /etc/init.d/alsa {start|stop|restart|reload|force-stop|force-reload}"
-	exit 1
+	echo "Usage: /etc/init.d/alsa {start|stop|restart|reload|force-stop|force-reload}" >&2
+	exit 3
 	;;
 esac
Index: debian/alsa-driver/debian/changelog
diff -u debian/alsa-driver/debian/changelog:1.265 debian/alsa-driver/debian/changelog:1.266
--- debian/alsa-driver/debian/changelog:1.265	Tue Aug 31 21:16:41 2004
+++ debian/alsa-driver/debian/changelog	Thu Sep  2 04:49:00 2004
@@ -30,6 +30,19 @@
       Carlos Galisteo)
   * Jordi Mallach:
     - Update Catalan Debconf translation.
+  * Thomas Hood:
+    - /etc/init.d/alsa:
+      + Don't fail if kill fails because of disappeared process
+        (Closes: #269494)
+      + Tell the user if processes couldn't be stopped or if
+        modules couldn't be unloaded  (Closes: #269453)
+      + Send usage to stderr and exit 3 (as per LSB)
+      + Use more functions
+      + On restart, attempt start even if stop fails
+      + On force-reload, start after force-stop
+      + Don't pad '...' with spaces (as per policy 9.4)
+    - /etc/default/alsa
+      + Try to improve comments some more
   * Unreleased.
 
  -- Steve Kowalik <stevenk@debian.org>  Wed,  1 Sep 2004 13:07:24 +1000