From nobody@FreeBSD.org  Fri Feb  8 10:04:09 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C076D16A418
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Feb 2008 10:04:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id B2A0013C455
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Feb 2008 10:04:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m18A239W016468
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 8 Feb 2008 10:02:03 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m18A22ip016467;
	Fri, 8 Feb 2008 10:02:02 GMT
	(envelope-from nobody)
Message-Id: <200802081002.m18A22ip016467@www.freebsd.org>
Date: Fri, 8 Feb 2008 10:02:02 GMT
From: Aragon Gouveia <aragon@phat.za.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Handling newly attached pcm devices (eg. via uaudio)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120406
>Category:       conf
>Synopsis:       [devd] [patch] Handle newly attached pcm devices (eg. via uaudio)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-usb
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 08 10:10:00 UTC 2008
>Closed-Date:    
>Last-Modified:  Sat Nov  3 23:10:00 UTC 2012
>Originator:     Aragon Gouveia
>Release:        7.0-RC1
>Organization:
>Environment:
FreeBSD geek.pcs.intranet 7.0-RC1 FreeBSD 7.0-RC1 #0: Wed Jan 16 17:07:28 SAST 2008     root@geek.pcs.intranet:/usr/obj/usr/src/sys/GEEK  i386
>Description:
On my FreeBSD workstations I frequently use a USB sound device (headphone
amplifier).  I typically plug it in and out only when I need it, and
expect (or hope!) for my system to use it when it's plugged in, but use
the onboard sound when it is unplugged.

On FreeBSD 7 I used to set hw.snd.default_unit to 1 (from 0) after
plugging the device in and then set the mixer levels to how I want them.
I've subsequently automated this ala devd and a shell script to do
precisely the same thing, except the shell script also calls
/etc/rc.d/mixer to restore the saved mixer settings in /var/db. I would
like to PR my work in the hope of someone committing it as I think it
might be useful to others.

I've included a devd.conf addition and an rc script for inclusion to
/etc/rc.d.  The rc script only works if pcm_defaulthot is set to YES
in /etc/rc.conf, and I would say it should be set to NO by default.

>How-To-Repeat:

>Fix:
devd.conf entry:

attach 100 {
	device-name "pcm[0-9]+";
	action "/etc/rc.d/pcm start $device-name";
};


Patch attached with submission follows:

#!/bin/sh
#

# PROVIDE: pcm
# REQUIRE: DAEMON cleanvar
# KEYWORD: nojail

. /etc/rc.subr

name=pcm
rcvar="pcm_defaulthot"
start_cmd="pcm_start"

load_rc_config $name

pcm_start()
{
	local pcm_unit
	
	pcm_unit=${pcm_device#pcm}
	if [ "${pcm_unit}" -ge 0 ]; then
		sysctl -w hw.snd.default_unit=${pcm_unit}
		/etc/rc.d/mixer start mixer${pcm_unit}
	fi
}

if [ -n "$2" ]; then
	pcm_device=$2
	run_rc_command $*
fi


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Feb 8 16:08:44 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120406 

From: Aragon Gouveia <aragon@phat.za.net>
To: bug-followup@FreeBSD.org, aragon@phat.za.net
Cc:  
Subject: Re: conf/120406: [devd] [patch] Handle newly attached pcm devices (eg. via uaudio)
Date: Sun, 11 May 2008 19:04:11 +0200

 Hi,
 
 I noticed today that there is a sysctl variable, hw.snd.default_auto, that
 performs half the functionality of my script - great!  Still no mixer
 restoral though so I think it might be worth considering my script minus the
 sysctl line.
 
 Has anyone taken a look at this?
 
 
 Regards,
 Aragon
Responsible-Changed-From-To: freebsd-rc->freebsd-usb 
Responsible-Changed-By: crees 
Responsible-Changed-When: Wed Oct 31 18:35:43 UTC 2012 
Responsible-Changed-Why:  
I definitely think that rc is the wrong place for this.  It's a good 
idea, but it needs integrating into devd; I don't see that is will ever 
need executing on boot. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120406 

From: Patrick Lamaiziere <patfbsd@davenulle.org>
To: bug-followup@FreeBSD.org, aragon@phat.za.net
Cc:  
Subject: Re: conf/120406: [devd] [patch] Handle newly attached pcm devices
 (eg. via uaudio)
Date: Sun, 4 Nov 2012 00:07:04 +0100

 Hello,
 
 In my opinion this kind of behavior should be handle by the user, using
 hand made devd entry, unless there is a benefit for most of users.
 
 For example I use a guitar effects processor which is seen as uaudio(4)
 device. When I plug in, I really don't want it to auto-magically change
 the default sound unit (I use it on input). 
 
 (my 2 cents)
 
 Regards.
>Unformatted:
