rc: virtual_oss: Some bug fixes #33

Manually merged
christos merged 3 commits from christos/rc into main 2026-05-28 14:07:20 +00:00 AGit
Member

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

Sponsored by: The FreeBSD Foundation MFC after: 1 week
rc: virtual_oss: Define variables in rc.conf
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
87913bd178
They will now be part of /etc/defaults/rc.conf and be accessible by
sysrc(8).

Fixes:		70e27ecba5 ("virtual_oss: Introduce virtual_oss_default_control_device rc variable")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
@ -740,0 +748,4 @@
-b 24 \
-s 8ms \
-i 8 \
-f /dev/dsp$(sysctl -n hw.snd.default_unit 2>/dev/null) \
Author
Member

The sysctl command here does not take effect. Is there a way to make this work somehow?

The sysctl command here does not take effect. Is there a way to make this work somehow?
Member

I tend to agree with @Omp that /etc/defaults/rc.conf may not be the best place to call sysctl. That said, I think this is working for me. Right after a reboot, I see virtual_oss is running as 4660 - S<s 0:00.68 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 -b 24 -s 8ms -i 8 -f /dev/dsp3 -d dsp -t vdsp.ctl. Could there be a race condition where the sysctl may run before or after the devices are created?

I tend to agree with @Omp that `/etc/defaults/rc.conf` may not be the best place to call `sysctl`. That said, I think this is working for me. Right after a reboot, I see `virtual_oss` is running as ` 4660 - S<s 0:00.68 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 -b 24 -s 8ms -i 8 -f /dev/dsp3 -d dsp -t vdsp.ctl`. Could there be a race condition where the sysctl may run before or after the devices are created?
Author
Member

@jrm wrote in #33 (comment):

I tend to agree with @Omp that /etc/defaults/rc.conf may not be the best place to call sysctl. That said, I think this is working for me. Right after a reboot, I see virtual_oss is running as 4660 - S<s 0:00.68 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 -b 24 -s 8ms -i 8 -f /dev/dsp3 -d dsp -t vdsp.ctl. Could there be a race condition where the sysctl may run before or after the devices are created?

Probably. I think it's better to do what Mateusz said indeed.

@jrm wrote in https://ron-dev.freebsd.org/FreeBSD/src/pulls/33#issuecomment-492: > I tend to agree with @Omp that `/etc/defaults/rc.conf` may not be the best place to call `sysctl`. That said, I think this is working for me. Right after a reboot, I see `virtual_oss` is running as ` 4660 - S<s 0:00.68 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 -b 24 -s 8ms -i 8 -f /dev/dsp3 -d dsp -t vdsp.ctl`. Could there be a race condition where the sysctl may run before or after the devices are created? Probably. I think it's better to do what Mateusz said indeed.
christos marked this conversation as resolved
christos force-pushed christos/rc from 87913bd178
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
to 3e6783dcfd
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
2026-05-21 16:32:25 +00:00
Compare
christos requested review from jrm 2026-05-21 16:33:31 +00:00
christos changed title from rc: virtual_oss: Define variables in rc.conf to rc: virtual_oss: Some bug fixes 2026-05-21 16:34:08 +00:00
rc: virtual_oss: Handle absent pidfile properly
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
5b98f648bf
Instead of throwing errors from the programs that use it, print a
warning if the file does not exist.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
0mp requested changes 2026-05-21 17:16:46 +00:00
@ -740,0 +740,4 @@
virtual_oss_enable="NO" # Run virtual_oss at startup.
virtual_oss_default_control_device="vdsp.ctl" # Default configuration's control device.
virtual_oss_configs="dsp" # List of configurations. Default is "dsp".
virtual_oss_dsp="\
Member

Probably this should just live in the rc script and any overrides should be handled differently. There is always the standard *_flags but the exact semantics in the case of virtual_oss will require some thinking.

Probably this should just live in the rc script and any overrides should be handled differently. There is always the standard `*_flags` but the exact semantics in the case of virtual_oss will require some thinking.
christos marked this conversation as resolved
@ -740,0 +750,4 @@
-i 8 \
-f /dev/dsp$(sysctl -n hw.snd.default_unit 2>/dev/null) \
-d dsp \
-t ${virtual_oss_default_control_device}" # Default configuration.
Member

This will be broken as well if someone sets a custom virtual_oss_default_control_device

This will be broken as well if someone sets a custom virtual_oss_default_control_device
christos marked this conversation as resolved
christos force-pushed christos/rc from 5b98f648bf
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
to 454abddea7
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
2026-05-21 17:49:17 +00:00
Compare
christos requested review from 0mp 2026-05-21 17:50:32 +00:00
christos force-pushed christos/rc from 454abddea7
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
to 62dedd593a
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
2026-05-21 18:44:31 +00:00
Compare
0mp approved these changes 2026-05-22 10:33:47 +00:00
@ -740,0 +739,4 @@
virtual_oss_enable="NO" # Run virtual_oss at startup.
virtual_oss_configs="dsp" # List of configurations.
# Default is "dsp", defined in
Member

I think that lines 742 and 743 are not strictly necessary. I'd recommend removing them, but I leave the decision to you.

I think that lines 742 and 743 are not strictly necessary. I'd recommend removing them, but I leave the decision to you.
Author
Member

These are documented in rc.conf.5, so I guess we could remove them indeed. Updating the review.

These are documented in rc.conf.5, so I guess we could remove them indeed. Updating the review.
christos marked this conversation as resolved
christos force-pushed christos/rc from 62dedd593a
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
to 451304c3ed
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
2026-05-22 10:41:18 +00:00
Compare
christos requested review from 0mp 2026-05-22 10:41:44 +00:00
@ -93,0 +83,4 @@
pid="$(cat "${pidfile}")"
startmsg -n "Stopping virtual_oss config: ${config}: "
kill "${pid}"
pwait "${pid}"
Member

I'm testing this, and I'm seeing service virtual_oss stop hang indefinitely. It would be helpful to add a timeout to the pwait call.

Maybe something like this (untested):

			pid="$(cat "${pidfile}")"
			startmsg -n "Stopping virtual_oss config: ${config}: "
			kill "${pid}"
			if ! pwait -t 10 "${pid}"; then
				warn "virtual_oss did not stop gracefully.  Killing..."
				kill -KILL "${pid}"
				pwait "${pid}"
			fi
			rm -f "${pidfile}"
I'm testing this, and I'm seeing `service virtual_oss stop` hang indefinitely. It would be helpful to add a timeout to the `pwait` call. Maybe something like this (untested): ``` pid="$(cat "${pidfile}")" startmsg -n "Stopping virtual_oss config: ${config}: " kill "${pid}" if ! pwait -t 10 "${pid}"; then warn "virtual_oss did not stop gracefully. Killing..." kill -KILL "${pid}" pwait "${pid}" fi rm -f "${pidfile}" ```
Member

Let's talk about this more this coming week.

Let's talk about this more this coming week.
Member

Why is virtual_oss refusing to terminate?

Why is virtual_oss refusing to terminate?
Author
Member

It looks like this happens when virtual_oss gets killed during I/O. But worse than this, if you stop the service command, and then look at ps, virtual_oss is still there:

root@freebsd:~ # service virtual_oss onestop
Stopping virtual_oss config: dsp: ^C
root@freebsd:~ #
root@freebsd:~ # ps aux | grep virtual
root 1764   0.0  0.1 32824  5860  -  D<Es 20:44    0:00.25 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 -
root 1819   0.0  0.0 14276  2796  0  S+   20:44    0:00.00 grep virtual
root@freebsd:~ #

Manually issuing a kill -KILL afterwards does not do anything.

It looks like this happens when virtual_oss gets killed during I/O. But worse than this, if you stop the `service` command, and then look at ps, virtual_oss is still there: ``` root@freebsd:~ # service virtual_oss onestop Stopping virtual_oss config: dsp: ^C root@freebsd:~ # root@freebsd:~ # ps aux | grep virtual root 1764 0.0 0.1 32824 5860 - D<Es 20:44 0:00.25 /usr/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -S -C 2 -c 2 -r 48000 - root 1819 0.0 0.0 14276 2796 0 S+ 20:44 0:00.00 grep virtual root@freebsd:~ # ``` Manually issuing a `kill -KILL` afterwards does not do anything.
Author
Member

This seems unrelated to this PR though. The same problems occurs even if you manually try to kill a virtual_oss instance during I/O. I think we could go ahead with this PR, and debug this problem separately.

This seems unrelated to this PR though. The same problems occurs even if you manually try to kill a virtual_oss instance during I/O. I think we could go ahead with this PR, and debug this problem separately.
Author
Member

Can we go through with this? Especially the rc.conf commit fixes a bug that's already attracted a PR [1]. As I said in the inline comments, the hang is unrelated to these patches, and has to do with virtual_oss(8), not the rc scripts.

[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295560

Can we go through with this? Especially the rc.conf commit fixes a bug that's already attracted a PR [1]. As I said in the inline comments, the hang is unrelated to these patches, and has to do with virtual_oss(8), not the rc scripts. [1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295560
Member

You can consider "rc: virtual_oss: Define some variables in rc.conf" approved by me.

Regarding remaining commits: it's actually better to just call run_rc_command stop to handle pidfiles, signal sending, and waiting. But should be taken care of in another PR.

You can consider "rc: virtual_oss: Define some variables in rc.conf" approved by me. Regarding remaining commits: it's actually better to just call `run_rc_command stop` to handle pidfiles, signal sending, and waiting. But should be taken care of in another PR.
Member

Despite my original comments, I agree with this. I think it would also be good to get this into the tree so more people can test it.

Despite my original comments, I agree with this. I think it would also be good to get this into the tree so more people can test it.
christos force-pushed christos/rc from 451304c3ed
Some checks failed
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
Style Checker / Style Checker (pull_request) Has been cancelled
to b2677d002e
Some checks failed
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (push) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (push) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (push) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (push) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (push) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (push) Has been cancelled
Checklist / commit (pull_request_target) Has been cancelled
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (pull_request) Has been cancelled
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / amd64 macos-latest (clang-18) (pull_request) Has been cancelled
Cross-build Kernel / aarch64 macos-latest (clang-18) (pull_request) Has been cancelled
2026-05-28 14:06:22 +00:00
Compare
christos manually merged commit b2677d002e into main 2026-05-28 14:07:20 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
FreeBSD/src!33
No description provided.