Bug 25910

Summary: [sound] Kernel sound driver may die if a program crashes (workaround)
Product: Base System Reporter: Nate Dannenberg <natedac>
Component: kernAssignee: freebsd-multimedia (Nobody) <multimedia>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Nate Dannenberg 2001-03-19 06:00:02 UTC
If a program crashes while it's using the sound device, the kernel fails 
to close the device so that other programs may use it.  The device is left 
in an open, "busy" state.

Fix: 

Don't compile the sound driver into the kernel.  Instead, use the loadable 
module.  I got a chance to test this out, and sure enough, I can restore 
the sound after the driver dies, without rebooting the system (which is 
the case with the in-kernel driver)...

Exit all audio applications, including those that may be using the mixer 
device (gqmpeg, aumix) or that are just acting as a server/daemon for 
other programs (esd).  Unload the driver modules and reload them.

These few lines will automate the process a little bit:

#!/usr/local/bin/bash   # or any other path-capable shell.
killall esd
killall mpg123
killall gqmpeg
killall xmp
killall aumix

sleep 1

kldunload snd_pcm
kldunload snd_solo

sleep 1

kldload /modules/snd_pcm
kldload /modules/snd_solo

mixer line 0
mixer line1 0
mixer mic 0
mixer synth 0
mixer cd 100
mixer pcm 50
mixer vol 50
#  end...

If the sound drivers are compiled into the kernel, it is necessary to shut 
the computer down and re-start it to restore sound once the driver dies.  
With the modules, the above code seems to work, preserving what may be 
rather important uptime.
How-To-Repeat: 
Run any program like mpg123, and find a way to cause it to crash.  Now try 
to play something else with that or any other audio application.
Comment 1 Kris Kennaway freebsd_committer freebsd_triage 2001-03-24 05:24:48 UTC
Responsible Changed
From-To: freebsd-bugs->cg

Cameron is the soundmeister
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2004-09-09 20:33:21 UTC
Responsible Changed
From-To: cg->sound

With permission, reassign to mailing list alias.
Comment 3 Alexander Leidinger freebsd_committer freebsd_triage 2005-09-11 10:36:25 UTC
State Changed
From-To: open->feedback

The sound system changed a lot since 4.3. Does this still apply to 
5.[34] or -current? 

Internal note: This PR should be closed after 2 months if we don't get 
an answer.
Comment 4 Alexander Leidinger freebsd_committer freebsd_triage 2005-09-11 19:57:04 UTC
State Changed
From-To: feedback->closed

Originator address bounces (invalid recipient). 

If someone has this problem too, please open a new PR.