git: 04ea02cb7ac8 - main - sysrc: Add error messages to usage responses
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 25 Nov 2026 21:51:25 UTC
The branch main has been updated by dteske:
URL: https://cgit.FreeBSD.org/src/commit/?id=04ea02cb7ac87a22755bd46443a97f410919468d
commit 04ea02cb7ac87a22755bd46443a97f410919468d
Author: Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-11-25 21:45:28 +0000
Commit: Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-11-25 21:47:37 +0000
sysrc: Add error messages to usage responses
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61722
---
usr.sbin/sysrc/sysrc | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index 0fc2e9ec872e..b1814948330d 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -16,7 +16,7 @@ pgm="${0##*/}" # Program basename
#
# Version information
#
-SYSRC_VERSION="8.5 Nov-18,2026"
+SYSRC_VERSION="8.6 Nov-18,2026"
#
# Options
@@ -43,27 +43,35 @@ VERBOSE= # -v
############################################################ FUNCTIONS
+# warn [$fmt [$opts ...]]
+#
+# Produce an error message on stderr.
+#
+warn()
+{
+ local fmt="$1"
+ [ "$fmt" ] || return
+ shift 1 # fmt
+ f_err "%s: $fmt\n" "$pgm" "$@"
+}
+
# die [$fmt [$opts ...]]
#
# Optionally print a message to stderr before exiting with failure status.
#
die()
{
- local fmt="$1"
-
- if [ "$fmt" ]; then
- shift 1 # fmt
- f_err "%s: $fmt\n" "$pgm" "$@"
- fi
+ warn "$@"
exit $FAILURE
}
-# usage
+# usage [$fmt [$opts ...]]
#
-# Prints a short syntax statement and exits.
+# Prints a short syntax statement and exits. Optionally preceded by an error.
#
usage()
{
+ warn "$@"
f_err "Usage: %s [OPTIONS] %s\n" "$pgm" \
"{name[[+|-|.]=value] ... | -a | -A | -l | -L [name ...]}"
f_err "Try \`%s --help' for more information.\n" "$pgm"
@@ -202,7 +210,7 @@ escape()
#
# Perform sanity checks
#
-[ $# -gt 0 ] || usage # NOTREACHED
+[ $# -gt 0 ] || usage "no names provided" # NOTREACHED
#
# Check for `--help' and `--version' command-line option
@@ -381,7 +389,7 @@ fi
# Process `-l' option flag
#
if [ "$LIST_CONFS" ]; then
- [ $# -eq 0 ] || usage
+ [ $# -eq 0 ] || usage "-l does not take names" # NOTREACHED
if [ "$DEFAULT" ]; then
echo "$RC_DEFAULTS"
elif [ "${RC_CONFS+set}" ]; then
@@ -395,7 +403,7 @@ fi
#
# [More] Sanity checks (e.g., "sysrc --")
#
-[ $# -eq 0 -a ! "$SHOW_ALL" ] && usage # NOTREACHED
+[ $# -eq 0 -a ! "$SHOW_ALL" ] && usage "no names provided" # NOTREACHED
#
# Taint-check all rc.conf(5) files