Use $required_modules wherever suitable. Use load_kld() in special

cases.  So we get rid of quite a few lines of duplicated code.
This commit is contained in:
Yaroslav Tykhiy 2006-12-31 10:37:18 +00:00
parent 619a36fa66
commit 0c30639059
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=165683
21 changed files with 43 additions and 234 deletions

View File

@ -19,13 +19,13 @@ ibcs2_compat()
{
if checkyesno ibcs2_enable; then
echo -n ' ibcs2'
kldload ibcs2 > /dev/null 2>&1
load_kld ibcs2
case ${ibcs2_loaders} in
[Nn][Oo])
;;
*)
for i in ${ibcs2_loaders}; do
kldload ibcs2_$i > /dev/null 2>&1
load_kld ibcs2_$i
done
;;
esac

View File

@ -48,7 +48,7 @@ atm_start()
{
if [ -n "${natm_interfaces}" ] ; then
# Load the HARP pseudo interface
kldstat -v | grep -q if_harp || kldload if_harp
load_kld if_harp || return 1
# Load all the NATM drivers that we need
for natm in ${natm_interfaces} ; do
@ -58,7 +58,7 @@ atm_start()
# Load loadable HARP drivers
for dev in ${atm_load} ; do
kldstat -v | grep -q ${dev} || kldload ${dev}
load_kld ${dev} || return 1
done
# Locate all probed ATM adapters

View File

@ -36,6 +36,7 @@ name="bluetooth"
rcvar=
start_cmd="bluetooth_start"
stop_cmd="bluetooth_stop"
required_modules="ng_bluetooth ng_hci ng_l2cap ng_btsocket"
##############################################################################
# Read and parse Bluetooth device configuration file
@ -231,17 +232,11 @@ bluetooth_start()
dev=$1
# Automatically load modules
kldload ng_bluetooth > /dev/null 2>&1
kldload ng_hci > /dev/null 2>&1
kldload ng_l2cap > /dev/null 2>&1
kldload ng_btsocket > /dev/null 2>&1
# Try to figure out device type by looking at device name
case "${dev}" in
# sioX - serial/UART Bluetooth device
sio*)
kldload ng_h4 > /dev/null 2>&1
load_kld ng_h4 || return 1
hook="hook"

View File

@ -34,20 +34,15 @@
. /etc/rc.subr
name="geli"
start_precmd='[ -n "$(geli_make_list)" ]'
start_cmd="geli_start"
stop_cmd="geli_stop"
required_modules="geom_eli:g_eli"
geli_start()
{
devices=`geli_make_list`
# If there are no devices return before loading geom_eli.ko.
if [ -z "${devices}" ]; then
return
fi
kldstat -q -m g_eli || geli load || err 1 'geom_eli module failed to load.'
if [ -z "${geli_tries}" ]; then
if [ -n "${geli_attach_attempts}" ]; then
# Compatibility with rc.d/gbde.

View File

@ -14,21 +14,7 @@ name="hcsecd"
command="/usr/sbin/${name}"
pidfile="/var/run/${name}.pid"
rcvar=`set_rcvar`
start_precmd="hcsecd_prestart"
hcsecd_prestart()
{
if ! kldstat -q -m ng_btsocket ; then
if kldload ng_btsocket > /dev/null 2>&1 ; then
info 'ng_btsocket module loaded'
else
warn 'ng_btsocket module failed to load'
return 1
fi
fi
return 0
}
required_modules="ng_btsocket"
load_rc_config $name
config="${hcsecd_config:-/etc/bluetooth/${name}.conf}"

View File

@ -13,21 +13,8 @@
name="ip6fw"
rcvar=`set_rcvar ipv6_firewall`
start_cmd="ip6fw_start"
start_precmd="ip6fw_prestart"
stop_cmd="${SYSCTL_W} net.inet6.ip6.fw.enable=0"
ip6fw_prestart()
{
# Load IPv6 firewall module, if not already loaded
if ! ${SYSCTL} net.inet6.ip6.fw.enable > /dev/null 2>&1; then
kldload ipfw && {
debug 'Kernel IPv6 firewall module loaded.'
return 0
}
warn 'IPv6 firewall kernel module failed to load.'
return 1
fi
}
required_modules="ipfw"
ip6fw_start()
{

View File

@ -16,7 +16,7 @@ rcvar=`set_rcvar`
load_rc_config $name
stop_precmd="test -f ${ipfilter_rules} -o -f ${ipv6_ipfilter_rules}"
start_precmd="ipfilter_prestart"
start_precmd="$stop_precmd"
start_cmd="ipfilter_start"
stop_cmd="ipfilter_stop"
reload_precmd="$stop_precmd"
@ -26,35 +26,7 @@ resync_cmd="ipfilter_resync"
status_precmd="$stop_precmd"
status_cmd="ipfilter_status"
extra_commands="reload resync status"
ipfilter_loaded()
{
if ! kldstat -v | grep "ipfilter$" > /dev/null 2>&1; then
return 1
else
return 0
fi
}
ipfilter_prestart()
{
# load ipfilter kernel module if needed
if ! ipfilter_loaded; then
if kldload ipl; then
info 'IP-filter module loaded.'
else
err 1 'IP-filter module failed to load.'
fi
fi
# check for ipfilter rules
if [ ! -r "${ipfilter_rules}" ] && [ ! -r "${ipv6_ipfilter_rules}" ]
then
warn 'IP-filter: NO IPF RULES'
return 1
fi
return 0
}
required_modules="ipl:ipfilter"
ipfilter_start()
{
@ -111,10 +83,6 @@ ipfilter_reload()
ipfilter_resync()
{
# Don't resync if ipfilter is not loaded
if ! ipfilter_loaded; then
return
fi
${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags}
}

View File

@ -14,20 +14,8 @@
name="ipfw"
rcvar="firewall_enable"
start_cmd="ipfw_start"
start_precmd="ipfw_precmd"
stop_cmd="ipfw_stop"
ipfw_precmd()
{
if ! ${SYSCTL} net.inet.ip.fw.enable > /dev/null 2>&1; then
if ! kldload ipfw; then
warn unable to load firewall module.
return 1
fi
fi
return 0
}
required_modules="ipfw"
ipfw_start()
{

View File

@ -14,31 +14,15 @@
name="ipnat"
rcvar=`set_rcvar`
load_rc_config $name
start_precmd="ipnat_precmd"
start_cmd="ipnat_start"
stop_cmd="${ipnat_program} -F -C"
reload_cmd="${ipnat_program} -F -C -f ${ipnat_rules}"
extra_commands="reload"
ipnat_precmd()
{
# Make sure ipfilter is loaded before continuing
if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1; then
if kldload ipl; then
info 'IP-filter module loaded.'
else
err 1 'IP-filter module failed to load.'
fi
fi
return 0
}
required_files="${ipnat_rules}"
required_modules="ipl:ipfilter"
ipnat_start()
{
if [ ! -f ${ipnat_rules} ]; then
warn 'NO IPNAT RULES'
return 0
fi
echo "Installing NAT rules."
${ipnat_program} -CF -f ${ipnat_rules} ${ipnat_flags}
}

View File

@ -36,6 +36,8 @@
name="mdconfig"
stop_cmd="mdconfig_stop"
start_cmd="mdconfig_start"
start_precmd='[ -n "${_mdconfig_list}" ]'
required_modules="geom_md:g_md"
is_readonly()
{
@ -83,8 +85,6 @@ init_variables()
err 2 "You need to specify \"-f <file>\" in mdconfig_${_md} for vnode devices"
fi
if [ "${_file}" != "${_file%.uzip}" ]; then
# Load geom_uzip kernel module if needed
kldstat -q -m g_uzip || kldload geom_uzip || err 1 "geom_uzip failed to load."
_dev="/dev/${_md}.uzip"
fi
for _i in `df ${_file} 2>/dev/null`; do _fs=${_i}; done
@ -103,13 +103,6 @@ mdconfig_start()
{
local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd
# If there are no devices return before loading geom_md.ko.
if [ -z "${_mdconfig_list}" ]; then
return
fi
kldstat -q -m g_md || kldload geom_md || err 1 "geom_md failed to load."
for _md in ${_mdconfig_list}; do
init_variables ${_md}
# Create md(4) devices of types swap, malloc and vnode if the
@ -120,6 +113,9 @@ mdconfig_start()
warn "${_fs} is mounted read-only, skipping ${_md}."
continue
fi
if [ "${_file}" != "${_file%.uzip}" ]; then
load_kld -m g_uzip geom_uzip || return 3
fi
fi
if mdconfig -l -u ${_md} >/dev/null 2>&1; then
err 3 "${_md} already exists"

View File

@ -36,6 +36,8 @@
name="mdconfig2"
stop_cmd="mdconfig2_stop"
start_cmd="mdconfig2_start"
start_precmd='[ -n "${_mdconfig2_list}" ]'
required_modules="geom_md:g_md"
is_readonly()
{
@ -88,8 +90,6 @@ init_variables()
fi
if [ "${_file}" != "${_file%.uzip}" ]; then
# Load geom_uzip kernel module if needed
kldstat -q -m g_uzip || kldload geom_uzip || err 1 "geom_uzip failed to load."
_dev="/dev/${_md}.uzip"
fi
for _i in `df ${_file} 2>/dev/null`; do _fs=${_i}; done
@ -111,13 +111,6 @@ mdconfig2_start()
{
local _md _fs _mp _mounted _dev _config _type _file _owner _perms _files _populate _fsck_cmd _i
# If there are no devices return before loading geom_md.ko.
if [ -z "${_mdconfig2_list}" ]; then
return
fi
kldstat -q -m g_md || kldload geom_md || err 1 "geom_md failed to load."
for _md in ${_mdconfig2_list}; do
init_variables ${_md}
if [ ! -r ${_file} ]; then
@ -128,6 +121,9 @@ mdconfig2_start()
# non-root partition. Swap and malloc md(4) devices have already
# been created.
if [ "${_type}" = "vnode" -a "${_fs}" != "/" ]; then
if [ "${_file}" != "${_file%.uzip}" ]; then
load_kld -m g_uzip geom_uzip || return 3
fi
if is_readonly ${_fs}; then
warn "${_fs} is mounted read-only, skipping ${_md}."
continue

View File

@ -27,11 +27,7 @@ mountcritremote_precmd()
case "`mount -d -a -t nfs 2> /dev/null`" in
*mount_nfs*)
# Handle absent nfs client support
if ! sysctl vfs.nfs >/dev/null 2>&1; then
kldload nfsclient || { warn 'nfs mount ' \
'requested, but no nfs client in kernel'; \
return 1; }
fi
load_kld -m nfs nfsclient || return 1
;;
esac
return 0

View File

@ -14,16 +14,10 @@ rcvar=`set_rcvar`
command="/sbin/${name}"
pidfile="/var/run/${name}.pid"
start_precmd="natd_precmd"
required_modules="ipdivert"
natd_precmd()
{
if ! ${SYSCTL} net.inet.divert > /dev/null 2>&1; then
if ! kldload ipdivert; then
warn unable to load IPDIVERT module.
return 1
fi
fi
if [ -n "${natd_interface}" ]; then
dhcp_list="`list_net_interfaces dhcp`"
for ifn in ${dhcp_list}; do

View File

@ -12,20 +12,8 @@
name="nfsclient"
rcvar="nfs_client_enable"
start_cmd="nfsclient_start"
start_precmd="nfsclient_precmd"
stop_cmd="unmount_all"
# Load nfs module if it was not compiled into the kernel
nfsclient_precmd()
{
if ! sysctl vfs.nfs >/dev/null 2>&1; then
if ! kldload nfsclient; then
warn 'Could not load nfs client module'
return 1
fi
fi
return 0
}
required_modules="nfsclient:nfs"
nfsclient_start()
{

View File

@ -11,20 +11,9 @@
name="nfsserver"
rcvar="nfs_server_enable"
start_cmd="nfsserver_start"
start_cmd=":"
stop_cmd=":"
# Load nfs modules if they were not compiled into the kernel
nfsserver_start()
{
if ! sysctl vfs.nfsrv >/dev/null 2>&1; then
if ! kldload nfsserver; then
warn 'Could not load NFS server module'
return 1
fi
fi
return 0
}
required_modules="nfsserver"
load_rc_config $name
run_rc_command "$1"

View File

@ -13,7 +13,6 @@
name="pf"
rcvar=`set_rcvar`
load_rc_config $name
start_precmd="pf_prestart"
start_cmd="pf_start"
stop_cmd="pf_stop"
check_cmd="pf_check"
@ -22,20 +21,7 @@ resync_cmd="pf_resync"
status_cmd="pf_status"
extra_commands="check reload resync status"
required_files="$pf_rules"
pf_prestart()
{
# load pf kernel module if needed
if ! kldstat -q -m pf ; then
if kldload pf ; then
info 'pf module loaded.'
else
warn 'pf module failed to load.'
return 1
fi
fi
return 0
}
required_modules="pf"
pf_start()
{

View File

@ -22,15 +22,7 @@ resync_cmd="pflog_resync"
pflog_prestart()
{
# load pflog kernel module if needed
if ! kldstat -q -m pflog; then
if kldload pflog; then
info 'pflog module loaded.'
else
warn 'pflog module failed to load.'
return 1
fi
fi
load_kld pflog || return 1
# set pflog0 interface to up state
if ! ifconfig pflog0 up; then

View File

@ -14,26 +14,23 @@ rcvar=`set_rcvar`
start_precmd="pfsync_prestart"
start_cmd="pfsync_start"
stop_cmd="pfsync_stop"
required_modules="pf"
pfsync_prestart()
{
# XXX Currently pfsync cannot be a module as it must register
# a network protocol in a static kernel table.
if ! kldstat -q -m pfsync; then
warn "pfsync(4) must be statically compiled in the kernel."
return 1
fi
case "$pfsync_syncdev" in
'')
warn "pfsync_syncdev is not set."
return 1
;;
esac
# load pf kernel module if needed
if ! kldstat -q -m pf ; then
if kldload pf ; then
info "pf module loaded."
else
warn "pf module failed to load."
return 1
fi
fi
return 0
}

View File

@ -13,21 +13,7 @@
name="sdpd"
command="/usr/sbin/${name}"
rcvar=`set_rcvar`
start_precmd="sdpd_prestart"
sdpd_prestart()
{
if ! kldstat -q -m ng_btsocket ; then
if kldload ng_btsocket > /dev/null 2>&1 ; then
info 'ng_btsocket module loaded'
else
warn 'ng_btsocket module failed to load'
return 1
fi
fi
return 0
}
required_modules="ng_btsocket"
load_rc_config $name
control="${sdpd_control:-/var/run/sdp}"

View File

@ -213,7 +213,7 @@ syscons_start()
for i in `kldstat | awk '$5 ~ "^splash_.*$" { print $5 }'`; do
kldunload ${i}
done
kldstat -v | grep -q _saver || kldload ${saver}_saver
load_kld -e _saver ${saver}_saver
;;
esac

View File

@ -12,8 +12,8 @@
name="ugidfw"
rcvar="ugidfw_enable"
start_cmd="ugidfw_start"
start_precmd="ugidfw_precmd"
stop_cmd="ugidfw_stop"
required_modules="mac_bsdextended"
ugidfw_load()
{
@ -22,20 +22,6 @@ ugidfw_load()
fi
}
ugidfw_precmd()
{
if ! sysctl security.mac.bsdextended
then kldload mac_bsdextended
if [ "$?" -ne "0" ]
then warn Unable to load the mac_bsdextended module.
return 1
else
return 0
fi
fi
return 0
}
ugidfw_start()
{
[ -z "${bsdextended_script}" ] && bsdextended_script=/etc/rc.bsdextended