virtual_oss(8): Improve hw.snd.basename_clone handling
If we request a /dev/dsp virtual_oss(8) device, we have to replace the sound(4) one by first disabling hw.snd.basename_clone. This sysctl tells sound(4) to not create the /dev/dsp alias for the default device. There are currently two issues with the way this is handled by virtual_oss(8), however: 1. It uses system(3) instead of sysctlbyname(3). 2. It does not restore hw.snd.basename_clone to its original value, so if prior to virtual_oss(8) running, hw.snd.basename_clone was enabled (which is the case by default), and it is closed at some point, hw.snd.basename_clone stays disabled, which is annoying, because users have to manually restore it, otherwise applications that open the default device (i.e., most) will not work. Fix both issues. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53621
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include <sys/nv.h>
|
#include <sys/nv.h>
|
||||||
#include <sys/sndstat.h>
|
#include <sys/sndstat.h>
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -52,6 +53,8 @@
|
|||||||
#include "int.h"
|
#include "int.h"
|
||||||
#include "virtual_oss.h"
|
#include "virtual_oss.h"
|
||||||
|
|
||||||
|
#define SYSCTL_BASECLONE "hw.snd.basename_clone"
|
||||||
|
|
||||||
pthread_mutex_t atomic_mtx;
|
pthread_mutex_t atomic_mtx;
|
||||||
pthread_cond_t atomic_cv;
|
pthread_cond_t atomic_cv;
|
||||||
|
|
||||||
@@ -1617,6 +1620,7 @@ volatile sig_atomic_t voss_exit = 0;
|
|||||||
|
|
||||||
static int voss_dsp_perm = 0666;
|
static int voss_dsp_perm = 0666;
|
||||||
static int voss_do_background;
|
static int voss_do_background;
|
||||||
|
static int voss_baseclone = 0;
|
||||||
static const char *voss_pid_path;
|
static const char *voss_pid_path;
|
||||||
|
|
||||||
uint32_t voss_dsp_rx_refresh;
|
uint32_t voss_dsp_rx_refresh;
|
||||||
@@ -1739,6 +1743,20 @@ usage(void)
|
|||||||
exit(EX_USAGE);
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Restore hw.snd.basename_clone if it was disabled by us.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
restore_baseclone(void)
|
||||||
|
{
|
||||||
|
if (voss_baseclone) {
|
||||||
|
if (sysctlbyname(SYSCTL_BASECLONE, NULL, NULL, &voss_baseclone,
|
||||||
|
sizeof(int)) < 0)
|
||||||
|
warn("Could not enable " SYSCTL_BASECLONE);
|
||||||
|
printf(SYSCTL_BASECLONE ": 0 -> %d\n", voss_baseclone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_compressor(struct virtual_profile *pvp)
|
init_compressor(struct virtual_profile *pvp)
|
||||||
{
|
{
|
||||||
@@ -1883,8 +1901,18 @@ dup_profile(vprofile_t *pvp, int *pamp, int pol, int rx_mute,
|
|||||||
* Detect /dev/dsp creation and try to disable system
|
* Detect /dev/dsp creation and try to disable system
|
||||||
* basename cloning automatically:
|
* basename cloning automatically:
|
||||||
*/
|
*/
|
||||||
if (strcmp(ptr->oss_name, "dsp") == 0)
|
if (strcmp(ptr->oss_name, "dsp") == 0) {
|
||||||
system("sysctl hw.snd.basename_clone=0");
|
size_t size;
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
size = sizeof(int);
|
||||||
|
if (sysctlbyname(SYSCTL_BASECLONE, &voss_baseclone,
|
||||||
|
&size, &x, size) < 0)
|
||||||
|
return ("Could not disable " SYSCTL_BASECLONE);
|
||||||
|
printf(SYSCTL_BASECLONE ": %d -> 0\n", voss_baseclone);
|
||||||
|
if (atexit(restore_baseclone) < 0)
|
||||||
|
return ("Could not set atexit callback");
|
||||||
|
}
|
||||||
|
|
||||||
/* create DSP character device */
|
/* create DSP character device */
|
||||||
pdev = cuse_dev_create(&vclient_oss_methods, ptr, NULL,
|
pdev = cuse_dev_create(&vclient_oss_methods, ptr, NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user