From nobody Tue Nov 11 12:08:28 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4d5QKn2KRVz6GLT5; Tue, 11 Nov 2025 12:08:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d5QKn050Gz3cBT; Tue, 11 Nov 2025 12:08:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762862909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sHuKWHmZnVmfNjW+nMt2Q0YNLyJvcdmJPWcmWDK3guk=; b=cealz/Ib0x37Z6qs3htFbzhIB2Nc5Fsabm9C+co9ZEvzll9wL0OsJxymAkzTSuQbza5zng lFwQZ+nPB676PX++MDveE7QVKbreSYbZllqtMrPomtPApw9/HXv0SyrQZEHMUzbPTUQMj4 ORsqMZ0H9dL9Mpax3VQZqMyfgMYFIDixi+kzcgt8v5o9hwO5+ZXGVzl+vG/mRW9z0VryQw AR1TpzQ1IgceZDdvNTiiXpz48MFuwy1s+Nci5e54vd8Ny+eozDrYTcQ/He7w2H6xZ+S4Pq Z+0TmnocAdvOjhi1Tn6NKXLfoNWMA2OF3ORrJ996da4QUnXCeUhoTffhjV+MMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762862909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sHuKWHmZnVmfNjW+nMt2Q0YNLyJvcdmJPWcmWDK3guk=; b=gTJTUDQxzCIPmrKjwYTqaK1G9XKB71XpUUIESloHd8xh2eAur7CvE+b0Dz5u61Y1TbqYXZ Z20/Q+ZRidLuBGGLtuO/WTDN+v7F4xTpMcPDaFftVbB1sghqYs6sV6Le9nQJdadbucTOz4 429DQopVormVaQOnlFwKxSKG3Cw1TBEzzqrBdQrYcYI2XuJMXQb0ZfcaAfoP6Ey+AJbPpI 38jMDNBuRW4NmiawBEMHYYMI1m6kM4+3xHJpWaAHvNKMp5y7fIYEU/mytykbu19Fj9KcWX N06wSNifKu+YXrR9apCPYiPbmgX8y669kA7aEJ4YZRYiOoMhJO7MTCDPBt0iiQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1762862909; a=rsa-sha256; cv=none; b=Bip2lbKsPKzPkvXC9V9D0XyRqIupESc4DpZqIM9MJ7eXgN2fPKZVkHso/L/cCLMpD4X074 90YPgGIasT5sHEvUgfH/xltfDJt35Vqkyx0x8+VQQ7BUAppa6oE2vpvkd8ICWeMp5URv1c 6+ZkuBwtCC8/OXxh5H7yrZSMOOcfRIuwvpN/AiMNUVbRPWVR9hwsSoJPfnF+2DK4gx2XTt jKg8eItN2R/PwpQk7B7kUIo/fCdVk7tTJ9+0FHGbn5j/o7tOjOM+8AcApbOzHJkKq3US4E DtVhtZuCJFOF9WHJ2ThNKeCzSxJVAW2cDtGc0McuyJ/v+1KsScih642JeXR5nQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4d5QKm6lxyz13Zm; Tue, 11 Nov 2025 12:08:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5ABC8Sk5035688; Tue, 11 Nov 2025 12:08:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5ABC8S2J035685; Tue, 11 Nov 2025 12:08:28 GMT (envelope-from git) Date: Tue, 11 Nov 2025 12:08:28 GMT Message-Id: <202511111208.5ABC8S2J035685@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: e5c0d7020f3d - main - virtual_oss(8): Improve hw.snd.basename_clone handling List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e5c0d7020f3d040b28dc7ca0cda9926e07e5aaf4 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=e5c0d7020f3d040b28dc7ca0cda9926e07e5aaf4 commit e5c0d7020f3d040b28dc7ca0cda9926e07e5aaf4 Author: Christos Margiolis AuthorDate: 2025-11-11 12:07:44 +0000 Commit: Christos Margiolis CommitDate: 2025-11-11 12:07:44 +0000 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 --- usr.sbin/virtual_oss/virtual_oss/main.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/usr.sbin/virtual_oss/virtual_oss/main.c b/usr.sbin/virtual_oss/virtual_oss/main.c index f2fd085664ed..28095880c201 100644 --- a/usr.sbin/virtual_oss/virtual_oss/main.c +++ b/usr.sbin/virtual_oss/virtual_oss/main.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,8 @@ #include "int.h" #include "virtual_oss.h" +#define SYSCTL_BASECLONE "hw.snd.basename_clone" + pthread_mutex_t atomic_mtx; 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_do_background; +static int voss_baseclone = 0; static const char *voss_pid_path; uint32_t voss_dsp_rx_refresh; @@ -1739,6 +1743,20 @@ usage(void) 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 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 * basename cloning automatically: */ - if (strcmp(ptr->oss_name, "dsp") == 0) - system("sysctl hw.snd.basename_clone=0"); + if (strcmp(ptr->oss_name, "dsp") == 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 */ pdev = cuse_dev_create(&vclient_oss_methods, ptr, NULL,