xref: /dragonfly/etc/rc.d/sysctl (revision 35e996c9)
1#!/bin/sh
2#
3# $NetBSD: sysctl,v 1.12 2002/04/29 12:10:23 lukem Exp $
4# $FreeBSD: src/etc/rc.d/sysctl,v 1.12 2003/04/24 08:20:47 mtm Exp $
5#
6
7# PROVIDE: sysctl
8# REQUIRE: FILESYSTEMS
9# REQUIRE: modules
10# BEFORE:  NETWORKING
11
12. /etc/rc.subr
13
14name="sysctl"
15required_files="/etc/sysctl.conf"
16stop_cmd=":"
17start_cmd="sysctl_start"
18reload_cmd="sysctl_start"
19lastload_cmd="sysctl_start last"
20extra_commands="reload lastload"
21
22sysctl_start()
23{
24	local config extra mib val old_val output
25
26	if [ ! -f "/etc/sysctl.conf" ]; then
27		return
28	fi
29
30	# NOTE: Do not miss the last line when it does not end with a LF.
31	while read config extra || [ -n "${config}" ]; do
32		case ${config} in
33		\#*|'')
34			continue
35			;;
36		*[^=]=[^=]*)
37			mib=${config%=*}
38			val=${config#*=}
39			;;
40		*)
41			warn "invalid syntax: ${config}"
42			continue
43			;;
44		esac
45
46		if old_val=$(${SYSCTL_N} -q ${mib}); then
47			debug "sysctl '${mib}': '${old_val}' -> '${val}'"
48			if [ "${old_val}" != "${val}" ]; then
49				output=$(${SYSCTL_W} ${mib}=${val})
50				echo ${output}
51			fi
52		elif [ "$1" = "last" ]; then
53			warn "sysctl '${mib}' does not exist."
54		fi
55	done < /etc/sysctl.conf
56}
57
58load_rc_config $name
59run_rc_command "$1"
60