xref: /freebsd/libexec/rc/rc.d/devfs (revision cbb3ec25236ba72f91cbdf23f8b78b9d1af0cedf)
1#!/bin/sh
2#
3#
4
5# PROVIDE: devfs
6# REQUIRE: mountcritremote
7# BEFORE:  SERVERS securelevel
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="devfs"
13desc="Device filesystem"
14start_cmd='devfs_start'
15stop_cmd=':'
16
17devfs_start()
18{
19	if [ -n "$devfs_system_ruleset" -o -n "$devfs_set_rulesets" ] ||
20	    checkyesno devfs_load_rulesets; then
21		devfs_init_rulesets
22		if [ -n "$devfs_system_ruleset" ]; then
23			devfs_set_ruleset $devfs_system_ruleset /dev
24			devfs_apply_ruleset $devfs_system_ruleset /dev
25		fi
26		if [ -n "$devfs_set_rulesets" ]; then
27			local _dir_set
28			local _dir
29			local _set
30			for _dir_set in $devfs_set_rulesets; do
31				_dir=${_dir_set%=*}
32				_set=${_dir_set#*=}
33				devfs_set_ruleset $_set $_dir
34				devfs_apply_ruleset $_set $_dir
35			done
36		fi
37	fi
38	read_devfs_conf
39}
40
41read_devfs_conf()
42{
43	if [ -r /etc/devfs.conf ]; then
44		cd /dev
45		while read action devicelist parameter; do
46			case "${action}" in
47			l*)	for device in ${devicelist}; do
48					if [ ! -e ${parameter} ]; then
49						ln -fs ${device} ${parameter}
50					fi
51				done
52				;;
53			o*)	for device in ${devicelist}; do
54					if [ -c ${device} ]; then
55						chown ${parameter} ${device}
56					fi
57				done
58				;;
59			p*)	for device in ${devicelist}; do
60					if [ -c ${device} ]; then
61						chmod ${parameter} ${device}
62					fi
63				done
64				;;
65			esac
66		done < /etc/devfs.conf
67	fi
68}
69
70load_rc_config $name
71run_rc_command "$1"
72