Bug 293582 - Unknown oid 'hw.snd.default_unit' message at startup and shutdown
Summary: Unknown oid 'hw.snd.default_unit' message at startup and shutdown
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Christos Margiolis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-03-04 14:44 UTC by Ralf Wenk
Modified: 2026-03-13 11:50 UTC (History)
1 user (show)

See Also:


Attachments
Verified proposed patch. (313 bytes, patch)
2026-03-05 16:31 UTC, Ralf Wenk
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Wenk 2026-03-04 14:44:51 UTC
Hi,

on VMs without any sound device /etc/rc.d/virtual_oss triggers sysctl(8) to
output the error message "unknown oid 'hw.snd.default_unit'" on the console
at system startup or shutdown.

The rc.conf variable virtual_oss_enable has its default value of "NO" from
/etc/defaults/rc.conf.

Without much changing of virtual_oss script a simple solution would be to
redirect stderr to /dev/null while executing sysctl(8).

Regards

  Ralf
Comment 1 Christos Margiolis freebsd_committer freebsd_triage 2026-03-05 15:03:34 UTC
I suspect your proposal will also fail, but because virtual_oss will try to use "/dev/dsp" with the -f option (see script), which won't exist if you have no sound device available at that time. In fact, the commit that introduced the sysctl command [1] in fact indirectly fixes what I just described.

If you run a VM without sound devices, and the virtual_oss rc service is disabled by default, how do you end up running into this error in the first place?

[1] https://cgit.freebsd.org/src/commit/?id=06b466526a7fc35cc6fc5bf6f6269e7f3a0a7aea
Comment 2 Ralf Wenk 2026-03-05 15:36:35 UTC
(In reply to Christos Margiolis from comment #1)

> If you run a VM without sound devices, and the virtual_oss rc service is
> disabled by default, how do you end up running into this error in the first
> place?

Because the default_unit variable gets its value from sysctl set up
before the value of virtual_oss_enable is evaluated.

So $(sysctl -n hw.snd.default_unit) is called regardless of virtual_oss_enable's value.

Please see the excerpt from the output of
sh -xv /etc/rc.d/virtual_oss start
on such a VM:

...
configs=
+ configs=''
pidpath="/var/run/${name}"
+ pidpath=/var/run/virtual_oss
default_unit=$(sysctl -n hw.snd.default_unit)
+ sysctl -n hw.snd.default_unit
sysctl: unknown oid 'hw.snd.default_unit'
+ default_unit=''
virtual_oss_default_args="\
        -S \
        -C 2 \
        -c 2 \
        -r 48000 \
        -b 24 \
        -s 8ms \
        -i 8 \
        -f /dev/dsp${default_unit} \
        -d dsp \
        -t vdsp.ctl"
+ virtual_oss_default_args=$'\t-S \t-C 2 \t-c 2 \t-r 48000 \t-b 24 \t-s 8ms \t-i 8 \t-f /dev/dsp \t-d dsp \t-t vdsp.ctl'

# Set to NO by default. Set it to "YES" to enable virtual_oss.
: "${virtual_oss_enable:="NO"}"
+ : NO
...
Comment 3 Christos Margiolis freebsd_committer freebsd_triage 2026-03-05 16:00:11 UTC
(In reply to rz-rpi03 from comment #2)
Is the issue addressed if you redirect sysctl's stderr to /dev/null as you said, or are there other problems with this approach?
Comment 4 Ralf Wenk 2026-03-05 16:09:39 UTC
(In reply to Christos Margiolis from comment #3)
Just changed the rc.d script as suggested on a spare VM and rebooted.
I did not notice any negative effects on shutdown and boot.

So I think there are no other problems with this approach.
Comment 5 Christos Margiolis freebsd_committer freebsd_triage 2026-03-05 16:15:53 UTC
(In reply to rz-rpi03 from comment #4)
Feel free to attach the patch and I'll commit it right away. Thanks.
Comment 6 Ralf Wenk 2026-03-05 16:31:14 UTC
Created attachment 268559 [details]
Verified proposed patch.

Simple fix as suggested.
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-03-06 12:28:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e85f221def717660c9daf4c0616dfb9cdfb75827

commit e85f221def717660c9daf4c0616dfb9cdfb75827
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-03-06 12:27:03 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-03-06 12:27:03 +0000

    rc: virtual_oss: Silence potential hw.snd.default_unit error

    PR:             293582
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week

 libexec/rc/rc.d/virtual_oss | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2026-03-13 11:50:23 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=63888350d583e370814abb5c078244cd8ddf8eeb

commit 63888350d583e370814abb5c078244cd8ddf8eeb
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-03-06 12:27:03 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-03-13 11:49:23 +0000

    rc: virtual_oss: Silence potential hw.snd.default_unit error

    PR:             293582
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week

    (cherry picked from commit e85f221def717660c9daf4c0616dfb9cdfb75827)

 libexec/rc/rc.d/virtual_oss | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)