History log of /openbsd-current/usr.bin/sndiod/siofile.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.27 02-Apr-2024 ratchov

sndiod: Migrate clients upon watchdog timeout

When -F is used, fixes the difference in behavior between watchdog
timer expiry and other errors.


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.26 29-Apr-2022 ratchov

Add sio_flush(3) function to stop playback immediately

The new sio_flush(3) functions works the same way as sio_stop(3),
except that it doesn't wait for play buffer to be drained. Instead,
it discards its contents and returns immediately.


Revision tags: OPENBSD_7_1_BASE
# 1.25 01-Nov-2021 ratchov

Stop binding audio devices exposed by sndiod to physical devices

This a shift towards a new model: clients connect to logical devices
(created with -s option) then the server routes data to/from the
underlying physical device (registered with -f option). The binding
may be changed at run-time with the server.device control exposed by
sndioctl(1).

As audio devices exposed by sndiod(8) are not bound to fixed physical
devices anymore, the physical audio device number component of
sndio(7) descriptors was removed.

fixes, help from and ok denis, edd


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.24 03-Mar-2021 ratchov

sndiod: Move controls out of the device structure

Moving to a global server-wide controls list is necessary to expose
controls that are not associated to a particular device (ex. a device
selector).

The current hack to use the device-side sioctl_desc->addr variable as
client-side key can't work anymore. So, we use a unique dynamically
allocated ctl->addr key; this is much cleaner. A new "scope" enum
(with two "void *" arguments) is used to determine what the control
does control. This adds flexibility and allows to easily add new
control types that are not associated to devices.

No behavior change.


# 1.23 02-Mar-2021 edd

sndiod: Allow alternative devices to support different modes.

Currently sndiod does not allow you to use alternative devices (-F
devices) which support only a subset of the modes of the main (-f)
device.

For example, if you do `sndiod -f rsnd/0 -F rsnd/1` and:
- rsnd/0 is full-duplex (rec + play).
- rsnd/1 is play-only.

Then you will be unable to use rsnd/1 as sndiod deems it incompatible
and refuses to use it (similarly if rsnd/1 is record-only).

This is annoying. It means if you want to use a record-only or play-only
device, you will either have to kill sndiod and restart it specifying
only that device (`sndiod -f rsnd/1` for the above example), or failing
that, downgrade the functionality of the main device (`-m play`).

This diff (a joint effort between ratchov@ and myself) makes mixing
devices with different modes possible. It does this by making both
recording and playing available for all devices, even if the underlying
hardware doesn't support both modes.

For example, if I try to record from a play-only device, then recording
will succeed, but the captured PCM data will be pure silence. Similarly,
if I try to play to a record-only device, then the audio stream will
disappear into the ether.

This is mostly a no-op for sndiod in the default configuration (except
that play-only devices now accept recording clients). If you use
alternative devices (-F), then it's possible for a record-only device to
be found first, which may be confusing if you just want to hear sound.
We can only assume that if you deviate from defaults, then you know what
you are doing.

With guidance from, and OK ratchov@, thanks!


Revision tags: OPENBSD_6_8_BASE
# 1.22 28-Jun-2020 ratchov

Allow switching between alternate devices (-F option) with sndioctl(1)


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.26 29-Apr-2022 ratchov

Add sio_flush(3) function to stop playback immediately

The new sio_flush(3) functions works the same way as sio_stop(3),
except that it doesn't wait for play buffer to be drained. Instead,
it discards its contents and returns immediately.


Revision tags: OPENBSD_7_1_BASE
# 1.25 01-Nov-2021 ratchov

Stop binding audio devices exposed by sndiod to physical devices

This a shift towards a new model: clients connect to logical devices
(created with -s option) then the server routes data to/from the
underlying physical device (registered with -f option). The binding
may be changed at run-time with the server.device control exposed by
sndioctl(1).

As audio devices exposed by sndiod(8) are not bound to fixed physical
devices anymore, the physical audio device number component of
sndio(7) descriptors was removed.

fixes, help from and ok denis, edd


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.24 03-Mar-2021 ratchov

sndiod: Move controls out of the device structure

Moving to a global server-wide controls list is necessary to expose
controls that are not associated to a particular device (ex. a device
selector).

The current hack to use the device-side sioctl_desc->addr variable as
client-side key can't work anymore. So, we use a unique dynamically
allocated ctl->addr key; this is much cleaner. A new "scope" enum
(with two "void *" arguments) is used to determine what the control
does control. This adds flexibility and allows to easily add new
control types that are not associated to devices.

No behavior change.


# 1.23 02-Mar-2021 edd

sndiod: Allow alternative devices to support different modes.

Currently sndiod does not allow you to use alternative devices (-F
devices) which support only a subset of the modes of the main (-f)
device.

For example, if you do `sndiod -f rsnd/0 -F rsnd/1` and:
- rsnd/0 is full-duplex (rec + play).
- rsnd/1 is play-only.

Then you will be unable to use rsnd/1 as sndiod deems it incompatible
and refuses to use it (similarly if rsnd/1 is record-only).

This is annoying. It means if you want to use a record-only or play-only
device, you will either have to kill sndiod and restart it specifying
only that device (`sndiod -f rsnd/1` for the above example), or failing
that, downgrade the functionality of the main device (`-m play`).

This diff (a joint effort between ratchov@ and myself) makes mixing
devices with different modes possible. It does this by making both
recording and playing available for all devices, even if the underlying
hardware doesn't support both modes.

For example, if I try to record from a play-only device, then recording
will succeed, but the captured PCM data will be pure silence. Similarly,
if I try to play to a record-only device, then the audio stream will
disappear into the ether.

This is mostly a no-op for sndiod in the default configuration (except
that play-only devices now accept recording clients). If you use
alternative devices (-F), then it's possible for a record-only device to
be found first, which may be confusing if you just want to hear sound.
We can only assume that if you deviate from defaults, then you know what
you are doing.

With guidance from, and OK ratchov@, thanks!


Revision tags: OPENBSD_6_8_BASE
# 1.22 28-Jun-2020 ratchov

Allow switching between alternate devices (-F option) with sndioctl(1)


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.25 01-Nov-2021 ratchov

Stop binding audio devices exposed by sndiod to physical devices

This a shift towards a new model: clients connect to logical devices
(created with -s option) then the server routes data to/from the
underlying physical device (registered with -f option). The binding
may be changed at run-time with the server.device control exposed by
sndioctl(1).

As audio devices exposed by sndiod(8) are not bound to fixed physical
devices anymore, the physical audio device number component of
sndio(7) descriptors was removed.

fixes, help from and ok denis, edd


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.24 03-Mar-2021 ratchov

sndiod: Move controls out of the device structure

Moving to a global server-wide controls list is necessary to expose
controls that are not associated to a particular device (ex. a device
selector).

The current hack to use the device-side sioctl_desc->addr variable as
client-side key can't work anymore. So, we use a unique dynamically
allocated ctl->addr key; this is much cleaner. A new "scope" enum
(with two "void *" arguments) is used to determine what the control
does control. This adds flexibility and allows to easily add new
control types that are not associated to devices.

No behavior change.


# 1.23 02-Mar-2021 edd

sndiod: Allow alternative devices to support different modes.

Currently sndiod does not allow you to use alternative devices (-F
devices) which support only a subset of the modes of the main (-f)
device.

For example, if you do `sndiod -f rsnd/0 -F rsnd/1` and:
- rsnd/0 is full-duplex (rec + play).
- rsnd/1 is play-only.

Then you will be unable to use rsnd/1 as sndiod deems it incompatible
and refuses to use it (similarly if rsnd/1 is record-only).

This is annoying. It means if you want to use a record-only or play-only
device, you will either have to kill sndiod and restart it specifying
only that device (`sndiod -f rsnd/1` for the above example), or failing
that, downgrade the functionality of the main device (`-m play`).

This diff (a joint effort between ratchov@ and myself) makes mixing
devices with different modes possible. It does this by making both
recording and playing available for all devices, even if the underlying
hardware doesn't support both modes.

For example, if I try to record from a play-only device, then recording
will succeed, but the captured PCM data will be pure silence. Similarly,
if I try to play to a record-only device, then the audio stream will
disappear into the ether.

This is mostly a no-op for sndiod in the default configuration (except
that play-only devices now accept recording clients). If you use
alternative devices (-F), then it's possible for a record-only device to
be found first, which may be confusing if you just want to hear sound.
We can only assume that if you deviate from defaults, then you know what
you are doing.

With guidance from, and OK ratchov@, thanks!


Revision tags: OPENBSD_6_8_BASE
# 1.22 28-Jun-2020 ratchov

Allow switching between alternate devices (-F option) with sndioctl(1)


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.24 03-Mar-2021 ratchov

sndiod: Move controls out of the device structure

Moving to a global server-wide controls list is necessary to expose
controls that are not associated to a particular device (ex. a device
selector).

The current hack to use the device-side sioctl_desc->addr variable as
client-side key can't work anymore. So, we use a unique dynamically
allocated ctl->addr key; this is much cleaner. A new "scope" enum
(with two "void *" arguments) is used to determine what the control
does control. This adds flexibility and allows to easily add new
control types that are not associated to devices.

No behavior change.


# 1.23 02-Mar-2021 edd

sndiod: Allow alternative devices to support different modes.

Currently sndiod does not allow you to use alternative devices (-F
devices) which support only a subset of the modes of the main (-f)
device.

For example, if you do `sndiod -f rsnd/0 -F rsnd/1` and:
- rsnd/0 is full-duplex (rec + play).
- rsnd/1 is play-only.

Then you will be unable to use rsnd/1 as sndiod deems it incompatible
and refuses to use it (similarly if rsnd/1 is record-only).

This is annoying. It means if you want to use a record-only or play-only
device, you will either have to kill sndiod and restart it specifying
only that device (`sndiod -f rsnd/1` for the above example), or failing
that, downgrade the functionality of the main device (`-m play`).

This diff (a joint effort between ratchov@ and myself) makes mixing
devices with different modes possible. It does this by making both
recording and playing available for all devices, even if the underlying
hardware doesn't support both modes.

For example, if I try to record from a play-only device, then recording
will succeed, but the captured PCM data will be pure silence. Similarly,
if I try to play to a record-only device, then the audio stream will
disappear into the ether.

This is mostly a no-op for sndiod in the default configuration (except
that play-only devices now accept recording clients). If you use
alternative devices (-F), then it's possible for a record-only device to
be found first, which may be confusing if you just want to hear sound.
We can only assume that if you deviate from defaults, then you know what
you are doing.

With guidance from, and OK ratchov@, thanks!


Revision tags: OPENBSD_6_8_BASE
# 1.22 28-Jun-2020 ratchov

Allow switching between alternate devices (-F option) with sndioctl(1)


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.22 28-Jun-2020 ratchov

Allow switching between alternate devices (-F option) with sndioctl(1)


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.21 18-Jun-2020 ratchov

Don't try to open device that's already open

Save the current alternate device index and skip it in
dev_reopen(). Handling alternate device indices this way will ease
future development as well.


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.20 12-Jun-2020 ratchov

On error, drop clients and close the device only if it's still open

Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.


Revision tags: OPENBSD_6_7_BASE
# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.19 24-Apr-2020 ratchov

Make sure devices are properly closed in case of an error.

Fixes possible crashes if the contol device fails, while the audio
device continues to work.


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.18 26-Feb-2020 ratchov

Add API to control audio device parameters exposed by sndiod.

The API exposes controls of modern audio hardware and sndiod software
volume knobs in a uniform way. Hardware knobs are exposed through
sndiod. Multiple programs may use the controls at the same time
without the need to continuously scan the controls.

For now sndiod exposes only its own controls and the master output and
input volumes of the underlying hardware (if any), i.e. those
typically exposed by acpi volume keys.

ok deraadt


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.17 23-Jan-2020 ratchov

When opening a device, loop over the alternate devices list in the
worker process instead of the helper process. It is simpler this way
and allows the worker to properly log which device is being used.


Revision tags: OPENBSD_6_6_BASE
# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.16 21-Sep-2019 ratchov

Allow switching between devices without disconnecting clients.

The new -F option allows alternate device to be specified. If the
device is disconnected, the one given with the last -f or -F options
will be used instead. Similarly, the new -Q option allows an alternate
MIDI port to be specified.

ok mpi@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


# 1.15 29-Aug-2019 ratchov

Uniformize device-specific debug printfs


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.14 20-Jul-2017 ratchov

Fix debug printf used to report kernel bugs: print par.bps instead
of par.bits. Found by coverity.


Revision tags: OPENBSD_6_1_BASE
# 1.13 27-Oct-2016 ratchov

Fix many typos in comments, from Michael W. Bombardieri <mb at ii.net>


Revision tags: OPENBSD_6_0_BASE
# 1.12 25-May-2016 ratchov

Don't warn when read or write block at cycle boundary, this may
happen when remote devices are used and is not an error.


Revision tags: OPENBSD_5_9_BASE
# 1.11 08-Jan-2016 ratchov

Make code fit in 80 columns, remove trailing spaces & tabs.


# 1.10 20-Dec-2015 ratchov

In case of a bug in sndiod, an attacker (a local user) could run
arbitrary code as user _sndio, i.e. get a second uid.

Mitigate the risk by implementing initial privilege separation as
follows. Break sndiod in two processes: a chroot()ed "worker" process
processing input, and a non-chroot()ed "helper" process opening
devices and passing descriptors to the worker.

With help from benno, claudio, semarie and gilles.

ok benno, semarie and tb


Revision tags: OPENBSD_5_8_BASE
# 1.9 24-Jul-2015 ratchov

Crank watchdog timeout from 2 to 4 seconds.


# 1.8 24-Jul-2015 ratchov

Log when device is disconnected.


# 1.7 24-Jul-2015 ratchov

Clear watchdog timer when device is closed, fixes use-after-free in
error code-paths when device is closed before audio is stopped.


Revision tags: OPENBSD_5_7_BASE
# 1.6 16-Feb-2015 ratchov

add missing protos, fix spacing


# 1.5 08-Oct-2014 ratchov

check audio parameters returned by the audio drivers,
and nicely report driver bugs rather than crashing/misbehaving
later if parameters aren't consistent.


Revision tags: OPENBSD_5_6_BASE
# 1.4 17-Mar-2014 ratchov

unbreak monitoring mode, which was shifted in time by 1 block


Revision tags: OPENBSD_5_5_BASE
# 1.3 18-Nov-2013 ratchov

add missing prototypes


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.2 01-Feb-2013 ratchov

if a device doesn't respond within two seconds, then just close it
and drop all connections. This is shameful but unfortunately it's
still necessery on certain MP machines and audio driver combinations


# 1.1 23-Nov-2012 ratchov

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
- The sample rate and the encoding are a per-device parameters
thus -r and -e options must precede the corresponding -f option
- MIDI thru boxes are dynamically created and no -M option
is required anymore, so -M was removed.
- MIDI ports are exposed with a new ``midi/N'' name, rather
than abusing MIDI thru boxes.
with help from armani@, ok deraadt@