Bug 291092 - beep(1) options in wrong order, min/max not stated
Summary: beep(1) options in wrong order, min/max not stated
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: Jose Luis Duran
URL: https://man.freebsd.org/cgi/man.cgi?q...
Keywords:
Depends on:
Blocks:
 
Reported: 2025-11-19 02:51 UTC by B.S.
Modified: 2025-11-29 00:37 UTC (History)
3 users (show)

See Also:
jlduran: mfc-stable15+
jlduran: mfc-stable14+
jlduran: mfc-stable13+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description B.S. 2025-11-19 02:51:15 UTC
Compare beep(1) to the usage message `beep -h`:

> Usage: beep [parameters]
>	-F <frequency in HZ, default 440 Hz>
>	-D <duration in ms, from 50 ms to 2000 ms, default 150 ms>
>	-r <sample rate in HZ, from 8000 Hz to 48000 Hz, default 48000 Hz>
>	-d <OSS device (default /dev/dsp)>
>	-g <gain from 0 to 100, default 75>
>	-B Run in background
>	-h Show usage

Source: https://github.com/freebsd/freebsd-src/blob/main/usr.bin/beep/beep.c

This output is generated from DEFAULT_HZ, DURATION_MIN, DURATION_MAX, DURATION_DEF, SAMPLE_RATE_MIN, SAMPLE_RATE_MAX, SAMPLE_RATE_DEF, DEFAULT_DEVICE, GAIN_MIN, GAIN_MAX, and GAIN_DEF so stated figures match the code's behavior. A supplied value for duration, sample rate, or gain that is below min or above max results in exit status 1. No min or max is applied for frequency.

The beep(1) "Description" section states correct defaults for -F, -D, -d, -r, and -g but not the min and max permissible values for -D, -r, and -g.

The order with -d followed by -r is swapped both in comparison to the usage message and the "Synopsis", where -r comes before -d.

Also, several sentences have a space before the period, including one in "Examples" ("Playback default beep sound using /dev/dsp .") which should probably end in a colon instead.
Comment 1 Jose Luis Duran freebsd_committer freebsd_triage 2025-11-19 16:03:51 UTC
Proposed fixes:

https://reviews.freebsd.org/D53827
Comment 2 B.S. 2025-11-19 17:42:42 UTC
(In reply to Jose Luis Duran from comment #1)
Thanks, this is much better! Commenting here as I do not have a Phabricator account:

All dictionaries and references I checked list "sample rate" as two words separated by a space, and not as a single word or hyphenated. So "samplerate" in the man page should be "sample rate" like in the usage message.

In the usage message, there's an inconsistency between "<OSS device (default %s)>" with parenthesized default, and the way other defaults are given after a comma like "<frequency in Hz, default %d Hz>".
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2025-11-21 16:19:31 UTC
Resetting the status since the patch hasn't landed in main yet.
Comment 4 B.S. 2025-11-21 18:21:27 UTC
Re whether the usage message is redundant to the man page: it has a different role. The usage message is printed to stderr after an impermissible input (e.g. duration below min or above max).

For comparison, ministat(1) has an extensive usage message but it only appears after an erroneous input (no `-h` flag to invoke it deliberately). Nicely, this is accompanied by a statement of what triggered the error: `ministat -c 71` reports "No support for confidence level", then the usage message. This would be nice to have on beep(1) too, but wasn't part of my Problem Report. See:

https://man.freebsd.org/cgi/man.cgi?ministat

https://github.com/freebsd/freebsd-src/blob/main/usr.bin/ministat/ministat.c

Arguably, when deliberately invoked by `beep -h`, perhaps the usage message should be printed to stdout instead of stderr, but practice on that is not universal and I don't know what the norm is in FreeBSD. See e.g.

https://stackoverflow.com/questions/2199624/should-the-command-line-usage-be-printed-on-stdout-or-stderr
Comment 5 Jose Luis Duran freebsd_committer freebsd_triage 2025-11-21 23:51:16 UTC
(In reply to B.S. from comment #4)
I agree with most of the comments described here.

Regarding the file descriptor of "-h" (stdout or stderr), I also agree, that -h should output usage() to stdout.  But I would prefer this change be implemented as part of an effort to standardize all non-contributed utilities (preferably with tests).  I think there are a few utilities in base that pre-date the notion of "-h" standing for "help".
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-11-22 17:32:38 UTC
A commit in branch main references this bug:

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

commit 55d98b024f25403f60efe04f90a391014b6bc388
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-19 15:59:25 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-11-22 17:28:46 +0000

    beep: Sort usage and man page options

    Sort usage and man page options, mention possible minimum and maximum
    values, fix punctuation marks, and cleanup the man page.

    PR:             291092
    Reviewed by:    pauamma_gundo.com, christos
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53827

 usr.bin/beep/beep.1 | 55 ++++++++++++++++++++++++++++-------------------------
 usr.bin/beep/beep.c | 19 +++++++++---------
 2 files changed, 39 insertions(+), 35 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-11-29 00:36:31 UTC
A commit in branch stable/15 references this bug:

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

commit 6bda3655b8272aa9fd1301df3346aca4d5b0d39c
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-19 15:59:25 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-11-29 00:30:21 +0000

    beep: Sort usage and man page options

    Sort usage and man page options, mention possible minimum and maximum
    values, fix punctuation marks, and cleanup the man page.

    PR:             291092
    Reviewed by:    pauamma_gundo.com, christos
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53827

    (cherry picked from commit 55d98b024f25403f60efe04f90a391014b6bc388)

 usr.bin/beep/beep.1 | 55 ++++++++++++++++++++++++++++-------------------------
 usr.bin/beep/beep.c | 19 +++++++++---------
 2 files changed, 39 insertions(+), 35 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2025-11-29 00:36:32 UTC
A commit in branch stable/14 references this bug:

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

commit 4c10ec9bd43feb86394dc2dc1c16f1c15d4b0285
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-19 15:59:25 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-11-29 00:31:57 +0000

    beep: Sort usage and man page options

    Sort usage and man page options, mention possible minimum and maximum
    values, fix punctuation marks, and cleanup the man page.

    PR:             291092
    Reviewed by:    pauamma_gundo.com, christos
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53827

    (cherry picked from commit 55d98b024f25403f60efe04f90a391014b6bc388)

 usr.bin/beep/beep.1 | 55 ++++++++++++++++++++++++++++-------------------------
 usr.bin/beep/beep.c | 19 +++++++++---------
 2 files changed, 39 insertions(+), 35 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-11-29 00:36:33 UTC
A commit in branch stable/13 references this bug:

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

commit 8d338f99f8b1dc16d2175721c48201fce117fe43
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-19 15:59:25 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-11-29 00:32:36 +0000

    beep: Sort usage and man page options

    Sort usage and man page options, mention possible minimum and maximum
    values, fix punctuation marks, and cleanup the man page.

    PR:             291092
    Reviewed by:    pauamma_gundo.com, christos
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53827

    (cherry picked from commit 55d98b024f25403f60efe04f90a391014b6bc388)

 usr.bin/beep/beep.1 | 55 ++++++++++++++++++++++++++++-------------------------
 usr.bin/beep/beep.c | 19 +++++++++---------
 2 files changed, 39 insertions(+), 35 deletions(-)
Comment 10 Jose Luis Duran freebsd_committer freebsd_triage 2025-11-29 00:37:43 UTC
Thank you for the bug report and review!