rc: Use SYSCTL{,_N,_W} variables
authorAaron LI <aly@aaronly.me>
Sun, 9 Dec 2018 02:55:55 +0000 (10:55 +0800)
committerAaron LI <aly@aaronly.me>
Wed, 12 Dec 2018 13:11:09 +0000 (21:11 +0800)
With minor cleanups to IO redirections.

19 files changed:
etc/network.subr
etc/rc.d/devd
etc/rc.d/diskless
etc/rc.d/fixbootfile
etc/rc.d/initdiskless
etc/rc.d/initrandom
etc/rc.d/ip6fw
etc/rc.d/ipfw
etc/rc.d/ipfw3
etc/rc.d/jail
etc/rc.d/netoptions
etc/rc.d/nfsclient
etc/rc.d/nfsd
etc/rc.d/random
etc/rc.d/routing
etc/rc.d/serial
etc/rc.d/sysctl
etc/rc.d/watchdogd
etc/rc.d/wpa_supplicant

index aaacb00..037a034 100644 (file)
@@ -610,7 +610,7 @@ network6_interface_setup()
                # You can configure only single interface, as
                # specification assumes that autoconfigured host has
                # single interface only.
-               sysctl net.inet6.ip6.accept_rtadv=1
+               ${SYSCTL_W} net.inet6.ip6.accept_rtadv=1
                set ${rtsol_interfaces}
                ifconfig $1 up
                rtsol $1
@@ -749,7 +749,7 @@ network6_default_interface_setup()
                [Yy][Ee][Ss])
                        ;;
                *)
-                       if [ `sysctl -n net.inet6.ip6.accept_rtadv` -eq 1 ]
+                       if [ `${SYSCTL_N} net.inet6.ip6.accept_rtadv` -eq 1 ]
                        then
                                ndp -I ${ipv6_default_interface}
                        fi
index 7e76c0b..28b9a64 100644 (file)
@@ -32,7 +32,7 @@ devd_prestart()
 
        # If devd is disabled, turn it off in the kernel to avoid memory leaks.
        if ! checkyesno ${rcvar}; then
-           $SYSCTL hw.bus.devctl_disable=1
+           ${SYSCTL_W} hw.bus.devctl_disable=1
        fi
 }
 
index 759afe9..6c5e357 100644 (file)
@@ -25,7 +25,6 @@
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.d/diskless,v 1.25 2003/02/15 16:34:14 jhay Exp $
-# $DragonFly: src/etc/rc.d/diskless,v 1.7 2007/05/13 22:25:41 swildner Exp $
 #
 
 # PROVIDE: diskless
@@ -37,7 +36,7 @@ if [ -r /etc/rc.subr ]; then
     dummy_rc_command "$1"
 fi
 
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
+dlv=`${SYSCTL_N} -q vfs.nfs.diskless_valid`
 [ ${dlv:=0} -eq 0 ] && exit 0
 
 name="diskless"
index 3c4f327..864d05e 100644 (file)
@@ -22,9 +22,9 @@ fixbootfile_start()
        [Nn][Oo])
                ;;
        *)
-               bootfile=`sysctl -n kern.bootfile`
+               bootfile=`${SYSCTL_N} kern.bootfile`
                if [ -f "/boot$bootfile" ]; then
-                       sysctl kern.bootfile="/boot$bootfile"
+                       ${SYSCTL_W} kern.bootfile="/boot$bootfile"
                fi
                ;;
        esac
index 830b7fe..cbaae5d 100644 (file)
@@ -25,7 +25,6 @@
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.d/initdiskless,v 1.24 2003/06/30 21:47:06 brooks Exp $
-# $DragonFly: src/etc/rc.d/initdiskless,v 1.9 2008/02/19 22:02:47 thomas Exp $
 #
 # PROVIDE: initdiskless
 
@@ -85,7 +84,7 @@ dummy_rc_command "$1"
 # NOTE!  rc.d/diskless will create /var, /tmp, and /dev.  Those filesystems
 # should not be specified in /conf.  At least not yet.
 
-dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
+dlv=`${SYSCTL_N} -q vfs.nfs.diskless_valid`
 [ ${dlv:=0} -eq 0 ] && exit 0
 
 # chkerr:
index 7f65700..a367135 100644 (file)
@@ -1,7 +1,6 @@
 #!/bin/sh
 #
 # $FreeBSD: src/etc/rc.d/initrandom,v 1.1 2002/06/13 22:14:36 gordon Exp $
-# $DragonFly: src/etc/rc.d/initrandom,v 1.6 2006/07/10 22:19:14 dillon Exp $
 #
 
 # PROVIDE: initrandom
@@ -17,9 +16,9 @@ stop_cmd=":"
 feed_dev_random()
 {
        if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
-               sysctl kern.seedenable=1 >/dev/null
+               ${SYSCTL_W} kern.seedenable=1 >/dev/null
                cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
-               sysctl kern.seedenable=0 >/dev/null
+               ${SYSCTL_W} kern.seedenable=0 >/dev/null
        fi
 }
 
@@ -38,16 +37,16 @@ initrandom_start()
        esac
 
        # Mix in more junk.  At the very least this will make seeding a
-       # bit more machine specific.  The sysctl -a will also catch the
+       # bit more machine specific.  The 'sysctl -a' will also catch the
        # TSC, 8254, and a few other things that tend to be somewhat more
        # random (even from a CD boot) so it isn't all that bad.
        #
        echo -n 'Initializing random seed: '
-       sysctl kern.seedenable=1 >/dev/null
-       ( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \
+       ${SYSCTL_W} kern.seedenable=1 >/dev/null
+       ( ps -fauxww; ${SYSCTL} -a; date; df -ib; dmesg; ps -fauxww; ) \
            2>&1 | dd of=/dev/random bs=8k 2>/dev/null
        cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
-       sysctl kern.seedenable=0 >/dev/null
+       ${SYSCTL_W} kern.seedenable=0 >/dev/null
        echo 'done. '
 }
 
index 116f2e9..5e598c4 100644 (file)
@@ -18,7 +18,7 @@ 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
+       if ! ${SYSCTL} -q net.inet6.ip6.fw.enable >/dev/null; then
                kldstat -qm ip6fw || kldload -n ip6fw || return 1
        fi
        return 0
@@ -45,7 +45,7 @@ ip6fw_start()
        #
        if checkyesno ipv6_firewall_logging; then
                echo 'IPv6 Firewall logging=YES'
-               sysctl net.inet6.ip6.fw.verbose=1 >/dev/null
+               ${SYSCTL_W} net.inet6.ip6.fw.verbose=1 >/dev/null
        fi
 }
 
index c7ab3cd..6e4b1be 100644 (file)
@@ -18,7 +18,7 @@ stop_cmd="ipfw_stop"
 ipfw_precmd()
 {
        # Load IPv4 firewall module, if not already loaded
-       if ! ${SYSCTL} net.inet.ip.fw.enable > /dev/null 2>&1; then
+       if ! ${SYSCTL} -q net.inet.ip.fw.enable >/dev/null; then
                kldstat -qm ipfw || kldload -n ipfw || return 1
        fi
        return 0
@@ -58,7 +58,7 @@ ipfw_start()
        #
        if checkyesno firewall_logging; then
                echo 'Firewall logging enabled'
-               sysctl net.inet.ip.fw.verbose=1 >/dev/null
+               ${SYSCTL_W} net.inet.ip.fw.verbose=1 >/dev/null
        fi
 
        # Enable the firewall
index 46f2629..cc24447 100644 (file)
@@ -47,7 +47,7 @@ stop_cmd="${name}_stop"
 ipfw3_precmd()
 {
        # Load firewall modules, if not already loaded
-       if ! ${SYSCTL} net.inet.ip.fw3.enable > /dev/null 2>&1; then
+       if ! ${SYSCTL} -q net.inet.ip.fw3.enable >/dev/null; then
                for _module in ${ipfw3_modules}; do
                        kldload -n ${_module} || return 1
                done
index 789d829..018d731 100644 (file)
@@ -106,16 +106,16 @@ set_sysctl()
        _mib="$2"
        _msg="$3"
 
-       _current=`${SYSCTL} -n $_mib 2>/dev/null`
+       _current=`${SYSCTL_N} -q $_mib`
        if checkyesno $_knob ; then
                if [ "$_current" -ne 1 ]; then
                        echo -n " ${_msg}=YES"
-                       ${SYSCTL_W} 1>/dev/null ${_mib}=1
+                       ${SYSCTL_W} ${_mib}=1 >/dev/null
                fi
        else
                if [ "$_current" -ne 0 ]; then
                        echo -n " ${_msg}=NO"
-                       ${SYSCTL_W} 1>/dev/null ${_mib}=0
+                       ${SYSCTL_W} ${_mib}=0 >/dev/null
                fi
        fi
 }
index 1cd4e64..4063461 100644 (file)
@@ -1,7 +1,6 @@
 #!/bin/sh
 #
 # $FreeBSD: src/etc/rc.d/netoptions,v 1.138 2003/06/29 05:09:48 mtm Exp $
-# $DragonFly: src/etc/rc.d/netoptions,v 1.4 2005/11/19 21:47:32 swildner Exp $
 #
 
 # PROVIDE: netoptions
@@ -32,7 +31,7 @@ esac
 
 [ "${log_in_vain}" -ne 0 ] && (
        echo -n " log_in_vain=${log_in_vain}"
-       sysctl net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
-       sysctl net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
+       ${SYSCTL_W} net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
+       ${SYSCTL_W} net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
 )
 echo '.'
index 1021cef..4359db1 100644 (file)
@@ -29,16 +29,16 @@ nfsclient_start()
        #
        echo -n "NFS CLIENT:"
        if [ -n "${nfs_access_cache}" ]; then
-               sysctl vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
+               ${SYSCTL_W} vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
        fi
        if [ -n "${nfs_neg_cache}" ]; then
-               sysctl vfs.nfs.neg_cache_timeout=${nfs_neg_cache} >/dev/null
+               ${SYSCTL_W} vfs.nfs.neg_cache_timeout=${nfs_neg_cache} >/dev/null
        fi
        if [ -n "${nfs_bufpackets}" ]; then
-               sysctl vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
+               ${SYSCTL_W} vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
        fi
-       echo -n " access_cache_timeout=`sysctl -n vfs.nfs.access_cache_timeout`"
-       echo -n " neg_cache_timeout=`sysctl -n vfs.nfs.neg_cache_timeout`"
+       echo -n " access_cache_timeout=`${SYSCTL_N} vfs.nfs.access_cache_timeout`"
+       echo -n " neg_cache_timeout=`${SYSCTL_N} vfs.nfs.neg_cache_timeout`"
        unmount_all
 }
 
index 03d72fd..578e850 100644 (file)
@@ -2,7 +2,6 @@
 #
 # $NetBSD: nfsd,v 1.4 2001/06/16 06:13:10 lukem Exp $
 # $FreeBSD: src/etc/rc.d/nfsd,v 1.9 2003/01/24 00:37:52 mtm Exp $
-# $DragonFly: src/etc/rc.d/nfsd,v 1.5 2005/11/19 21:47:32 swildner Exp $
 #
 
 # PROVIDE: nfsd
@@ -21,7 +20,7 @@ sig_stop="USR1"
 
 nfsd_precmd()
 {
-       if ! sysctl vfs.nfs >/dev/null 2>&1; then
+       if ! ${SYSCTL} -q vfs.nfs >/dev/null; then
                force_depend nfsserver || return 1
        fi
 
@@ -39,7 +38,7 @@ nfsd_precmd()
 
        if checkyesno nfs_reserved_port_only; then
                echo 'NFS on reserved port only=YES'
-               sysctl vfs.nfs.nfs_privport=1 > /dev/null
+               ${SYSCTL_W} vfs.nfs.nfs_privport=1 >/dev/null
        fi
        return 0
 }
index 0353829..b31773e 100644 (file)
@@ -1,7 +1,6 @@
 #!/bin/sh
 #
 # $FreeBSD: src/etc/rc.d/random,v 1.3 2003/04/18 17:55:05 mtm Exp $
-# $DragonFly: src/etc/rc.d/random,v 1.4 2006/07/10 22:19:14 dillon Exp $
 #
 
 # PROVIDE: random
@@ -18,12 +17,12 @@ stop_cmd="random_stop"
 feed_dev_random()
 {
        if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
-               sysctl kern.seedenable=1 >/dev/null
+               ${SYSCTL_W} kern.seedenable=1 >/dev/null
                # Feed using a small block size so that a pool-based CSPRNG
                # is more likely to distribute the entropy over several
                # pools
                cat "${1}" | dd of=/dev/random bs=512 2>/dev/null
-               sysctl kern.seedenable=0 >/dev/null
+               ${SYSCTL_W} kern.seedenable=0 >/dev/null
        fi
 }
 
index 226e6c1..11e8420 100644 (file)
@@ -71,70 +71,70 @@ options_start()
                ;;
        *)
                echo -n ' tcp extensions=NO'
-               sysctl net.inet.tcp.rfc1323=0 >/dev/null
+               ${SYSCTL_W} net.inet.tcp.rfc1323=0 >/dev/null
                ;;
        esac
 
        case ${icmp_bmcastecho} in
        [Yy][Ee][Ss])
                echo -n ' broadcast ping responses=YES'
-               sysctl net.inet.icmp.bmcastecho=1 >/dev/null
+               ${SYSCTL_W} net.inet.icmp.bmcastecho=1 >/dev/null
                ;;
        esac
 
        case ${icmp_drop_redirect} in
        [Yy][Ee][Ss])
                echo -n ' ignore ICMP redirect=YES'
-               sysctl net.inet.icmp.drop_redirect=1 >/dev/null
+               ${SYSCTL_W} net.inet.icmp.drop_redirect=1 >/dev/null
                ;;
        esac
 
        case ${icmp_log_redirect} in
        [Yy][Ee][Ss])
                echo -n ' log ICMP redirect=YES'
-               sysctl net.inet.icmp.log_redirect=1 >/dev/null
+               ${SYSCTL_W} net.inet.icmp.log_redirect=1 >/dev/null
                ;;
        esac
 
        case ${gateway_enable} in
        [Yy][Ee][Ss])
                echo -n ' IP gateway=YES'
-               sysctl net.inet.ip.forwarding=1 >/dev/null
+               ${SYSCTL_W} net.inet.ip.forwarding=1 >/dev/null
                ;;
        esac
 
        case ${forward_sourceroute} in
        [Yy][Ee][Ss])
                echo -n ' do source routing=YES'
-               sysctl net.inet.ip.sourceroute=1 >/dev/null
+               ${SYSCTL_W} net.inet.ip.sourceroute=1 >/dev/null
                ;;
        esac
 
        case ${accept_sourceroute} in
        [Yy][Ee][Ss])
                echo -n ' accept source routing=YES'
-               sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
+               ${SYSCTL_W} net.inet.ip.accept_sourceroute=1 >/dev/null
                ;;
        esac
 
        case ${tcp_keepalive} in
        [Nn][Oo])
                echo -n ' TCP keepalive=NO'
-               sysctl net.inet.tcp.always_keepalive=0 >/dev/null
+               ${SYSCTL_W} net.inet.tcp.always_keepalive=0 >/dev/null
                ;;
        esac
 
        case ${tcp_drop_synfin} in
        [Yy][Ee][Ss])
                echo -n ' drop SYN+FIN packets=YES'
-               sysctl net.inet.tcp.drop_synfin=1 >/dev/null
+               ${SYSCTL_W} net.inet.tcp.drop_synfin=1 >/dev/null
                ;;
        esac
 
        case ${arpproxy_all} in
        [Yy][Ee][Ss])
                echo -n ' ARP proxyall=YES'
-               sysctl net.link.ether.inet.proxyall=1 >/dev/null
+               ${SYSCTL_W} net.link.ether.inet.proxyall=1 >/dev/null
                ;;
        esac
 
@@ -143,7 +143,7 @@ options_start()
                ;;
        *)
                echo -n " ip_portrange_first=$ip_portrange_first"
-               sysctl net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
+               ${SYSCTL_W} net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
                ;;
        esac
 
@@ -152,7 +152,7 @@ options_start()
                ;;
        *)
                echo -n " ip_portrange_last=$ip_portrange_last"
-               sysctl net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
+               ${SYSCTL_W} net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
                ;;
        esac
 
index a481714..69040d2 100644 (file)
@@ -25,7 +25,6 @@
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.d/serial,v 1.20 2003/05/05 03:26:50 bde Exp $
-# $DragonFly: src/etc/rc.d/serial,v 1.4 2005/11/19 21:47:32 swildner Exp $
 #
 
 # PROVIDE: serial
@@ -50,7 +49,7 @@ default() {
 
        ci=$1; shift    # call in device identifier
        co=$1; shift    # call out device identifier
-       drainwait=`sysctl -n kern.drainwait`
+       drainwait=`${SYSCTL_N} kern.drainwait`
 
        for i in $*
        do
index 835623b..74e83a2 100644 (file)
@@ -2,7 +2,6 @@
 #
 # $NetBSD: sysctl,v 1.12 2002/04/29 12:10:23 lukem Exp $
 # $FreeBSD: src/etc/rc.d/sysctl,v 1.12 2003/04/24 08:20:47 mtm Exp $
-# $DragonFly: src/etc/rc.d/sysctl,v 1.5 2005/11/19 21:47:32 swildner Exp $
 #
 
 # PROVIDE: sysctl
@@ -33,12 +32,12 @@ DragonFly_start()
                                mib=${var%=*}
                                val=${var#*=}
 
-                               if current_value=`${SYSCTL} -n ${mib} 2>/dev/null`; then
+                               if current_value=`${SYSCTL_N} -q ${mib}`; then
                                        case ${current_value} in
                                        ${val})
                                                ;;
                                        *)
-                                               sysctl ${var}
+                                               ${SYSCTL_W} ${var}
                                                ;;
                                        esac
                                elif [ "$1" = "last" ]; then
index 2d7f99b..31b34af 100644 (file)
@@ -25,7 +25,6 @@
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.d/watchdogd,v 1.1 2003/06/26 09:50:51 smkelly Exp $
-# $DragonFly: src/etc/rc.d/watchdogd,v 1.3 2005/11/19 21:47:32 swildner Exp $
 #
 
 # PROVIDE: watchdogd
@@ -41,7 +40,7 @@ pidfile="/var/run/${name}.pid"
 
 watchdogd_precmd()
 {
-       if ! sysctl debug.watchdog >/dev/null 2>&1; then
+       if ! ${SYSCTL} -q debug.watchdog >/dev/null; then
                err 1 "Your kernel doesn't have watchdog support."
        fi
        return 0
index 952fbc6..9031916 100644 (file)
@@ -53,7 +53,7 @@ fi
 
 is_ndis_interface()
 {
-       case `sysctl -n net.wlan.${1#wlan}.%parent 2>/dev/null` in
+       case `${SYSCTL_N} -q net.wlan.${1#wlan}.%parent` in
                ndis*) true ;;
                *) false ;;
        esac