2018-02-11 23:45:17 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2019-12-04 11:56:11 -05:00
|
|
|
# Copyright (c) 2018 M. Warner Losh <imp@FreeBSD.org>
|
2018-02-11 23:45:17 -05:00
|
|
|
#
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
|
# are met:
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
|
#
|
|
|
|
|
# $FreeBSD$
|
|
|
|
|
#
|
|
|
|
|
# PROVIDE: devmatch
|
2021-07-07 16:43:35 -04:00
|
|
|
# REQUIRE: kld
|
2020-05-16 14:37:48 -04:00
|
|
|
# BEFORE: netif
|
2018-02-11 23:45:17 -05:00
|
|
|
# KEYWORD: nojail
|
|
|
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
|
|
name="devmatch"
|
2018-02-11 23:52:25 -05:00
|
|
|
desc="Use devmatch(8) to load kernel modules"
|
2018-06-14 12:09:29 -04:00
|
|
|
rcvar="${name}_enable"
|
2018-02-11 23:45:17 -05:00
|
|
|
|
|
|
|
|
start_cmd="${name}_start"
|
|
|
|
|
stop_cmd=':'
|
2018-02-17 08:32:29 -05:00
|
|
|
one_nomatch="$2"
|
2018-02-11 23:45:17 -05:00
|
|
|
|
|
|
|
|
devmatch_start()
|
|
|
|
|
{
|
2018-08-23 01:06:27 -04:00
|
|
|
local x m list
|
2018-02-11 23:45:17 -05:00
|
|
|
|
2018-02-17 08:32:29 -05:00
|
|
|
if [ -n "$one_nomatch" ]; then
|
2018-08-23 01:06:27 -04:00
|
|
|
list=$(devmatch -p "${one_nomatch}" | sort -u)
|
2018-02-17 08:32:29 -05:00
|
|
|
else
|
2018-08-23 01:06:27 -04:00
|
|
|
list=$(devmatch | sort -u)
|
2018-02-17 08:32:29 -05:00
|
|
|
fi
|
2018-02-11 23:45:17 -05:00
|
|
|
|
2018-08-23 01:06:27 -04:00
|
|
|
[ -n "$list" ] || return
|
2018-02-11 23:45:17 -05:00
|
|
|
|
2021-07-08 15:44:21 -04:00
|
|
|
# While kldload can accept multiple modules on the line at once, we loop
|
|
|
|
|
# here in case there's some weird error with one of them. We also
|
|
|
|
|
# optimize against the false positives or drivers that have symbolic
|
|
|
|
|
# links that confuse devmatch by running it -n. Finally, we filter out
|
|
|
|
|
# all items in the devmatch_blocklist.
|
|
|
|
|
#
|
|
|
|
|
# We strip all the .ko suffixes off so that one may specify modules
|
|
|
|
|
# with or without .ko. Prior version documented it was without, while
|
|
|
|
|
# the code required it, so accept both now. devmatch produces module
|
|
|
|
|
# names with .ko
|
|
|
|
|
|
2018-08-23 01:06:07 -04:00
|
|
|
devctl freeze
|
2021-07-08 15:44:21 -04:00
|
|
|
x=$(echo '#'${devmatch_blocklist:-${devmatch_blacklist}}'#' | \
|
|
|
|
|
sed -e "s/ /#/g;s/\.ko#/#/g")
|
2018-08-23 01:06:27 -04:00
|
|
|
for m in ${list}; do
|
2021-07-08 15:44:21 -04:00
|
|
|
m="${m%.ko}"
|
|
|
|
|
case "${x}" in
|
2018-08-23 01:06:27 -04:00
|
|
|
*"#${m}#"*) continue ;;
|
|
|
|
|
esac
|
2021-07-08 15:53:18 -04:00
|
|
|
kldstat -q -n ${m} || \
|
|
|
|
|
(echo "Autoloading module: ${m}"; kldload -n ${m})
|
2018-02-17 01:57:21 -05:00
|
|
|
done
|
2018-08-23 01:06:07 -04:00
|
|
|
devctl thaw
|
2018-02-11 23:45:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
|
run_rc_command "$1"
|