Subject: Re: /etc/rc.d/mixerctl
To: None <tech-userlevel@netbsd.org>
From: TAMURA Kent <kent@netbsd.org>
List: tech-userlevel
Date: 10/11/2002 18:44:35
In message "Re: /etc/rc.d/mixerctl"
    on 02/10/11, ITOH Yasufumi <itohy@netbsd.org> writes:
> > How about the following change?  It saves all mixer values at
> > the shutdown stage and restore them at the boot stage.
> 
> Two comments:
>   - The save and restore should be configurable (in rc.conf or whatever).
>     User may like to see the default values after reboot.
> 
>   - Only one device (mixer0) is saved and restored.
>     It's nice if it can be configured to handle more than one devices.

Ok, I merged Julio's scirpt in misc/15648.

* If only mixerctl=YES:
	It works as ever.  It simply sets /etc/mixerctl.conf to /dev/mixer.
* If mixerctl=YES and savedmixers="mixer0 mixer2 blahblah":
	It saves and restores each mixer in $savedmixers.
	/etc/mixerctl.conf affects as ever.

Other comments?

-- 
TAMURA Kent <kent2002@hauN.org> <kent@netbsd.org>


Index: defaults/rc.conf
===================================================================
RCS file: /cvsroot/basesrc/etc/defaults/rc.conf,v
retrieving revision 1.42
diff -u -r1.42 rc.conf
--- defaults/rc.conf	2002/08/27 14:12:14	1.42
+++ defaults/rc.conf	2002/10/11 09:35:21
@@ -247,3 +247,8 @@
 # Configuration of "tpctl" touch panel calibration utility
 #
 tpctl=NO		tpctl_flags=""
+
+# Mixer setting
+#
+mixerctl=NO		savedmixers=""		# "mixer0 mixer1" means saving
+						# and restoring their settings
Index: rc.d/mixerctl
===================================================================
RCS file: /cvsroot/basesrc/etc/rc.d/mixerctl,v
retrieving revision 1.4
diff -u -r1.4 mixerctl
--- rc.d/mixerctl	2002/07/16 03:24:24	1.4
+++ rc.d/mixerctl	2002/10/11 09:35:21
@@ -5,21 +5,45 @@
 
 # PROVIDE: mixerctl
 # REQUIRE: mountcritremote
+# KEYWORD: shutdown
 
 . /etc/rc.subr
 
 name="mixerctl"
 start_cmd="mixerctl_start"
-stop_cmd=":"
+stop_cmd="mixerctl_stop"
 
 mixerctl_start()
 {
+	if [ -n "$savedmixers" ]; then
+		echo -n "Restoring mixer settings:"
+		for mix in $savedmixers; do
+			if [ -s /var/db/${mix}.conf ]; then
+				echo -n " $mix"
+				/usr/bin/mixerctl -f /dev/$mix -n -w \
+					`/bin/cat /var/db/${mix}.conf`
+			fi
+		done
+		echo "."
+	fi
 	if [ -r /etc/mixerctl.conf ]; then
 		echo "Setting mixerctl variables..."
 		while read setting; do
-			[ -z "$setting" ] || mixerctl -n -w $setting
+			[ -z "$setting" ] || /usr/bin/mixerctl -n -w $setting
 		done < /etc/mixerctl.conf
 	fi
+}
+
+mixerctl_stop()
+{
+	echo -n "Saving mixer settings:"
+	if [ -n "$savedmixers" ]; then
+		for mix in $savedmixers; do
+			echo -n " $mix"
+			/usr/bin/mixerctl -f /dev/$mix -a > /var/db/${mix}.conf
+		done
+	fi
+	echo "."
 }
 
 load_rc_config $name