Bug 277615 - /usr/sbin/mixer -a does not display all mixer devices if /dev/mixer0 happens to not exist.
Summary: /usr/sbin/mixer -a does not display all mixer devices if /dev/mixer0 happens ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-10 17:08 UTC by Keith Hellman
Modified: 2024-05-25 19:32 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Hellman 2024-03-10 17:08:42 UTC
$ freebsd-version
14.0-RELEASE-p4
$ echo /dev/mixer[0-9]*
/dev/mixer3 /dev/mixer4 /dev/mixer5 /dev/mixer6 /dev/mixer7
$ /usr/sbin/mixer -a
mixer: mixer_open: /dev/mixer0: Bad file descriptor
Comment 1 commit-hook freebsd_committer freebsd_triage 2024-05-23 00:59:04 UTC
A commit in branch main references this bug:

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

commit 0e80798518be673bdad7245b627cb5bd7ec08888
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-23 00:57:25 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-23 00:57:25 +0000

    mixer(8): Ignore mixer_open() failures for the -a option

    The most likely reason mixer_open() will fail is because either the
    device doesn't exist, or because it is disabled, so there is not reason
    to kill the application. Instead, continue and print the rest of the
    enabled mixers.

    PR:             277615
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 day
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45151

 usr.sbin/mixer/mixer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-05-23 00:59:06 UTC
A commit in branch main references this bug:

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

commit 5d980fadf73df64a1e0eda40a93170ed76ce6f14
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-23 00:57:17 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-23 00:57:17 +0000

    sound: Handle unavailable devices in various OSS IOCTLs

    mixer(8)'s -a option is used to print information about all mixer
    devices in the system. To do this, it loops from 0 to
    mixer_get_nmixers(), and tries to open "/dev/mixer%d". However, this
    approach doesn't work when there are disabled/unregistered mixers in the
    system, or when an audio device simply doesn't have a mixer.

    mixer_get_nmixers() calls SNDCTL_SYSINFO and returns
    oss_sysinfo->nummixers, whose value is the number of currently _enabled_
    mixers only. Taking the bug report mentioned below (277615) as an
    example, suppose a system with 8 mixer devices total, but 3 of them are
    either disabled or non-existent, which means they will not show up under
    /dev, meaning we have 5 enabled mixer devices, which is also what the
    value of oss_sysinfo->nummixers will be. What mixer(8) will do is loop
    from 0 to 5 (instead of 8), and start calling mixer_open() on
    /dev/mixer0, up to /dev/mixer4, and as is expected, the first call will
    fail right away, hence the error shown in the bug report.

    To fix this, modify oss_sysinfo->nummixers to hold the value of the
    maximum unit in the system, which, although not necessarily "correct",
    is more intuitive for applications that will want to use this value to
    loop through all mixer devices.

    Additionally, notify applications that a device is
    unavailable/unregistered instead of skipping it. The current
    implementations of SNDCTL_AUDIOINFO, SNDCTL_MIXERINFO and
    SNDCTL_CARDINFO break applications that expect to get information about
    a device that is skipped. Related discussion can be found here:
    https://reviews.freebsd.org/D45135#1029526

    It has to be noted, that other applications, apart from mixer(8), suffer
    from this.

    PR:             277615
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 day
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45256

 lib/libmixer/mixer.3      |   7 +-
 sys/dev/sound/pcm/dsp.c   |  23 +++++-
 sys/dev/sound/pcm/mixer.c | 201 ++++++++++++++++++++++++----------------------
 sys/dev/sound/pcm/mixer.h |   2 -
 sys/dev/sound/pcm/sound.c |  41 ++++++----
 5 files changed, 155 insertions(+), 119 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-05-25 19:32:32 UTC
A commit in branch stable/14 references this bug:

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

commit ab7c89415462567665c36628137375847fbff590
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-23 00:57:17 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-25 19:30:40 +0000

    sound: Handle unavailable devices in various OSS IOCTLs

    mixer(8)'s -a option is used to print information about all mixer
    devices in the system. To do this, it loops from 0 to
    mixer_get_nmixers(), and tries to open "/dev/mixer%d". However, this
    approach doesn't work when there are disabled/unregistered mixers in the
    system, or when an audio device simply doesn't have a mixer.

    mixer_get_nmixers() calls SNDCTL_SYSINFO and returns
    oss_sysinfo->nummixers, whose value is the number of currently _enabled_
    mixers only. Taking the bug report mentioned below (277615) as an
    example, suppose a system with 8 mixer devices total, but 3 of them are
    either disabled or non-existent, which means they will not show up under
    /dev, meaning we have 5 enabled mixer devices, which is also what the
    value of oss_sysinfo->nummixers will be. What mixer(8) will do is loop
    from 0 to 5 (instead of 8), and start calling mixer_open() on
    /dev/mixer0, up to /dev/mixer4, and as is expected, the first call will
    fail right away, hence the error shown in the bug report.

    To fix this, modify oss_sysinfo->nummixers to hold the value of the
    maximum unit in the system, which, although not necessarily "correct",
    is more intuitive for applications that will want to use this value to
    loop through all mixer devices.

    Additionally, notify applications that a device is
    unavailable/unregistered instead of skipping it. The current
    implementations of SNDCTL_AUDIOINFO, SNDCTL_MIXERINFO and
    SNDCTL_CARDINFO break applications that expect to get information about
    a device that is skipped. Related discussion can be found here:
    https://reviews.freebsd.org/D45135#1029526

    It has to be noted, that other applications, apart from mixer(8), suffer
    from this.

    PR:             277615
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 day
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45256

    (cherry picked from commit 5d980fadf73df64a1e0eda40a93170ed76ce6f14)

 lib/libmixer/mixer.3      |   7 +-
 sys/dev/sound/pcm/dsp.c   |  23 +++++-
 sys/dev/sound/pcm/mixer.c | 201 ++++++++++++++++++++++++----------------------
 sys/dev/sound/pcm/mixer.h |   2 -
 sys/dev/sound/pcm/sound.c |  41 ++++++----
 5 files changed, 155 insertions(+), 119 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-05-25 19:32:34 UTC
A commit in branch stable/14 references this bug:

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

commit cd254b9243d3d0f4d86b388f919dc744086fb002
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-23 00:57:25 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-25 19:30:49 +0000

    mixer(8): Ignore mixer_open() failures for the -a option

    The most likely reason mixer_open() will fail is because either the
    device doesn't exist, or because it is disabled, so there is not reason
    to kill the application. Instead, continue and print the rest of the
    enabled mixers.

    PR:             277615
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 day
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45151

    (cherry picked from commit 0e80798518be673bdad7245b627cb5bd7ec08888)

 usr.sbin/mixer/mixer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)