rc.d: Add mounttmpfs to support tmpfs at /var/run and /tmp
[dragonfly.git] / etc / rc.d / sysctl
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: root modules
9 # BEFORE:  DAEMON
10
11 . /etc/rc.subr
12
13 name="sysctl"
14 required_files="/etc/sysctl.conf"
15 stop_cmd=":"
16 start_cmd="sysctl_start"
17 reload_cmd="sysctl_start"
18 lastload_cmd="sysctl_start last"
19 extra_commands="reload lastload"
20
21 sysctl_start()
22 {
23         local config extra mib val old_val output
24
25         if [ ! -f "/etc/sysctl.conf" ]; then
26                 return
27         fi
28
29         # NOTE: Do not miss the last line when it does not end with a LF.
30         while read config extra || [ -n "${config}" ]; do
31                 case ${config} in
32                 \#*|'')
33                         continue
34                         ;;
35                 *[^=]=[^=]*)
36                         mib=${config%=*}
37                         val=${config#*=}
38                         ;;
39                 *)
40                         warn "invalid syntax: ${config}"
41                         continue
42                         ;;
43                 esac
44
45                 if old_val=$(${SYSCTL_N} -q ${mib}); then
46                         debug "sysctl '${mib}': '${old_val}' -> '${val}'"
47                         if [ "${old_val}" != "${val}" ]; then
48                                 output=$(${SYSCTL_W} ${mib}=${val})
49                                 echo ${output}
50                         fi
51                 elif [ "$1" = "last" ]; then
52                         warn "sysctl '${mib}' does not exist."
53                 fi
54         done < /etc/sysctl.conf
55 }
56
57 load_rc_config $name
58 run_rc_command "$1"