Date: Sun, 28 Jun 2026 09:43:52 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 2baf97f3305a - stable/15 - rc: Improve load_kld Message-ID: <6a40ecd8.3026c.6b04f785@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=2baf97f3305a89c1211566c6ba38815e0af5412f commit 2baf97f3305a89c1211566c6ba38815e0af5412f Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-06-23 15:23:30 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-06-28 09:43:39 +0000 rc: Improve load_kld * Centralize the usage message. * Document and enforce that -e and -m are mutually exclusive; previously, speficying both would result in only -e being applied. * If -e was not specified, and -m was not specified or did not match, fall back to `kldstat -n file` which will always work for modules that aren't built into the kernel. This means the kld and ntpd scripts can now rely on load_kld to dtrt. MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D57706 (cherry picked from commit a95d324dd3107afcbc16767d183acca7a57ebca9) --- libexec/rc/rc.d/kld | 6 ++++-- libexec/rc/rc.d/ntpd | 2 +- libexec/rc/rc.subr | 27 ++++++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/libexec/rc/rc.d/kld b/libexec/rc/rc.d/kld index 37b14255abb9..851db5dd6a32 100755 --- a/libexec/rc/rc.d/kld +++ b/libexec/rc/rc.d/kld @@ -44,10 +44,12 @@ kld_start() local _kld - echo 'Loading kernel modules:' $kld_list + startmsg -n "Loading kernel modules:" for _kld in $kld_list ; do - load_kld -e ${_kld}.ko $_kld + load_kld $_kld + startmsg -n " ${_kld}" done + startmsg "." } load_rc_config $name diff --git a/libexec/rc/rc.d/ntpd b/libexec/rc/rc.d/ntpd index e7e42da8acc7..a46a32144cce 100755 --- a/libexec/rc/rc.d/ntpd +++ b/libexec/rc/rc.d/ntpd @@ -67,7 +67,7 @@ can_run_nonroot() # the policy module if not already present, then check whether the # policy has been disabled via tunable or sysctl. [ -n "$(sysctl -qn security.mac.version)" ] || return 1 - sysctl -qn security.mac.ntpd >/dev/null || kldload -qn mac_ntpd || return 1 + load_kld mac_ntpd || return 1 [ "$(sysctl -qn security.mac.ntpd.enabled)" == "1" ] || return 1 # On older existing systems, the ntp dir may by owned by root, change diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 4e19d10f5e4e..451521c038d8 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -2413,37 +2413,38 @@ mount_md() # Code common to scripts that need to load a kernel module # if it isn't in the kernel yet. Syntax: -# load_kld [-e regex] [-m module] file +# load_kld [-e regex | -m module] file # where -e or -m chooses the way to check if the module # is already loaded: -# regex is egrep'd in the output from `kldstat -v', -# module is passed to `kldstat -m'. -# The default way is as though `-m file' were specified. +# -e greps the output from `kldstat -v', +# -m uses `kldstat -m module'. +# The default way is as though `-m file` was specified. load_kld() { - local _loaded _mod _opt _re + local _loaded _mod _opt _re _x + _x=0 while getopts "e:m:" _opt; do case "$_opt" in e) _re="$OPTARG" ;; m) _mod="$OPTARG" ;; - *) err 3 'USAGE: load_kld [-e regex] [-m module] file' ;; + *) _x=999 ;; esac + _x=$((_x + 1)) done shift $(($OPTIND - 1)) - if [ $# -ne 1 ]; then - err 3 'USAGE: load_kld [-e regex] [-m module] file' + if [ $# -ne 1 ] || [ $_x -gt 1 ]; then + err 3 'USAGE: load_kld [-e regex | -m module] file' fi - _mod=${_mod:-$1} _loaded=false if [ -n "$_re" ]; then if kldstat -v | egrep -q -e "$_re"; then _loaded=true fi - else - if kldstat -q -m "$_mod"; then - _loaded=true - fi + elif kldstat -q -m "${_mod:-$1}"; then + _loaded=true + elif kldstat -q -n "$1"; then + _loaded=true fi if ! $_loaded; then if ! kldload "$1"; thenhome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a40ecd8.3026c.6b04f785>
