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