rc revision 88531
140123Sdes#!/bin/sh
266830Sobrien#
366830Sobrien# Copyright (c) 2000  The FreeBSD Project
466830Sobrien# All rights reserved.
566830Sobrien#
666830Sobrien# Redistribution and use in source and binary forms, with or without
766830Sobrien# modification, are permitted provided that the following conditions
866830Sobrien# are met:
966830Sobrien# 1. Redistributions of source code must retain the above copyright
1066830Sobrien#    notice, this list of conditions and the following disclaimer.
1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright
1266830Sobrien#    notice, this list of conditions and the following disclaimer in the
1366830Sobrien#    documentation and/or other materials provided with the distribution.
1466830Sobrien#
1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1866830Sobrien# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2566830Sobrien# SUCH DAMAGE.
2666830Sobrien#
2783871Sobrien#	@(#)rc	5.27 (Berkeley) 6/5/91
2850472Speter# $FreeBSD: head/etc/rc 88531 2001-12-27 13:41:27Z sheldonh $
2966830Sobrien#
3037Srgrimes
3137Srgrimes# System startup script run by init on autoboot
3237Srgrimes# or after single-user.
3337Srgrimes# Output and error are redirected to console by init,
3437Srgrimes# and the console is the controlling terminal.
3537Srgrimes
3651231Ssheldonh# Note that almost all of the user-configurable behavior is no longer in
3751231Ssheldonh# this file, but rather in /etc/defaults/rc.conf.  Please check that file
3851231Ssheldonh# first before contemplating any changes here.  If you do need to change
3951231Ssheldonh# this file for some reason, we would like to know about it.
408460Sjkh
4137Srgrimesstty status '^T'
4237Srgrimes
4337Srgrimes# Set shell to ignore SIGINT (2), but not children;
4437Srgrimes# shell catches SIGQUIT (3) and returns to single user after fsck.
4551231Ssheldonh#
4637Srgrimestrap : 2
4737Srgrimestrap : 3	# shouldn't be needed
4837Srgrimes
4968985Sdougbbootmode=$1
5068985Sdougb
5151231SsheldonhHOME=/
5220684SjoergPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
5351231Ssheldonhexport HOME PATH
5437Srgrimes
5543179Sdillon# BOOTP diskless boot.  We have to run the rc file early in order to
5643803Sdillon# retarget various config files.
5743179Sdillon#
5851231Ssheldonhif [ -r /etc/rc.diskless1 ]; then
5943375Sdillon	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
6043375Sdillon	if [ ${dlv:=0} != 0 ]; then
6143803Sdillon		. /etc/rc.diskless1
6243179Sdillon	fi
6343179Sdillonfi
6443179Sdillon
6543219Speter# If there is a global system configuration file, suck it in.
6643219Speter#
6751231Ssheldonhif [ -r /etc/defaults/rc.conf ]; then
6843849Sjkh	. /etc/defaults/rc.conf
6959674Ssheldonh	source_rc_confs
7051231Ssheldonhelif [ -r /etc/rc.conf ]; then
7143219Speter	. /etc/rc.conf
7243219Speterfi
7343219Speter
7471014Sdougbfeed_dev_random() {
7571014Sdougb	if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
7678918Srwatson#		echo "Using ${1} as an entropy file"
7771014Sdougb		cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
7871014Sdougb	fi
7971014Sdougb}
8071014Sdougb
8169988Sbsdchkdepend() {
8269988Sbsd	svc=$1
8369988Sbsd	svc_var=$2
8469988Sbsd	dep=$3
8569988Sbsd	dep_var=$4
8669988Sbsd
8769988Sbsd	eval svc_val=\${$svc_var}
8869988Sbsd	eval dep_val=\${$dep_var}
8969988Sbsd
9069988Sbsd	case ${svc_val} in
9169876Sobrien	[Yy][Ee][Ss])
9269988Sbsd		case ${dep_val} in
9369949Sbsd		[Yy][Ee][Ss])
9469988Sbsd		    ;;
9569949Sbsd		*)
9669988Sbsd		    eval ${dep_var}="YES"
9769988Sbsd		    echo "DEPENDENCY NOTE: ${dep} will be enabled" \
9869988Sbsd			 "to support ${svc}"
9969988Sbsd		    ;;
10069949Sbsd		esac
10169876Sobrien		;;
10269876Sobrien	esac
10369988Sbsd}
10467179Sjwd
10569988Sbsdchkdepend amd amd_enable        portmap portmap_enable
10669988Sbsdchkdepend NFS nfs_server_enable portmap portmap_enable
10770916Sbsdchkdepend NIS nis_server_enable portmap portmap_enable
10870916Sbsdchkdepend NIS nis_client_enable portmap portmap_enable
10969876Sobrien
11073277Sdougb# Enable harvesting of entropy via devices.  The sooner this happens the
11173277Sdougb# better so that we can take advantage of the boot process.
11273277Sdougb#
11373277Sdougbecho -n 'Entropy harvesting:'
11473277Sdougb
11573277Sdougbcase ${harvest_interrupt} in
11673277Sdougb[Nn][Oo])
11773277Sdougb	;;
11873277Sdougb*)
11973277Sdougb	if [ -w /dev/random ]; then
12087646Sru		/sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null
12173277Sdougb		echo -n ' interrupts'
12273277Sdougb	fi
12373277Sdougb	;;
12473277Sdougbesac
12573277Sdougb
12673277Sdougbcase ${harvest_ethernet} in
12773277Sdougb[Nn][Oo])
12873277Sdougb	;;
12973277Sdougb*)
13074063Sdougb	if [ -w /dev/random ]; then
13187646Sru		/sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null
13273277Sdougb		echo -n ' ethernet'
13373277Sdougb	fi
13473277Sdougb	;;
13573277Sdougbesac
13673277Sdougb
13773277Sdougbcase ${harvest_p_to_p} in
13873277Sdougb[Nn][Oo])
13973277Sdougb	;;
14073277Sdougb*)
14174063Sdougb	if [ -w /dev/random ]; then
14287646Sru	/sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null
14373277Sdougb		echo -n ' point_to_point'
14473277Sdougb	fi
14573277Sdougb	;;
14673277Sdougbesac
14773277Sdougb
14873277Sdougbecho '.'
14973277Sdougb
15071014Sdougb# First pass at reseeding /dev/random.
15167113Smarkm#
15267113Smarkmcase ${entropy_file} in
15367113Smarkm[Nn][Oo] | '')
15467113Smarkm	;;
15567113Smarkm*)
15667113Smarkm	if [ -w /dev/random ]; then
15770922Sdougb		feed_dev_random "${entropy_file}"
15870922Sdougb	fi
15970922Sdougb	;;
16070922Sdougbesac
16170922Sdougb
16274063Sdougb# XXX temporary until we can get the entropy
16374063Sdougb# harvesting rate up
16474063Sdougb# Entropy below is not great,
16574063Sdougb# but better than nothing.
16674063Sdougb( ps -efauxww; sysctl -a; date; df -ib; dmesg; ps -efauxww; ) \
16774063Sdougb    | dd of=/dev/random bs=8k 2>/dev/null
16874063Sdougbcat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
16974063Sdougb
17015568Sasami# Configure ccd devices.
17151231Ssheldonh#
17251231Ssheldonhif [ -r /etc/ccd.conf ]; then
17315568Sasami	ccdconfig -C
17415568Sasamifi
17515568Sasami
17651231Ssheldonhcase ${start_vinum} in
17751231Ssheldonh[Yy][Ee][Ss])
17845239Sgrog	vinum start
17951231Ssheldonh	;;
18051231Ssheldonhesac
18142741Sgrog
18243803Sdillonswapon -a
1833843Sdg
18483957Sphk# Last chance to do things before potentially waiting for
18583957Sphk# operator to do fsck related tasks
18683957Sphkif [ -r /etc/rc.early ]; then
18783957Sphk	. /etc/rc.early
18883957Sphkfi
18983957Sphk
19068985Sdougbcase ${bootmode} in
19151231Ssheldonhautoboot)
19270109Sdougb	echo 'Automatic boot in progress...'
19376946Sdd	case ${background_fsck} in
19476946Sdd	[Yy][Ee][Ss])
19576946Sdd		fsck -F -p
19676946Sdd		;;
19776946Sdd	*)
19876946Sdd		fsck -p
19976946Sdd		;;
20076946Sdd	esac
20137Srgrimes	case $? in
20237Srgrimes	0)
20337Srgrimes		;;
20437Srgrimes	2)
20537Srgrimes		exit 1
20637Srgrimes		;;
20737Srgrimes	4)
20837Srgrimes		reboot
20970109Sdougb		echo 'Reboot failed... help!'
21037Srgrimes		exit 1
21137Srgrimes		;;
21237Srgrimes	8)
21372031Sdougb		case ${fsck_y_enable} in
21472031Sdougb		[Yy][Ee][Ss])
21572031Sdougb			echo 'File system preen failed, trying fsck -y . . .'
21672031Sdougb			fsck -y
21772031Sdougb			case $? in
21872031Sdougb			0)
21972031Sdougb				;;
22072031Sdougb			*)
22172031Sdougb			echo 'Automatic file system check failed . . . help!'
22272031Sdougb				exit 1
22372031Sdougb				;;
22472031Sdougb			esac
22572031Sdougb			;;
22672031Sdougb		*)
22772031Sdougb			echo 'Automatic file system check failed . . . help!'
22872031Sdougb			exit 1
22972031Sdougb			;;
23072031Sdougb		esac
23137Srgrimes		;;
23237Srgrimes	12)
23370109Sdougb		echo 'Reboot interrupted'
23437Srgrimes		exit 1
23537Srgrimes		;;
23637Srgrimes	130)
23737Srgrimes		# interrupt before catcher installed
23837Srgrimes		exit 1
23937Srgrimes		;;
24037Srgrimes	*)
24170109Sdougb		echo 'Unknown error in reboot'
24237Srgrimes		exit 1
24337Srgrimes		;;
24437Srgrimes	esac
24551231Ssheldonh	;;
24651231Ssheldonh*)
24770109Sdougb	echo 'Skipping disk checks ...'
24851231Ssheldonh	;;
24951231Ssheldonhesac
25037Srgrimes
25145222Scracauerset -T
25237Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
25337Srgrimes
25443197Sdillon# root normally must be read/write, but if this is a BOOTP NFS
25543197Sdillon# diskless boot it does not have to be.
25643197Sdillon#
25751231Ssheldonhcase ${root_rw_mount} in
25851231Ssheldonh[Nn][Oo] | '')
25951231Ssheldonh	;;
26051231Ssheldonh*)
26151231Ssheldonh	if ! mount -u -o rw / ; then
26270109Sdougb		echo 'Mounting root filesystem rw failed, startup aborted'
26351231Ssheldonh		exit 1
26451231Ssheldonh	fi
26551231Ssheldonh	;;
26651231Ssheldonhesac
2671692Sphk
26843803Sdillonumount -a >/dev/null 2>&1
26943197Sdillon
27077974Ssheldonh# Mount everything except nfs filesystems.
27188531Ssheldonhif [ -z "${networkfs_types}" ]; then
27288531Ssheldonh	networkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL'
27388531Ssheldonhfi
27488531Ssheldonhmount_excludes='no'
27588531Ssheldonhfor i in ${networkfs_types}; do
27688531Ssheldonh	fstype=${i%:*}
27788531Ssheldonh	mount_excludes="${mount_excludes}${fstype},"
27888531Ssheldonhdone
27988531Ssheldonhmount_excludes=${mount_excludes%,}
28088531Ssheldonhmount -a -t ${mount_excludes}
28151231Ssheldonh
28251231Ssheldonhcase $? in
28351231Ssheldonh0)
28451231Ssheldonh	;;
28551231Ssheldonh*)
28670109Sdougb	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
28743803Sdillon	exit 1
28851231Ssheldonh	;;
28951231Ssheldonhesac
29037Srgrimes
29143197Sdillon# Run custom disk mounting function here
29243197Sdillon#
29351231Ssheldonhif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
29450357Ssheldonh		sh ${diskless_mount}
29543197Sdillonfi
29643197Sdillon
29771014Sdougb# Reseed /dev/random with previously stored entropy.
29871014Sdougbcase ${entropy_dir} in
29971014Sdougb[Nn][Oo])
30067179Sjwd	;;
30167179Sjwd*)
30271014Sdougb	entropy_dir=${entropy_dir:-/var/db/entropy}
30371014Sdougb	if [ -d "${entropy_dir}" ]; then
30467179Sjwd		if [ -w /dev/random ]; then
30571014Sdougb			for seedfile in ${entropy_dir}/*; do
30671014Sdougb				feed_dev_random "${seedfile}"
30771014Sdougb			done
30867179Sjwd		fi
30971014Sdougb	fi
31067179Sjwd	;;
31167179Sjwdesac
31267179Sjwd
31371014Sdougbcase ${entropy_file} in
31471014Sdougb[Nn][Oo] | '')
31571014Sdougb	;;
31671014Sdougb*)
31771014Sdougb	if [ -w /dev/random ]; then
31871014Sdougb		feed_dev_random "${entropy_file}"
31971014Sdougb	fi
32071014Sdougb	;;
32171014Sdougbesac
32267179Sjwd
3234091Sacheadjkerntz -i
324872Sache
32564400Sbrianpurgedir() {
32664400Sbrian	local dir file
32764400Sbrian
32864400Sbrian	if [ $# -eq 0 ]; then
32964400Sbrian		purgedir .
33064400Sbrian	else
33164400Sbrian		for dir
33264400Sbrian		do
33364400Sbrian		(
33464449Sbrian			cd "$dir" && for file in .* *
33564400Sbrian			do
33664449Sbrian				[ ."$file" = .. -o ."$file" = ... ] && continue
33776430Sbrian				if [ -d "$file" -a ! -L "$file" ]
33876430Sbrian				then
33964449Sbrian					purgedir "$file"
34076430Sbrian				else
34176430Sbrian					rm -f -- "$file"
34276430Sbrian				fi
34364400Sbrian			done
34464400Sbrian		)
34564400Sbrian		done
34664400Sbrian	fi
34764400Sbrian}
34864400Sbrian
34938237Sbrianclean_var() {
35088199Sbrian	if [ -d /var/run -a ! -f /var/run/clean_var ]; then
35188199Sbrian		purgedir /var/run
35239384Sbrian		# Keep a copy of the boot messages around
35339384Sbrian		dmesg >/var/run/dmesg.boot
35439384Sbrian		# And an initial utmp file
35551231Ssheldonh		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
35639384Sbrian		>/var/run/clean_var
35739384Sbrian	fi
35888199Sbrian	if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
35988199Sbrian		purgedir /var/spool/lock
36088199Sbrian		>/var/spool/lock/clean_var
36188199Sbrian	fi
36288199Sbrian	rm -rf /var/spool/uucp/.Temp/*
36338237Sbrian}
36426450Sache
36588199Sbrian# network_pass1() *may* end up writing stuff to /var - we don't want to
36688199Sbrian# remove it immediately afterwards - *nor* do we want to fail to clean
36788199Sbrian# an NFS-mounted /var.
36888199Sbrianrm -f /var/run/clean_var /var/spool/lock/clean_var
36988199Sbrianclean_var
37021197Sphk
37117767Sjkh# Add additional swapfile, if configured.
37251231Ssheldonh#
37351231Ssheldonhcase ${swapfile} in
37451231Ssheldonh[Nn][Oo] | '')
37551231Ssheldonh	;;
37651231Ssheldonh*)
37775384Sru	if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
37870109Sdougb		echo "Adding ${swapfile} as additional swap"
37975384Sru		mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
38051231Ssheldonh	fi
38151231Ssheldonh	;;
38251231Ssheldonhesac
38317767Sjkh
38451231Ssheldonh# Set sysctl variables as early as we can
38551231Ssheldonh#
38651231Ssheldonhif [ -r /etc/rc.sysctl ]; then
38745096Simp	. /etc/rc.sysctl
38845096Simpfi
38945096Simp
39051231Ssheldonh# Configure serial devices
39151231Ssheldonh#
39251231Ssheldonhif [ -r /etc/rc.serial ]; then
3937293Sjkh	. /etc/rc.serial
3941675Sachefi
3951675Sache
39651231Ssheldonh# Start up PC-card configuration
39751231Ssheldonh#
39851231Ssheldonhif [ -r /etc/rc.pccard ]; then
39914624Snate	. /etc/rc.pccard
40014596Snatefi
40114596Snate
40251231Ssheldonh# Start up the initial network configuration.
40351231Ssheldonh#
40451231Ssheldonhif [ -r /etc/rc.network ]; then
40525184Sjkh	. /etc/rc.network	# We only need to do this once.
40625184Sjkh	network_pass1
4077460Sjkhfi
4087460Sjkh
40957398Sshincase ${ipv6_enable} in
41057398Sshin[Yy][Ee][Ss])
41157398Sshin	if [ -r /etc/rc.network6 ]; then
41257398Sshin		. /etc/rc.network6	# We only need to do this once also.
41357398Sshin		network6_pass1
41457398Sshin	fi
41557398Sshin	;;
41657398Sshinesac
41757398Sshin
41877974Ssheldonh# Mount NFS filesystems if present in /etc/fstab
41988531Ssheldonh#
42088531Ssheldonh# XXX When the vfsload() issues with nfsclient support and related sysctls
42188531Ssheldonh# have been resolved, this block can be removed, and the condition that
42288531Ssheldonh# skips nfs in the following block (for "other network filesystems") can
42388531Ssheldonh# be removed.
42477974Ssheldonhcase "`mount -d -a -t nfs 2> /dev/null`" in
42577974Ssheldonh*mount_nfs*)
42685136Sdougb	# Handle absent nfs client support
42785136Sdougb	nfsclient_in_kernel=0
42885136Sdougb	if sysctl vfs.nfs >/dev/null 2>&1; then
42985136Sdougb		nfsclient_in_kernel=1
43085136Sdougb	else
43185136Sdougb		kldload nfsclient && nfsclient_in_kernel=1
43285136Sdougb	fi
43385136Sdougb
43485136Sdougb	case ${nfsclient_in_kernel} in
43585136Sdougb	1)
43685136Sdougb		echo -n 'Mounting NFS file systems:'
43785136Sdougb		mount -a -t nfs
43885136Sdougb		echo '.'
43985136Sdougb		;;
44085136Sdougb	*)
44185136Sdougb		echo 'Warning: nfs mount requested, but no nfs client in kernel'
44285136Sdougb		;;
44385136Sdougb	esac
44477974Ssheldonh	;;
44577974Ssheldonhesac
4467487Srgrimes
44788531Ssheldonh# Mount other network filesystems if present in /etc/fstab
44888531Ssheldonhfor i in ${networkfs_types}; do
44988531Ssheldonh	fstype=${i%:*}
45088531Ssheldonh	fsdecr=${i#*:}
45188531Ssheldonh
45288531Ssheldonh	if [ "${fstype}" = "nfs" ]; then
45388531Ssheldonh		continue
45488531Ssheldonh	fi
45588531Ssheldonh	case "`mount -d -a -t ${fstype}`" in
45688531Ssheldonh	*mount_${fstype}*)
45788531Ssheldonh	       echo -n "Mounting ${fsdecr} file systems:"
45888531Ssheldonh	       mount -a -t ${fstype}
45988531Ssheldonh	       echo '.'
46088531Ssheldonh	       ;;
46188531Ssheldonh	esac
46288531Ssheldonhdone
46388531Ssheldonh
4647487Srgrimes# Whack the pty perms back into shape.
46551231Ssheldonh#
46664893Ssheldonhif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
46764893Ssheldonh	chflags 0 /dev/tty[pqrsPQRS]*
46864893Ssheldonh	chmod 666 /dev/tty[pqrsPQRS]*
46964893Ssheldonh	chown root:wheel /dev/tty[pqrsPQRS]*
47064893Ssheldonhfi
4717487Srgrimes
47251231Ssheldonh# Clean up left-over files
47351231Ssheldonh#
47438237Sbrianclean_var			# If it hasn't already been done
47588199Sbrianrm /var/run/clean_var /var/spool/lock/clean_var
47638237Sbrian
47731192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
47831192Ssteve# help in any way for long-living systems, and it might accidentally
47931192Ssteve# clobber files you would rather like to have preserved after a crash
48031192Ssteve# (if not using mfs /tmp anyway).
48131192Ssteve#
48231192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
48331192Ssteve#
48451231Ssheldonhcase ${clear_tmp_enable} in
48551231Ssheldonh[Yy][Ee][Ss])
48670109Sdougb	echo -n 'Clearing /tmp:'
48731192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
48831192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
48931192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
49051231Ssheldonh		find -d . ! -name . ! -name lost+found ! -name quota.user \
49151231Ssheldonh		! -name quota.group -exec rm -rf -- {} \;)
49270109Sdougb	echo '.'
49351231Ssheldonh	;;
49451231Ssheldonhesac
49531192Ssteve
49651231Ssheldonh# Remove X lock files, since they will prevent you from restarting X11
49738915Scracauer# after a system crash.
49851231Ssheldonh#
49938915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
50038915Scracauer
50151231Ssheldonh# Snapshot any kernel -c changes back to disk here <someday>.
50251231Ssheldonh# This has changed with ELF and /kernel.config.
5037487Srgrimes
50470109Sdougbecho -n 'Additional daemons:'
50551231Ssheldonh
50651231Ssheldonh# Start system logging and name service.  Named needs to start before syslogd
50751231Ssheldonh# if you don't have a /etc/resolv.conf.
5087259Sjkh#
50951231Ssheldonhcase ${syslogd_enable} in
51051231Ssheldonh[Yy][Ee][Ss])
51124463Spst	# Transitional symlink (for the next couple of years :) until all
51251231Ssheldonh	# binaries have had a chance to move towards /var/run/log.
51375525Sphk	if [ ! -L /dev/log ]; then
51424463Spst		# might complain for r/o root f/s
51524463Spst		ln -sf /var/run/log /dev/log
51624463Spst	fi
51724463Spst
51824463Spst	rm -f /var/run/log
51978905Sdd	echo -n ' syslogd';
52078905Sdd	${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
52151231Ssheldonh	;;
52251231Ssheldonhesac
52351231Ssheldonh
52425339Sjkhecho '.'
52525339Sjkh
52667445Sphk# Build device name databases if we are not using DEVFS
52767040Sache#
52867445Sphkif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
52970109Sdougb	rm -f /var/run/dev.db
53067445Sphkelse
53167445Sphk	dev_mkdb
53267445Sphkfi
53367040Sache
53451231Ssheldonh# Enable dumpdev so that savecore can see it.
53532340Sjoerg# /var/crash should be a directory or a symbolic link
53632340Sjoerg# to the crash directory if core dumps are to be saved.
53751231Ssheldonh#
53851231Ssheldonhcase ${dumpdev} in
53951231Ssheldonh[Nn][Oo] | '')
54051231Ssheldonh	;;
54151231Ssheldonh*)
54284744Sdougb	case ${dumpdir} in
54384744Sdougb	'')
54484744Sdougb		dumpdir='/var/crash'
54584744Sdougb		;;
54684744Sdougb	esac
54784744Sdougb
54884730Sdes	if [ -e "${dumpdev}" -a -d "${dumpdir}" ]; then
54974140Sdougb		/sbin/dumpon -v ${dumpdev}
55070109Sdougb		echo -n 'Checking for core dump: '
55184730Sdes		/sbin/savecore ${savecore_flags} "${dumpdir}"
55251231Ssheldonh	fi
55351231Ssheldonh	;;
55451231Ssheldonhesac
55532340Sjoerg
55650357Ssheldonhif [ -n "${network_pass1_done}" ]; then
55739384Sbrian	network_pass2
558857Sdgfi
55937Srgrimes
56044818Sbillf# Enable/Check the quotas (must be after ypbind if using NIS)
56151231Ssheldonh#
56251231Ssheldonhcase ${enable_quotas} in
56351231Ssheldonh[Yy][Ee][Ss])
56451231Ssheldonh	case ${check_quotas} in
56551231Ssheldonh	[Yy][Ee][Ss])
56670109Sdougb		echo -n 'Checking quotas:'
56751231Ssheldonh		quotacheck -a
56851231Ssheldonh		echo ' done.'
56951231Ssheldonh		;;
57051231Ssheldonh	esac
57144818Sbillf
57270109Sdougb	echo -n 'Enabling quotas:'
57351231Ssheldonh	quotaon -a
57451231Ssheldonh	echo ' done.'
57551231Ssheldonh	;;
57651231Ssheldonhesac
57744818Sbillf
57850357Ssheldonhif [ -n "${network_pass2_done}" ]; then
57939384Sbrian	network_pass3
5807477Sachefi
5817477Sache
58251231Ssheldonh# Check the password temp/lock file
58351231Ssheldonh#
58451231Ssheldonhif [ -e /etc/ptmp ]; then
5857487Srgrimes	logger -s -p auth.err \
5867487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
5877238Sachefi
5887238Sache
58951231Ssheldonhcase ${accounting_enable} in
59051231Ssheldonh[Yy][Ee][Ss])
59151231Ssheldonh	if [ -d /var/account ]; then
59270109Sdougb		echo 'Turning on accounting:'
59351231Ssheldonh		if [ ! -e /var/account/acct ]; then
59451231Ssheldonh			touch /var/account/acct
59551231Ssheldonh		fi
59651231Ssheldonh		accton /var/account/acct
59711992Sache	fi
59851231Ssheldonh	;;
59951231Ssheldonhesac
6007238Sache
60127365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
60227365Sjkh# add your own entries or you may come to grief.
60351231Ssheldonh#
60464520Sjdpldconfig="/sbin/ldconfig"
60564520Sjdpcase ${ldconfig_insecure} in
60664520Sjdp[Yy][Ee][Ss])
60764520Sjdp	ldconfig="${ldconfig} -i"
60864520Sjdp	;;
60964520Sjdpesac
61038512Sgpalmerif [ -x /sbin/ldconfig ]; then
61151231Ssheldonh	case `/usr/bin/objformat` in
61251231Ssheldonh	elf)
61339329Sjdp		_LDC=/usr/lib
61450357Ssheldonh		for i in ${ldconfig_paths}; do
61551231Ssheldonh			if [ -d "${i}" ]; then
61650357Ssheldonh				_LDC="${_LDC} ${i}"
61739329Sjdp			fi
61839329Sjdp		done
61970109Sdougb		echo 'ELF ldconfig path:' ${_LDC}
62064520Sjdp		${ldconfig} -elf ${_LDC}
62151231Ssheldonh		;;
62251231Ssheldonh	esac
62339329Sjdp
62441648Sjb	# Legacy aout support for i386 only
62551231Ssheldonh	case `sysctl -n hw.machine` in
62651231Ssheldonh	i386)
62743951Sjkh		# Default the a.out ldconfig path.
62841648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
62941648Sjb		_LDC=/usr/lib/aout
63050357Ssheldonh		for i in ${ldconfig_paths_aout}; do
63151231Ssheldonh			if [ -d "${i}" ]; then
63250357Ssheldonh				_LDC="${_LDC} ${i}"
63341648Sjb			fi
63441648Sjb		done
63570109Sdougb		echo 'a.out ldconfig path:' ${_LDC}
63664520Sjdp		${ldconfig} -aout ${_LDC}
63751231Ssheldonh		;;
63851231Ssheldonh	esac
63938512Sgpalmerfi
6407296Sjkh
64117210Spst# Now start up miscellaneous daemons that don't belong anywhere else
64217210Spst#
64370109Sdougbecho -n 'Starting standard daemons:'
64451231Ssheldonhcase ${inetd_enable} in
64551231Ssheldonh[Nn][Oo])
64651231Ssheldonh	;;
64751231Ssheldonh*)
64878905Sdd	echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
64951231Ssheldonh	;;
65051231Ssheldonhesac
65117210Spst
65251231Ssheldonhcase ${cron_enable} in
65351231Ssheldonh[Nn][Oo])
65451231Ssheldonh	;;
65551231Ssheldonh*)
65671340Sdougb	echo -n ' cron';	${cron_program:-/usr/sbin/cron} ${cron_flags}
65751231Ssheldonh	;;
65851231Ssheldonhesac
65926727Spst
66051231Ssheldonhcase ${lpd_enable} in
66151231Ssheldonh[Yy][Ee][Ss])
66251231Ssheldonh	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
66351231Ssheldonh	;;
66451231Ssheldonhesac
66517210Spst
66657572Smarkmcase ${sshd_enable} in
66757572Smarkm[Yy][Ee][Ss])
66857572Smarkm	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
66957572Smarkm		echo -n ' sshd';
67057572Smarkm		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
67157572Smarkm	fi
67257572Smarkm	;;
67357572Smarkmesac
67457572Smarkm
67551231Ssheldonhcase ${usbd_enable} in
67651231Ssheldonh[Yy][Ee][Ss])
67742498Sn_hibma	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
67851231Ssheldonh	;;
67951231Ssheldonhesac
68042498Sn_hibma
68174198Speterif [ -r /etc/mail/sendmail.cf ]; then
68274198Speter	case ${sendmail_enable} in
68374198Speter	[Yy][Ee][Ss])
68474198Speter		echo -n ' sendmail'
68574198Speter		/usr/sbin/sendmail ${sendmail_flags}
68674198Speter		;;
68774198Speter	*)
68874198Speter		case ${sendmail_outbound_enable} in
68974198Speter		[Yy][Ee][Ss])
69074198Speter			echo -n ' sendmail'
69174198Speter			/usr/sbin/sendmail ${sendmail_outbound_flags}
69274198Speter			;;
69374198Speter		esac
69474198Speter		;;
69574198Speter	esac
69674198Speterfi
69774198Speter
69817161Spstecho '.'
69917161Spst
70016671Spst# Recover vi editor files.
70150612Simpfind /var/tmp/vi.recover ! -type f -a ! -type d -delete
70219314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
70350357Ssheldonhif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
70470109Sdougb	echo -n 'Recovering vi editor sessions:'
70555511Speter	for i in /var/tmp/vi.recover/vi.*; do
70619314Speter		# Only test files that are readable.
70751231Ssheldonh		if [ ! -r "${i}" ]; then
70819314Speter			continue
70919314Speter		fi
71019314Speter
71119314Speter		# Unmodified nvi editor backup files either have the
71219314Speter		# execute bit set or are zero length.  Delete them.
71351231Ssheldonh		if [ -x "${i}" -o ! -s "${i}" ]; then
71455451Speter			rm -f "${i}"
71519314Speter		fi
71616671Spst	done
71719314Speter
71819314Speter	# It is possible to get incomplete recovery files, if the editor
71919314Speter	# crashes at the right time.
72019314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
72150357Ssheldonh	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
72255511Speter		for i in /var/tmp/vi.recover/recover.*; do
72319314Speter			# Only test files that are readable.
72451231Ssheldonh			if [ ! -r "${i}" ]; then
72519314Speter				continue
72619314Speter			fi
72719314Speter
72819314Speter			# Delete any recovery files that are zero length,
72919314Speter			# corrupted, or that have no corresponding backup file.
73019314Speter			# Else send mail to the user.
73155453Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
73251231Ssheldonh			if [ -n "${recfile}" -a -s "${recfile}" ]; then
73355451Speter				sendmail -t < "${i}"
73419314Speter			else
73555451Speter				rm -f "${i}"
73619314Speter			fi
73719314Speter		done
73819314Speter	fi
73970109Sdougb	echo '.'
74016671Spstfi
74116671Spst
74251231Ssheldonh# Make a bounds file for msgs(1) if there isn't one already
74351231Ssheldonh#
74470109Sdougbif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
74537899Snectar	echo 0 > /var/msgs/bounds
74637899Snectarfi
74737899Snectar
74851231Ssheldonhcase ${update_motd} in
74951231Ssheldonh[Nn][Oo] | '')
75051231Ssheldonh	;;
75151231Ssheldonh*)
75251231Ssheldonh	if T=`mktemp /tmp/_motd.XXXXXX`; then
75350357Ssheldonh		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
75450357Ssheldonh		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
75550357Ssheldonh		cmp -s ${T} /etc/motd || {
75650357Ssheldonh			cp ${T} /etc/motd
75749451Speter			chmod 644 /etc/motd
75849451Speter		}
75950357Ssheldonh		rm -f ${T}
76049451Speter	fi
76151231Ssheldonh	;;
76251231Ssheldonhesac
76351231Ssheldonh
76483956Sobrien# Run rc.devfs if readable to customize devfs
76583956Sobrien#
76683956Sobrienif [ -r /etc/rc.devfs ]; then
76783956Sobrien	sh /etc/rc.devfs
76883956Sobrienfi
76983956Sobrien
77051617Snsayer# Configure implementation specific stuff
77151617Snsayer#
77251617Snsayerarch=`uname -m`
77351617Snsayerif [ -r /etc/rc.${arch} ]; then
77451617Snsayer	. /etc/rc.${arch}
77551617Snsayerfi
77651617Snsayer
77770856Sjhb# Configure the system console
77870856Sjhb#
77970856Sjhbif [ -r /etc/rc.syscons ]; then
78070856Sjhb	. /etc/rc.syscons
78170856Sjhbfi
78270856Sjhb
78370109Sdougbecho -n 'Additional ABI support:'
78464684Sobrien
78571121Sdes# Load the SysV IPC API if requested.
78671121Sdescase ${sysvipc_enable} in
78771121Sdes[Yy][Ee][Ss])
78871121Sdes	echo -n ' sysvipc'
78971121Sdes	kldload sysvmsg >/dev/null 2>&1
79071121Sdes	kldload sysvsem >/dev/null 2>&1
79171121Sdes	kldload sysvshm >/dev/null 2>&1
79271121Sdes	;;
79371121Sdesesac
79471121Sdes
79564684Sobrien# Start the Linux binary compatibility if requested.
79664684Sobrien#
79764684Sobriencase ${linux_enable} in
79864684Sobrien[Yy][Ee][Ss])
79964809Ssheldonh	echo -n ' linux'
80064809Ssheldonh	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
80164809Ssheldonh		kldload linux > /dev/null 2>&1
80264809Ssheldonh	fi
80364809Ssheldonh	if [ -x /compat/linux/sbin/ldconfig ]; then
80464809Ssheldonh		/compat/linux/sbin/ldconfig
80564809Ssheldonh	fi
80664684Sobrien	;;
80764684Sobrienesac
80864684Sobrien
80964684Sobrien# Start the SysVR4 binary emulation if requested.
81064684Sobrien#
81164684Sobriencase ${svr4_enable} in
81264684Sobrien[Yy][Ee][Ss])
81376553Speter	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
81464684Sobrien	;;
81564684Sobrienesac
81664684Sobrien
81770109Sdougbecho '.'
81864810Ssheldonh
81941704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
82043951Sjkh# use this file and want to make it programmatic, source /etc/defaults/rc.conf
82143951Sjkh# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
82243951Sjkh# shown below.  Please do not put local extensions into /etc/rc itself.
82341704Sdillon# Use /etc/rc.local
82441704Sdillon#
82551231Ssheldonh# ---- rc.local ----
82651231Ssheldonh#	if [ -r /etc/defaults/rc.conf ]; then
82751231Ssheldonh#		. /etc/defaults/rc.conf
82859674Ssheldonh#		source_rc_confs
82959674Ssheldonh#	elif [ -r /etc/rc.conf ]; then
83059674Ssheldonh#		. /etc/rc.conf
83151231Ssheldonh#	fi
83251231Ssheldonh#
83351231Ssheldonh#	... additional startup conditionals ...
83451231Ssheldonh# ---- rc.local ----
83551231Ssheldonh#
83651231Ssheldonhif [ -r /etc/rc.local ]; then
83770109Sdougb	echo -n 'Starting local daemons:'
83851231Ssheldonh	sh /etc/rc.local
83943197Sdillon	echo '.'
84041704Sdillonfi
84141704Sdillon
84251617Snsayer# For each valid dir in $local_startup, search for init scripts matching *.sh
84351617Snsayer#
84451617Snsayercase ${local_startup} in
84551617Snsayer[Nn][Oo] | '')
84651617Snsayer	;;
84751617Snsayer*)
84851617Snsayer	echo -n 'Local package initialization:'
84979825Sroam	slist=""
85087728Sroam	if [ -z "${script_name_sep}" ]; then
85187728Sroam		script_name_sep=" "
85287728Sroam	fi
85351617Snsayer	for dir in ${local_startup}; do
85451617Snsayer		if [ -d "${dir}" ]; then
85551617Snsayer			for script in ${dir}/*.sh; do
85679825Sroam				slist="${slist}${script_name_sep}${script}"
85751617Snsayer			done
85851617Snsayer		fi
85951617Snsayer	done
86079825Sroam	script_save_sep="$IFS"
86179825Sroam	IFS="${script_name_sep}"
86279825Sroam	for script in ${slist}; do
86379825Sroam		if [ -x "${script}" ]; then
86479825Sroam			(set -T
86579825Sroam			trap 'exit 1' 2
86683897Sobrien			${script} start)
86784370Sru		elif [ -f "${script}" -o -L "${script}" ]; then
86884332Sobrien			echo -n " (skipping ${script##*/}, not executable)"
86979825Sroam		fi
87079825Sroam	done
87179825Sroam	IFS="${script_save_sep}"
87270109Sdougb	echo '.'
87351617Snsayer	;;
87451617Snsayeresac
87551617Snsayer
87653314Sacheif [ -n "${network_pass3_done}" ]; then
87753314Sache	network_pass4
87853314Sachefi
87953314Sache
88037106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
88137106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
88251231Ssheldonh#
88351231Ssheldonhcase ${kern_securelevel_enable} in
88451231Ssheldonh[Yy][Ee][Ss])
88551231Ssheldonh	if [ "${kern_securelevel}" -ge 0 ]; then
88670109Sdougb		echo 'Raising kernel security level: '
88787646Sru		sysctl kern.securelevel=${kern_securelevel}
88851231Ssheldonh	fi
88951231Ssheldonh	;;
89051231Ssheldonhesac
89137106Sjkoshy
89276946Sdd# Start background fsck checks if necessary
89376946Sddcase ${background_fsck} in
89476946Sdd[Yy][Ee][Ss])
89576946Sdd	echo 'Starting background filesystem checks'
89676946Sdd	nice -4 fsck -B -p 2>&1 | logger -p daemon.notice &
89776946Sdd	;;
89876946Sddesac
89976460Smckusick
90070109Sdougbecho ''
90170109Sdougb
90237Srgrimesdate
90370109Sdougb
90437Srgrimesexit 0
90570109Sdougb
906