rc revision 76553
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#
2750472Speter# $FreeBSD: head/etc/rc 76553 2001-05-13 20:43:30Z peter $
28709Swollman#	From: @(#)rc	5.27 (Berkeley) 6/5/91
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
7671014Sdougb		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
12074075Smarkm		/sbin/sysctl -w 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
13174075Smarkm		/sbin/sysctl -w 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
14274075Smarkm	/sbin/sysctl -w 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
18468985Sdougbcase ${bootmode} in
18551231Ssheldonhautoboot)
18670109Sdougb	echo 'Automatic boot in progress...'
18776460Smckusick#	To restore old fsck behavior use:
18876460Smckusick#	fsck -p
18976460Smckusick	fsck -F -p
19037Srgrimes	case $? in
19137Srgrimes	0)
19237Srgrimes		;;
19337Srgrimes	2)
19437Srgrimes		exit 1
19537Srgrimes		;;
19637Srgrimes	4)
19737Srgrimes		reboot
19870109Sdougb		echo 'Reboot failed... help!'
19937Srgrimes		exit 1
20037Srgrimes		;;
20137Srgrimes	8)
20272031Sdougb		case ${fsck_y_enable} in
20372031Sdougb		[Yy][Ee][Ss])
20472031Sdougb			echo 'File system preen failed, trying fsck -y . . .'
20572031Sdougb			fsck -y
20672031Sdougb			case $? in
20772031Sdougb			0)
20872031Sdougb				;;
20972031Sdougb			*)
21072031Sdougb			echo 'Automatic file system check failed . . . help!'
21172031Sdougb				exit 1
21272031Sdougb				;;
21372031Sdougb			esac
21472031Sdougb			;;
21572031Sdougb		*)
21672031Sdougb			echo 'Automatic file system check failed . . . help!'
21772031Sdougb			exit 1
21872031Sdougb			;;
21972031Sdougb		esac
22037Srgrimes		;;
22137Srgrimes	12)
22270109Sdougb		echo 'Reboot interrupted'
22337Srgrimes		exit 1
22437Srgrimes		;;
22537Srgrimes	130)
22637Srgrimes		# interrupt before catcher installed
22737Srgrimes		exit 1
22837Srgrimes		;;
22937Srgrimes	*)
23070109Sdougb		echo 'Unknown error in reboot'
23137Srgrimes		exit 1
23237Srgrimes		;;
23337Srgrimes	esac
23451231Ssheldonh	;;
23551231Ssheldonh*)
23670109Sdougb	echo 'Skipping disk checks ...'
23751231Ssheldonh	;;
23851231Ssheldonhesac
23937Srgrimes
24045222Scracauerset -T
24137Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
24237Srgrimes
24343197Sdillon# root normally must be read/write, but if this is a BOOTP NFS
24443197Sdillon# diskless boot it does not have to be.
24543197Sdillon#
24651231Ssheldonhcase ${root_rw_mount} in
24751231Ssheldonh[Nn][Oo] | '')
24851231Ssheldonh	;;
24951231Ssheldonh*)
25051231Ssheldonh	if ! mount -u -o rw / ; then
25170109Sdougb		echo 'Mounting root filesystem rw failed, startup aborted'
25251231Ssheldonh		exit 1
25351231Ssheldonh	fi
25451231Ssheldonh	;;
25551231Ssheldonhesac
2561692Sphk
25743803Sdillonumount -a >/dev/null 2>&1
25843197Sdillon
25956038Sgreen# Mount everything except nfs filesystems.
26056038Sgreenmount -a -t nonfs
26151231Ssheldonh
26251231Ssheldonhcase $? in
26351231Ssheldonh0)
26451231Ssheldonh	;;
26551231Ssheldonh*)
26670109Sdougb	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
26743803Sdillon	exit 1
26851231Ssheldonh	;;
26951231Ssheldonhesac
27037Srgrimes
27143197Sdillon# Run custom disk mounting function here
27243197Sdillon#
27351231Ssheldonhif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
27450357Ssheldonh		sh ${diskless_mount}
27543197Sdillonfi
27643197Sdillon
27771014Sdougb# Reseed /dev/random with previously stored entropy.
27871014Sdougbcase ${entropy_dir} in
27971014Sdougb[Nn][Oo])
28067179Sjwd	;;
28167179Sjwd*)
28271014Sdougb	entropy_dir=${entropy_dir:-/var/db/entropy}
28371014Sdougb	if [ -d "${entropy_dir}" ]; then
28467179Sjwd		if [ -w /dev/random ]; then
28571014Sdougb			for seedfile in ${entropy_dir}/*; do
28671014Sdougb				feed_dev_random "${seedfile}"
28771014Sdougb			done
28867179Sjwd		fi
28971014Sdougb	fi
29067179Sjwd	;;
29167179Sjwdesac
29267179Sjwd
29371014Sdougbcase ${entropy_file} in
29471014Sdougb[Nn][Oo] | '')
29571014Sdougb	;;
29671014Sdougb*)
29771014Sdougb	if [ -w /dev/random ]; then
29871014Sdougb		feed_dev_random "${entropy_file}"
29971014Sdougb	fi
30071014Sdougb	;;
30171014Sdougbesac
30267179Sjwd
3034091Sacheadjkerntz -i
304872Sache
30564400Sbrianpurgedir() {
30664400Sbrian	local dir file
30764400Sbrian
30864400Sbrian	if [ $# -eq 0 ]; then
30964400Sbrian		purgedir .
31064400Sbrian	else
31164400Sbrian		for dir
31264400Sbrian		do
31364400Sbrian		(
31464449Sbrian			cd "$dir" && for file in .* *
31564400Sbrian			do
31664449Sbrian				[ ."$file" = .. -o ."$file" = ... ] && continue
31776430Sbrian				if [ -d "$file" -a ! -L "$file" ]
31876430Sbrian				then
31964449Sbrian					purgedir "$file"
32076430Sbrian				else
32176430Sbrian					rm -f -- "$file"
32276430Sbrian				fi
32364400Sbrian			done
32464400Sbrian		)
32564400Sbrian		done
32664400Sbrian	fi
32764400Sbrian}
32864400Sbrian
32938237Sbrianclean_var() {
33039384Sbrian	if [ ! -f /var/run/clean_var ]; then
33171830Sbrian		purgedir /var/run /var/spool/lock
33239384Sbrian		rm -rf /var/spool/uucp/.Temp/*
33339384Sbrian		# Keep a copy of the boot messages around
33439384Sbrian		dmesg >/var/run/dmesg.boot
33539384Sbrian		# And an initial utmp file
33651231Ssheldonh		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
33739384Sbrian		>/var/run/clean_var
33839384Sbrian	fi
33938237Sbrian}
34026450Sache
34138237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
34239384Sbrian	# network_pass1() *may* end up writing stuff to /var - we don't want to
34339384Sbrian	# remove it immediately afterwards - *nor* to we want to fail to clean
34439384Sbrian	# an nfs-mounted /var.
34539384Sbrian	clean_var
34638237Sbrianfi
34721197Sphk
34817767Sjkh# Add additional swapfile, if configured.
34951231Ssheldonh#
35051231Ssheldonhcase ${swapfile} in
35151231Ssheldonh[Nn][Oo] | '')
35251231Ssheldonh	;;
35351231Ssheldonh*)
35475384Sru	if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
35570109Sdougb		echo "Adding ${swapfile} as additional swap"
35675384Sru		mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
35751231Ssheldonh	fi
35851231Ssheldonh	;;
35951231Ssheldonhesac
36017767Sjkh
36151231Ssheldonh# Set sysctl variables as early as we can
36251231Ssheldonh#
36351231Ssheldonhif [ -r /etc/rc.sysctl ]; then
36445096Simp	. /etc/rc.sysctl
36545096Simpfi
36645096Simp
36751231Ssheldonh# Configure serial devices
36851231Ssheldonh#
36951231Ssheldonhif [ -r /etc/rc.serial ]; then
3707293Sjkh	. /etc/rc.serial
3711675Sachefi
3721675Sache
37351231Ssheldonh# Start up PC-card configuration
37451231Ssheldonh#
37551231Ssheldonhif [ -r /etc/rc.pccard ]; then
37614624Snate	. /etc/rc.pccard
37714596Snatefi
37814596Snate
37951231Ssheldonh# Start up the initial network configuration.
38051231Ssheldonh#
38151231Ssheldonhif [ -r /etc/rc.network ]; then
38225184Sjkh	. /etc/rc.network	# We only need to do this once.
38325184Sjkh	network_pass1
3847460Sjkhfi
3857460Sjkh
38657398Sshincase ${ipv6_enable} in
38757398Sshin[Yy][Ee][Ss])
38857398Sshin	if [ -r /etc/rc.network6 ]; then
38957398Sshin		. /etc/rc.network6	# We only need to do this once also.
39057398Sshin		network6_pass1
39157398Sshin	fi
39257398Sshin	;;
39357398Sshinesac
39457398Sshin
39558566Sdan# Mount NFS filesystems if present in /etc/fstab
39661065Sasmodaicase "`mount -d -a -t nfs`" in
39761065Sasmodai*mount_nfs*)
39870109Sdougb	echo -n 'Mounting NFS file systems:'
39958566Sdan	mount -a -t nfs
40070109Sdougb	echo '.'
40161065Sasmodai	;;
40261065Sasmodaiesac
4037487Srgrimes
4047487Srgrimes# Whack the pty perms back into shape.
40551231Ssheldonh#
40664893Ssheldonhif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
40764893Ssheldonh	chflags 0 /dev/tty[pqrsPQRS]*
40864893Ssheldonh	chmod 666 /dev/tty[pqrsPQRS]*
40964893Ssheldonh	chown root:wheel /dev/tty[pqrsPQRS]*
41064893Ssheldonhfi
4117487Srgrimes
41251231Ssheldonh# Clean up left-over files
41351231Ssheldonh#
41438237Sbrianclean_var			# If it hasn't already been done
41538237Sbrianrm /var/run/clean_var
41638237Sbrian
41731192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
41831192Ssteve# help in any way for long-living systems, and it might accidentally
41931192Ssteve# clobber files you would rather like to have preserved after a crash
42031192Ssteve# (if not using mfs /tmp anyway).
42131192Ssteve#
42231192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
42331192Ssteve#
42451231Ssheldonhcase ${clear_tmp_enable} in
42551231Ssheldonh[Yy][Ee][Ss])
42670109Sdougb	echo -n 'Clearing /tmp:'
42731192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
42831192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
42931192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
43051231Ssheldonh		find -d . ! -name . ! -name lost+found ! -name quota.user \
43151231Ssheldonh		! -name quota.group -exec rm -rf -- {} \;)
43270109Sdougb	echo '.'
43351231Ssheldonh	;;
43451231Ssheldonhesac
43531192Ssteve
43651231Ssheldonh# Remove X lock files, since they will prevent you from restarting X11
43738915Scracauer# after a system crash.
43851231Ssheldonh#
43938915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
44038915Scracauer
44151231Ssheldonh# Snapshot any kernel -c changes back to disk here <someday>.
44251231Ssheldonh# This has changed with ELF and /kernel.config.
4437487Srgrimes
44470109Sdougbecho -n 'Additional daemons:'
44551231Ssheldonh
44651231Ssheldonh# Start system logging and name service.  Named needs to start before syslogd
44751231Ssheldonh# if you don't have a /etc/resolv.conf.
4487259Sjkh#
44951231Ssheldonhcase ${syslogd_enable} in
45051231Ssheldonh[Yy][Ee][Ss])
45124463Spst	# Transitional symlink (for the next couple of years :) until all
45251231Ssheldonh	# binaries have had a chance to move towards /var/run/log.
45375525Sphk	if [ ! -L /dev/log ]; then
45424463Spst		# might complain for r/o root f/s
45524463Spst		ln -sf /var/run/log /dev/log
45624463Spst	fi
45724463Spst
45824463Spst	rm -f /var/run/log
45951231Ssheldonh	echo -n ' syslogd';	syslogd ${syslogd_flags}
46051231Ssheldonh	;;
46151231Ssheldonhesac
46251231Ssheldonh
46325339Sjkhecho '.'
46425339Sjkh
46567445Sphk# Build device name databases if we are not using DEVFS
46667040Sache#
46767445Sphkif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
46870109Sdougb	rm -f /var/run/dev.db
46967445Sphkelse
47067445Sphk	dev_mkdb
47167445Sphkfi
47267040Sache
47351231Ssheldonh# Enable dumpdev so that savecore can see it.
47432340Sjoerg# /var/crash should be a directory or a symbolic link
47532340Sjoerg# to the crash directory if core dumps are to be saved.
47651231Ssheldonh#
47751231Ssheldonhcase ${dumpdev} in
47851231Ssheldonh[Nn][Oo] | '')
47951231Ssheldonh	;;
48051231Ssheldonh*)
48151231Ssheldonh	if [ -e "${dumpdev}" -a -d /var/crash ]; then
48274140Sdougb		/sbin/dumpon -v ${dumpdev}
48370109Sdougb		echo -n 'Checking for core dump: '
48474140Sdougb		/sbin/savecore ${savecore_flags} /var/crash
48551231Ssheldonh	fi
48651231Ssheldonh	;;
48751231Ssheldonhesac
48832340Sjoerg
48950357Ssheldonhif [ -n "${network_pass1_done}" ]; then
49039384Sbrian	network_pass2
491857Sdgfi
49237Srgrimes
49344818Sbillf# Enable/Check the quotas (must be after ypbind if using NIS)
49451231Ssheldonh#
49551231Ssheldonhcase ${enable_quotas} in
49651231Ssheldonh[Yy][Ee][Ss])
49751231Ssheldonh	case ${check_quotas} in
49851231Ssheldonh	[Yy][Ee][Ss])
49970109Sdougb		echo -n 'Checking quotas:'
50051231Ssheldonh		quotacheck -a
50151231Ssheldonh		echo ' done.'
50251231Ssheldonh		;;
50351231Ssheldonh	esac
50444818Sbillf
50570109Sdougb	echo -n 'Enabling quotas:'
50651231Ssheldonh	quotaon -a
50751231Ssheldonh	echo ' done.'
50851231Ssheldonh	;;
50951231Ssheldonhesac
51044818Sbillf
51150357Ssheldonhif [ -n "${network_pass2_done}" ]; then
51239384Sbrian	network_pass3
5137477Sachefi
5147477Sache
51551231Ssheldonh# Check the password temp/lock file
51651231Ssheldonh#
51751231Ssheldonhif [ -e /etc/ptmp ]; then
5187487Srgrimes	logger -s -p auth.err \
5197487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
5207238Sachefi
5217238Sache
52251231Ssheldonhcase ${accounting_enable} in
52351231Ssheldonh[Yy][Ee][Ss])
52451231Ssheldonh	if [ -d /var/account ]; then
52570109Sdougb		echo 'Turning on accounting:'
52651231Ssheldonh		if [ ! -e /var/account/acct ]; then
52751231Ssheldonh			touch /var/account/acct
52851231Ssheldonh		fi
52951231Ssheldonh		accton /var/account/acct
53011992Sache	fi
53151231Ssheldonh	;;
53251231Ssheldonhesac
5337238Sache
53427365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
53527365Sjkh# add your own entries or you may come to grief.
53651231Ssheldonh#
53764520Sjdpldconfig="/sbin/ldconfig"
53864520Sjdpcase ${ldconfig_insecure} in
53964520Sjdp[Yy][Ee][Ss])
54064520Sjdp	ldconfig="${ldconfig} -i"
54164520Sjdp	;;
54264520Sjdpesac
54338512Sgpalmerif [ -x /sbin/ldconfig ]; then
54451231Ssheldonh	case `/usr/bin/objformat` in
54551231Ssheldonh	elf)
54639329Sjdp		_LDC=/usr/lib
54750357Ssheldonh		for i in ${ldconfig_paths}; do
54851231Ssheldonh			if [ -d "${i}" ]; then
54950357Ssheldonh				_LDC="${_LDC} ${i}"
55039329Sjdp			fi
55139329Sjdp		done
55270109Sdougb		echo 'ELF ldconfig path:' ${_LDC}
55364520Sjdp		${ldconfig} -elf ${_LDC}
55451231Ssheldonh		;;
55551231Ssheldonh	esac
55639329Sjdp
55741648Sjb	# Legacy aout support for i386 only
55851231Ssheldonh	case `sysctl -n hw.machine` in
55951231Ssheldonh	i386)
56043951Sjkh		# Default the a.out ldconfig path.
56141648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
56241648Sjb		_LDC=/usr/lib/aout
56350357Ssheldonh		for i in ${ldconfig_paths_aout}; do
56451231Ssheldonh			if [ -d "${i}" ]; then
56550357Ssheldonh				_LDC="${_LDC} ${i}"
56641648Sjb			fi
56741648Sjb		done
56870109Sdougb		echo 'a.out ldconfig path:' ${_LDC}
56964520Sjdp		${ldconfig} -aout ${_LDC}
57051231Ssheldonh		;;
57151231Ssheldonh	esac
57238512Sgpalmerfi
5737296Sjkh
57417210Spst# Now start up miscellaneous daemons that don't belong anywhere else
57517210Spst#
57670109Sdougbecho -n 'Starting standard daemons:'
57751231Ssheldonhcase ${inetd_enable} in
57851231Ssheldonh[Nn][Oo])
57951231Ssheldonh	;;
58051231Ssheldonh*)
58126727Spst	echo -n ' inetd';	inetd ${inetd_flags}
58251231Ssheldonh	;;
58351231Ssheldonhesac
58417210Spst
58551231Ssheldonhcase ${cron_enable} in
58651231Ssheldonh[Nn][Oo])
58751231Ssheldonh	;;
58851231Ssheldonh*)
58971340Sdougb	echo -n ' cron';	${cron_program:-/usr/sbin/cron} ${cron_flags}
59051231Ssheldonh	;;
59151231Ssheldonhesac
59226727Spst
59351231Ssheldonhcase ${lpd_enable} in
59451231Ssheldonh[Yy][Ee][Ss])
59551231Ssheldonh	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
59651231Ssheldonh	;;
59751231Ssheldonhesac
59817210Spst
59957572Smarkmcase ${sshd_enable} in
60057572Smarkm[Yy][Ee][Ss])
60157572Smarkm	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
60257572Smarkm		echo -n ' sshd';
60357572Smarkm		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
60457572Smarkm	fi
60557572Smarkm	;;
60657572Smarkmesac
60757572Smarkm
60851231Ssheldonhcase ${usbd_enable} in
60951231Ssheldonh[Yy][Ee][Ss])
61042498Sn_hibma	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
61151231Ssheldonh	;;
61251231Ssheldonhesac
61342498Sn_hibma
61474198Speterif [ -r /etc/mail/sendmail.cf ]; then
61574198Speter	case ${sendmail_enable} in
61674198Speter	[Yy][Ee][Ss])
61774198Speter		echo -n ' sendmail'
61874198Speter		/usr/sbin/sendmail ${sendmail_flags}
61974198Speter		;;
62074198Speter	*)
62174198Speter		case ${sendmail_outbound_enable} in
62274198Speter		[Yy][Ee][Ss])
62374198Speter			echo -n ' sendmail'
62474198Speter			/usr/sbin/sendmail ${sendmail_outbound_flags}
62574198Speter			;;
62674198Speter		esac
62774198Speter		;;
62874198Speter	esac
62974198Speterfi
63074198Speter
63117161Spstecho '.'
63217161Spst
63316671Spst# Recover vi editor files.
63450612Simpfind /var/tmp/vi.recover ! -type f -a ! -type d -delete
63519314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
63650357Ssheldonhif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
63770109Sdougb	echo -n 'Recovering vi editor sessions:'
63855511Speter	for i in /var/tmp/vi.recover/vi.*; do
63919314Speter		# Only test files that are readable.
64051231Ssheldonh		if [ ! -r "${i}" ]; then
64119314Speter			continue
64219314Speter		fi
64319314Speter
64419314Speter		# Unmodified nvi editor backup files either have the
64519314Speter		# execute bit set or are zero length.  Delete them.
64651231Ssheldonh		if [ -x "${i}" -o ! -s "${i}" ]; then
64755451Speter			rm -f "${i}"
64819314Speter		fi
64916671Spst	done
65019314Speter
65119314Speter	# It is possible to get incomplete recovery files, if the editor
65219314Speter	# crashes at the right time.
65319314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
65450357Ssheldonh	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
65555511Speter		for i in /var/tmp/vi.recover/recover.*; do
65619314Speter			# Only test files that are readable.
65751231Ssheldonh			if [ ! -r "${i}" ]; then
65819314Speter				continue
65919314Speter			fi
66019314Speter
66119314Speter			# Delete any recovery files that are zero length,
66219314Speter			# corrupted, or that have no corresponding backup file.
66319314Speter			# Else send mail to the user.
66455453Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
66551231Ssheldonh			if [ -n "${recfile}" -a -s "${recfile}" ]; then
66655451Speter				sendmail -t < "${i}"
66719314Speter			else
66855451Speter				rm -f "${i}"
66919314Speter			fi
67019314Speter		done
67119314Speter	fi
67270109Sdougb	echo '.'
67316671Spstfi
67416671Spst
67551231Ssheldonh# Make a bounds file for msgs(1) if there isn't one already
67651231Ssheldonh#
67770109Sdougbif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
67837899Snectar	echo 0 > /var/msgs/bounds
67937899Snectarfi
68037899Snectar
68151231Ssheldonhcase ${update_motd} in
68251231Ssheldonh[Nn][Oo] | '')
68351231Ssheldonh	;;
68451231Ssheldonh*)
68551231Ssheldonh	if T=`mktemp /tmp/_motd.XXXXXX`; then
68650357Ssheldonh		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
68750357Ssheldonh		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
68850357Ssheldonh		cmp -s ${T} /etc/motd || {
68950357Ssheldonh			cp ${T} /etc/motd
69049451Speter			chmod 644 /etc/motd
69149451Speter		}
69250357Ssheldonh		rm -f ${T}
69349451Speter	fi
69451231Ssheldonh	;;
69551231Ssheldonhesac
69651231Ssheldonh
69751617Snsayer# Configure implementation specific stuff
69851617Snsayer#
69951617Snsayerarch=`uname -m`
70051617Snsayerif [ -r /etc/rc.${arch} ]; then
70151617Snsayer	. /etc/rc.${arch}
70251617Snsayerfi
70351617Snsayer
70470856Sjhb# Configure the system console
70570856Sjhb#
70670856Sjhbif [ -r /etc/rc.syscons ]; then
70770856Sjhb	. /etc/rc.syscons
70870856Sjhbfi
70970856Sjhb
71051231Ssheldonh# Run rc.devfs if readable to customize devfs
71151231Ssheldonh#
71251231Ssheldonhif [ -r /etc/rc.devfs ]; then
71351231Ssheldonh	sh /etc/rc.devfs
71441704Sdillonfi
71541704Sdillon
71670109Sdougbecho -n 'Additional ABI support:'
71764684Sobrien
71871121Sdes# Load the SysV IPC API if requested.
71971121Sdescase ${sysvipc_enable} in
72071121Sdes[Yy][Ee][Ss])
72171121Sdes	echo -n ' sysvipc'
72271121Sdes	kldload sysvmsg >/dev/null 2>&1
72371121Sdes	kldload sysvsem >/dev/null 2>&1
72471121Sdes	kldload sysvshm >/dev/null 2>&1
72571121Sdes	;;
72671121Sdesesac
72771121Sdes
72864684Sobrien# Start the Linux binary compatibility if requested.
72964684Sobrien#
73064684Sobriencase ${linux_enable} in
73164684Sobrien[Yy][Ee][Ss])
73264809Ssheldonh	echo -n ' linux'
73364809Ssheldonh	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
73464809Ssheldonh		kldload linux > /dev/null 2>&1
73564809Ssheldonh	fi
73664809Ssheldonh	if [ -x /compat/linux/sbin/ldconfig ]; then
73764809Ssheldonh		/compat/linux/sbin/ldconfig
73864809Ssheldonh	fi
73964684Sobrien	;;
74064684Sobrienesac
74164684Sobrien
74264684Sobrien# Start the SysVR4 binary emulation if requested.
74364684Sobrien#
74464684Sobriencase ${svr4_enable} in
74564684Sobrien[Yy][Ee][Ss])
74676553Speter	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
74764684Sobrien	;;
74864684Sobrienesac
74964684Sobrien
75070109Sdougbecho '.'
75164810Ssheldonh
75241704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
75343951Sjkh# use this file and want to make it programmatic, source /etc/defaults/rc.conf
75443951Sjkh# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
75543951Sjkh# shown below.  Please do not put local extensions into /etc/rc itself.
75641704Sdillon# Use /etc/rc.local
75741704Sdillon#
75851231Ssheldonh# ---- rc.local ----
75951231Ssheldonh#	if [ -r /etc/defaults/rc.conf ]; then
76051231Ssheldonh#		. /etc/defaults/rc.conf
76159674Ssheldonh#		source_rc_confs
76259674Ssheldonh#	elif [ -r /etc/rc.conf ]; then
76359674Ssheldonh#		. /etc/rc.conf
76451231Ssheldonh#	fi
76551231Ssheldonh#
76651231Ssheldonh#	... additional startup conditionals ...
76751231Ssheldonh# ---- rc.local ----
76851231Ssheldonh#
76951231Ssheldonhif [ -r /etc/rc.local ]; then
77070109Sdougb	echo -n 'Starting local daemons:'
77151231Ssheldonh	sh /etc/rc.local
77243197Sdillon	echo '.'
77341704Sdillonfi
77441704Sdillon
77551617Snsayer# For each valid dir in $local_startup, search for init scripts matching *.sh
77651617Snsayer#
77751617Snsayercase ${local_startup} in
77851617Snsayer[Nn][Oo] | '')
77951617Snsayer	;;
78051617Snsayer*)
78151617Snsayer	echo -n 'Local package initialization:'
78251617Snsayer	for dir in ${local_startup}; do
78351617Snsayer		if [ -d "${dir}" ]; then
78451617Snsayer			for script in ${dir}/*.sh; do
78551617Snsayer				if [ -x "${script}" ]; then
78651617Snsayer					(set -T
78751617Snsayer					 trap 'exit 1' 2
78851617Snsayer					 ${script} start)
78951617Snsayer				fi
79051617Snsayer			done
79151617Snsayer		fi
79251617Snsayer	done
79370109Sdougb	echo '.'
79451617Snsayer	;;
79551617Snsayeresac
79651617Snsayer
79753314Sacheif [ -n "${network_pass3_done}" ]; then
79853314Sache	network_pass4
79953314Sachefi
80053314Sache
80137106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
80237106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
80351231Ssheldonh#
80451231Ssheldonhcase ${kern_securelevel_enable} in
80551231Ssheldonh[Yy][Ee][Ss])
80651231Ssheldonh	if [ "${kern_securelevel}" -ge 0 ]; then
80770109Sdougb		echo 'Raising kernel security level: '
80851231Ssheldonh		sysctl -w kern.securelevel=${kern_securelevel}
80951231Ssheldonh	fi
81051231Ssheldonh	;;
81151231Ssheldonhesac
81237106Sjkoshy
81376460Smckusick# Start background fsck checks
81476460Smckusickecho 'Starting background filesystem checks'
81576460Smckusicknice -4 fsck -B -p 2>&1 | logger -p daemon.notice &
81676460Smckusick
81770109Sdougbecho ''
81870109Sdougb
81937Srgrimesdate
82070109Sdougb
82137Srgrimesexit 0
82270109Sdougb
823