From 61fb4aca35dab137e1fcb5b5f35363a6c6fb79b4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 30 Jan 2017 18:25:17 -0800 Subject: [PATCH] rc.d - Use kldstat -m to test existance before kldload * Use kldstat -m module || kldload -n module || exit 1 (roughly) when testing modules in rc scripts. * Fixes issue where kernels boot up in secure mode (aka vkernels do this by default) and rc scripts fail because kldload exits immediately with an error, even if the module already exists. --- etc/rc.d/abi | 2 +- etc/rc.d/addswap | 2 +- etc/rc.d/ip6fw | 2 +- etc/rc.d/ipfw | 2 +- etc/rc.d/mountcritremote | 2 +- etc/rc.d/nfsclient | 2 +- etc/rc.d/nfsserver | 2 +- etc/rc.d/pf | 2 +- etc/rc.d/pflog | 2 +- etc/rc.d/syscons | 2 +- etc/rc.d/vknetd | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/etc/rc.d/abi b/etc/rc.d/abi index 5b4f24b7df..46e5615591 100644 --- a/etc/rc.d/abi +++ b/etc/rc.d/abi @@ -18,7 +18,7 @@ start_cmd="linux_start" linux_start() { echo -n ' linux' - kldload -n linux + kldstat -m linux || kldload -n linux || return 1 if [ -x /compat/linux/sbin/ldconfig ]; then /compat/linux/sbin/ldconfig fi diff --git a/etc/rc.d/addswap b/etc/rc.d/addswap index 85195c5aea..cf250f8aa7 100644 --- a/etc/rc.d/addswap +++ b/etc/rc.d/addswap @@ -23,7 +23,7 @@ addswap_start() *) if [ -w "${swapfile}" ]; then # load vn kernel module if needed - kldload -n vn || exit 1 + kldstat -m vn || kldload -n vn || exit 1 echo "Adding ${swapfile} as additional swap" vnconfig -e vn0 ${swapfile} swap fi diff --git a/etc/rc.d/ip6fw b/etc/rc.d/ip6fw index 7544ee6ea6..a7e8cec88a 100644 --- a/etc/rc.d/ip6fw +++ b/etc/rc.d/ip6fw @@ -19,7 +19,7 @@ ip6fw_prestart() { # Load IPv6 firewall module, if not already loaded if ! ${SYSCTL} net.inet6.ip6.fw.enable > /dev/null 2>&1; then - kldload -n ip6fw || return 1 + kldstat -m ip6fw || kldload -n ip6fw || return 1 fi return 0 } diff --git a/etc/rc.d/ipfw b/etc/rc.d/ipfw index b2e45bb491..5107d14bbf 100644 --- a/etc/rc.d/ipfw +++ b/etc/rc.d/ipfw @@ -19,7 +19,7 @@ ipfw_precmd() { # Load IPv4 firewall module, if not already loaded if ! ${SYSCTL} net.inet.ip.fw.enable > /dev/null 2>&1; then - kldload -n ipfw || return 1 + kldstat -m ipfw || kldload -n ipfw || return 1 fi return 0 } diff --git a/etc/rc.d/mountcritremote b/etc/rc.d/mountcritremote index 820c1fedff..0d627ea83a 100644 --- a/etc/rc.d/mountcritremote +++ b/etc/rc.d/mountcritremote @@ -27,7 +27,7 @@ mountcritremote_precmd() case "`mount -d -a -t nfs 2> /dev/null`" in *mount_nfs*) # Handle absent nfs client support - kldload -n nfs || return 1 + kldstat -m nfs || kldload -n nfs || return 1 ;; esac return 0 diff --git a/etc/rc.d/nfsclient b/etc/rc.d/nfsclient index 55a2bd0496..a596051e1f 100644 --- a/etc/rc.d/nfsclient +++ b/etc/rc.d/nfsclient @@ -18,7 +18,7 @@ stop_cmd="unmount_all" # Load nfs module if it was not compiled into the kernel nfsclient_precmd() { - kldload -n nfs || return 1 + kldstat -m nfs || kldload -n nfs || return 1 return 0 } diff --git a/etc/rc.d/nfsserver b/etc/rc.d/nfsserver index e2b68542e1..55a217f713 100644 --- a/etc/rc.d/nfsserver +++ b/etc/rc.d/nfsserver @@ -16,7 +16,7 @@ stop_cmd=":" # Load nfs modules if they were not compiled into the kernel nfsserver_start() { - kldload -n nfs || return 1 + kldstat -m nfs || kldload -n nfs || return 1 return 0 } diff --git a/etc/rc.d/pf b/etc/rc.d/pf index 249d3f6f6e..605b333d3a 100644 --- a/etc/rc.d/pf +++ b/etc/rc.d/pf @@ -28,7 +28,7 @@ extra_commands="reload resync status" pf_prestart() { # load pf kernel module if needed - kldload -n pf || exit 1 + kldstat -m pf || kldload -n pf || exit 1 # check for pf rules if [ ! -r "${pf_rules}" ] diff --git a/etc/rc.d/pflog b/etc/rc.d/pflog index 48823f1dcd..dc5806af80 100644 --- a/etc/rc.d/pflog +++ b/etc/rc.d/pflog @@ -26,7 +26,7 @@ extra_commands="resync status" pflog_prestart() { # load pflog kernel module if needed - kldload -n pf || exit 1 + kldstat -m pf || kldload -n pf || exit 1 # set pflog0 interface to up state if ! ifconfig pflog0 up; then diff --git a/etc/rc.d/syscons b/etc/rc.d/syscons index 64cdf65e84..3d58eb3b3b 100644 --- a/etc/rc.d/syscons +++ b/etc/rc.d/syscons @@ -159,7 +159,7 @@ syscons_start() for i in `kldstat | awk '$5 ~ "^splash_.*$" { print $5 }'`; do kldunload ${i} done - kldload -n ${saver}_saver + kldstat -m ${saver}_saver || kldload -n ${saver}_saver ;; esac diff --git a/etc/rc.d/vknetd b/etc/rc.d/vknetd index 3d4682ba5d..c900f4e263 100644 --- a/etc/rc.d/vknetd +++ b/etc/rc.d/vknetd @@ -16,7 +16,7 @@ pidfile="/var/run/${name}.pid" vknetd_precmd() { # load if_tap kernel module if needed - kldload -n if_tap || exit 1 + kldstat -m if_tap || kldload -n if_tap || exit 1 } load_rc_config $name -- 2.11.4.GIT