19c600e7dSMatthew Dillon#!/bin/sh 29c600e7dSMatthew Dillon# 39c600e7dSMatthew Dillon# $NetBSD: sysctl,v 1.12 2002/04/29 12:10:23 lukem Exp $ 49c600e7dSMatthew Dillon# $FreeBSD: src/etc/rc.d/sysctl,v 1.12 2003/04/24 08:20:47 mtm Exp $ 59c600e7dSMatthew Dillon# 69c600e7dSMatthew Dillon 79c600e7dSMatthew Dillon# PROVIDE: sysctl 8*ce083385SAaron LI# REQUIRE: FILESYSTEMS 9*ce083385SAaron LI# REQUIRE: modules 10*ce083385SAaron LI# BEFORE: NETWORKING 119c600e7dSMatthew Dillon 129c600e7dSMatthew Dillon. /etc/rc.subr 139c600e7dSMatthew Dillon 149c600e7dSMatthew Dillonname="sysctl" 1587206e7cSAaron LIrequired_files="/etc/sysctl.conf" 169c600e7dSMatthew Dillonstop_cmd=":" 1787206e7cSAaron LIstart_cmd="sysctl_start" 1887206e7cSAaron LIreload_cmd="sysctl_start" 1987206e7cSAaron LIlastload_cmd="sysctl_start last" 209c600e7dSMatthew Dillonextra_commands="reload lastload" 21e5f78e6cSMatthew Dillon 2287206e7cSAaron LIsysctl_start() 239c600e7dSMatthew Dillon{ 24e7f4639aSzrj local config extra mib val old_val output 2587206e7cSAaron LI 2687206e7cSAaron LI if [ ! -f "/etc/sysctl.conf" ]; then 2787206e7cSAaron LI return 2887206e7cSAaron LI fi 2987206e7cSAaron LI 3087206e7cSAaron LI # NOTE: Do not miss the last line when it does not end with a LF. 3187206e7cSAaron LI while read config extra || [ -n "${config}" ]; do 3287206e7cSAaron LI case ${config} in 339c600e7dSMatthew Dillon \#*|'') 3487206e7cSAaron LI continue 3587206e7cSAaron LI ;; 3687206e7cSAaron LI *[^=]=[^=]*) 3787206e7cSAaron LI mib=${config%=*} 3887206e7cSAaron LI val=${config#*=} 399c600e7dSMatthew Dillon ;; 409c600e7dSMatthew Dillon *) 4187206e7cSAaron LI warn "invalid syntax: ${config}" 4287206e7cSAaron LI continue 439c600e7dSMatthew Dillon ;; 449c600e7dSMatthew Dillon esac 4587206e7cSAaron LI 46dcd3d479SAaron LI if old_val=$(${SYSCTL_N} -q ${mib}); then 47dcd3d479SAaron LI debug "sysctl '${mib}': '${old_val}' -> '${val}'" 48dcd3d479SAaron LI if [ "${old_val}" != "${val}" ]; then 49e7f4639aSzrj output=$(${SYSCTL_W} ${mib}=${val}) 50e7f4639aSzrj echo ${output} 51dcd3d479SAaron LI fi 529c600e7dSMatthew Dillon elif [ "$1" = "last" ]; then 5387206e7cSAaron LI warn "sysctl '${mib}' does not exist." 549c600e7dSMatthew Dillon fi 559c600e7dSMatthew Dillon done < /etc/sysctl.conf 569c600e7dSMatthew Dillon} 579c600e7dSMatthew Dillon 589c600e7dSMatthew Dillonload_rc_config $name 599c600e7dSMatthew Dillonrun_rc_command "$1" 60