Quite a number of rc.d scripts try to load kernel modules. Many
of them do that conditionally depending on kldstat. The code is duplicated all over, but bugs can be uniqie. To make the things more consistent, introduce a new rc.subr function, load_kld, which takes care of loading a kernel module conditionally. (Found this lying for a while in my p4 branch for various hacks.)
This commit is contained in:
parent
bc4990d51b
commit
1679c7f4f4
39
etc/rc.subr
39
etc/rc.subr
@ -1356,6 +1356,45 @@ mount_md()
|
||||
/sbin/mdmfs $flags -s $1 md $2
|
||||
}
|
||||
|
||||
# Code common to scripts that need to load a kernel module
|
||||
# if it isn't in the kernel yet. Syntax:
|
||||
# load_kld [-e regexp] [-m modname] filename
|
||||
# where -e or -m chooses the way to check if the module
|
||||
# is already loaded:
|
||||
# regexp is egrep'd in the output from `kldstat -v',
|
||||
# modname is passed to `kldstat -m'.
|
||||
# The default way is as though `-m filename' were specified.
|
||||
load_kld()
|
||||
{
|
||||
local _loaded _mod _opt _re
|
||||
|
||||
while getopts "e:m:" _opt; do
|
||||
case "$_opt" in
|
||||
e) _re="$OPTARG" ;;
|
||||
m) _mod="$OPTARG" ;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
_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
|
||||
fi
|
||||
if ! $_loaded; then
|
||||
if ! kldload "$1"; then
|
||||
warn "Unable to load kernel module $1"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# ltr str src dst
|
||||
# Change every $src in $str to $dst.
|
||||
# Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
|
||||
|
@ -64,6 +64,8 @@
|
||||
.It
|
||||
.Ic info Ar message
|
||||
.It
|
||||
.Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file
|
||||
.It
|
||||
.Ic load_rc_config Ar name
|
||||
.It
|
||||
.Ic load_rc_config_var Ar name Ar var
|
||||
@ -312,6 +314,20 @@ turned on or off by the
|
||||
.Xr rc.conf 5
|
||||
variable
|
||||
.Va rc_info .
|
||||
.It Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file
|
||||
Load
|
||||
.Ar file
|
||||
as a kernel module unless it is already loaded.
|
||||
For the purpose of checking the module status,
|
||||
either the exact module name can be specified using
|
||||
.Fl m ,
|
||||
or an
|
||||
.Xr egrep 1
|
||||
regular expression matching the module name can be supplied via
|
||||
.Fl e .
|
||||
By default, the module is assumed to have the same name as
|
||||
.Ar file ,
|
||||
which is not always the case.
|
||||
.It Ic load_rc_config Ar name
|
||||
Source in the configuration files for
|
||||
.Ar name .
|
||||
|
Loading…
Reference in New Issue
Block a user