rc revision 83871
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 83871 2001-09-24 03:03:51Z obrien $
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
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...'
18776946Sdd	case ${background_fsck} in
18876946Sdd	[Yy][Ee][Ss])
18976946Sdd		fsck -F -p
19076946Sdd		;;
19176946Sdd	*)
19276946Sdd		fsck -p
19376946Sdd		;;
19476946Sdd	esac
19537Srgrimes	case $? in
19637Srgrimes	0)
19737Srgrimes		;;
19837Srgrimes	2)
19937Srgrimes		exit 1
20037Srgrimes		;;
20137Srgrimes	4)
20237Srgrimes		reboot
20370109Sdougb		echo 'Reboot failed... help!'
20437Srgrimes		exit 1
20537Srgrimes		;;
20637Srgrimes	8)
20772031Sdougb		case ${fsck_y_enable} in
20872031Sdougb		[Yy][Ee][Ss])
20972031Sdougb			echo 'File system preen failed, trying fsck -y . . .'
21072031Sdougb			fsck -y
21172031Sdougb			case $? in
21272031Sdougb			0)
21372031Sdougb				;;
21472031Sdougb			*)
21572031Sdougb			echo 'Automatic file system check failed . . . help!'
21672031Sdougb				exit 1
21772031Sdougb				;;
21872031Sdougb			esac
21972031Sdougb			;;
22072031Sdougb		*)
22172031Sdougb			echo 'Automatic file system check failed . . . help!'
22272031Sdougb			exit 1
22372031Sdougb			;;
22472031Sdougb		esac
22537Srgrimes		;;
22637Srgrimes	12)
22770109Sdougb		echo 'Reboot interrupted'
22837Srgrimes		exit 1
22937Srgrimes		;;
23037Srgrimes	130)
23137Srgrimes		# interrupt before catcher installed
23237Srgrimes		exit 1
23337Srgrimes		;;
23437Srgrimes	*)
23570109Sdougb		echo 'Unknown error in reboot'
23637Srgrimes		exit 1
23737Srgrimes		;;
23837Srgrimes	esac
23951231Ssheldonh	;;
24051231Ssheldonh*)
24170109Sdougb	echo 'Skipping disk checks ...'
24251231Ssheldonh	;;
24351231Ssheldonhesac
24437Srgrimes
24545222Scracauerset -T
24637Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
24737Srgrimes
24843197Sdillon# root normally must be read/write, but if this is a BOOTP NFS
24943197Sdillon# diskless boot it does not have to be.
25043197Sdillon#
25151231Ssheldonhcase ${root_rw_mount} in
25251231Ssheldonh[Nn][Oo] | '')
25351231Ssheldonh	;;
25451231Ssheldonh*)
25551231Ssheldonh	if ! mount -u -o rw / ; then
25670109Sdougb		echo 'Mounting root filesystem rw failed, startup aborted'
25751231Ssheldonh		exit 1
25851231Ssheldonh	fi
25951231Ssheldonh	;;
26051231Ssheldonhesac
2611692Sphk
26243803Sdillonumount -a >/dev/null 2>&1
26343197Sdillon
26477974Ssheldonh# Mount everything except nfs filesystems.
26577974Ssheldonhmount -a -t nonfs
26651231Ssheldonh
26751231Ssheldonhcase $? in
26851231Ssheldonh0)
26951231Ssheldonh	;;
27051231Ssheldonh*)
27170109Sdougb	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
27243803Sdillon	exit 1
27351231Ssheldonh	;;
27451231Ssheldonhesac
27537Srgrimes
27643197Sdillon# Run custom disk mounting function here
27743197Sdillon#
27851231Ssheldonhif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
27950357Ssheldonh		sh ${diskless_mount}
28043197Sdillonfi
28143197Sdillon
28271014Sdougb# Reseed /dev/random with previously stored entropy.
28371014Sdougbcase ${entropy_dir} in
28471014Sdougb[Nn][Oo])
28567179Sjwd	;;
28667179Sjwd*)
28771014Sdougb	entropy_dir=${entropy_dir:-/var/db/entropy}
28871014Sdougb	if [ -d "${entropy_dir}" ]; then
28967179Sjwd		if [ -w /dev/random ]; then
29071014Sdougb			for seedfile in ${entropy_dir}/*; do
29171014Sdougb				feed_dev_random "${seedfile}"
29271014Sdougb			done
29367179Sjwd		fi
29471014Sdougb	fi
29567179Sjwd	;;
29667179Sjwdesac
29767179Sjwd
29871014Sdougbcase ${entropy_file} in
29971014Sdougb[Nn][Oo] | '')
30071014Sdougb	;;
30171014Sdougb*)
30271014Sdougb	if [ -w /dev/random ]; then
30371014Sdougb		feed_dev_random "${entropy_file}"
30471014Sdougb	fi
30571014Sdougb	;;
30671014Sdougbesac
30767179Sjwd
3084091Sacheadjkerntz -i
309872Sache
31064400Sbrianpurgedir() {
31164400Sbrian	local dir file
31264400Sbrian
31364400Sbrian	if [ $# -eq 0 ]; then
31464400Sbrian		purgedir .
31564400Sbrian	else
31664400Sbrian		for dir
31764400Sbrian		do
31864400Sbrian		(
31964449Sbrian			cd "$dir" && for file in .* *
32064400Sbrian			do
32164449Sbrian				[ ."$file" = .. -o ."$file" = ... ] && continue
32276430Sbrian				if [ -d "$file" -a ! -L "$file" ]
32376430Sbrian				then
32464449Sbrian					purgedir "$file"
32576430Sbrian				else
32676430Sbrian					rm -f -- "$file"
32776430Sbrian				fi
32864400Sbrian			done
32964400Sbrian		)
33064400Sbrian		done
33164400Sbrian	fi
33264400Sbrian}
33364400Sbrian
33438237Sbrianclean_var() {
33539384Sbrian	if [ ! -f /var/run/clean_var ]; then
33671830Sbrian		purgedir /var/run /var/spool/lock
33739384Sbrian		rm -rf /var/spool/uucp/.Temp/*
33839384Sbrian		# Keep a copy of the boot messages around
33939384Sbrian		dmesg >/var/run/dmesg.boot
34039384Sbrian		# And an initial utmp file
34151231Ssheldonh		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
34239384Sbrian		>/var/run/clean_var
34339384Sbrian	fi
34438237Sbrian}
34526450Sache
34638237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
34739384Sbrian	# network_pass1() *may* end up writing stuff to /var - we don't want to
34839384Sbrian	# remove it immediately afterwards - *nor* to we want to fail to clean
34939384Sbrian	# an nfs-mounted /var.
35039384Sbrian	clean_var
35138237Sbrianfi
35221197Sphk
35317767Sjkh# Add additional swapfile, if configured.
35451231Ssheldonh#
35551231Ssheldonhcase ${swapfile} in
35651231Ssheldonh[Nn][Oo] | '')
35751231Ssheldonh	;;
35851231Ssheldonh*)
35975384Sru	if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
36070109Sdougb		echo "Adding ${swapfile} as additional swap"
36175384Sru		mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
36251231Ssheldonh	fi
36351231Ssheldonh	;;
36451231Ssheldonhesac
36517767Sjkh
36651231Ssheldonh# Set sysctl variables as early as we can
36751231Ssheldonh#
36851231Ssheldonhif [ -r /etc/rc.sysctl ]; then
36945096Simp	. /etc/rc.sysctl
37045096Simpfi
37145096Simp
37251231Ssheldonh# Configure serial devices
37351231Ssheldonh#
37451231Ssheldonhif [ -r /etc/rc.serial ]; then
3757293Sjkh	. /etc/rc.serial
3761675Sachefi
3771675Sache
37851231Ssheldonh# Start up PC-card configuration
37951231Ssheldonh#
38051231Ssheldonhif [ -r /etc/rc.pccard ]; then
38114624Snate	. /etc/rc.pccard
38214596Snatefi
38314596Snate
38451231Ssheldonh# Start up the initial network configuration.
38551231Ssheldonh#
38651231Ssheldonhif [ -r /etc/rc.network ]; then
38725184Sjkh	. /etc/rc.network	# We only need to do this once.
38825184Sjkh	network_pass1
3897460Sjkhfi
3907460Sjkh
39157398Sshincase ${ipv6_enable} in
39257398Sshin[Yy][Ee][Ss])
39357398Sshin	if [ -r /etc/rc.network6 ]; then
39457398Sshin		. /etc/rc.network6	# We only need to do this once also.
39557398Sshin		network6_pass1
39657398Sshin	fi
39757398Sshin	;;
39857398Sshinesac
39957398Sshin
40077974Ssheldonh# Mount NFS filesystems if present in /etc/fstab
40177974Ssheldonhcase "`mount -d -a -t nfs 2> /dev/null`" in
40277974Ssheldonh*mount_nfs*)
40377974Ssheldonh	echo -n 'Mounting NFS file systems:'
40477974Ssheldonh	mount -a -t nfs
40577974Ssheldonh	echo '.'
40677974Ssheldonh	;;
40777974Ssheldonhesac
4087487Srgrimes
4097487Srgrimes# Whack the pty perms back into shape.
41051231Ssheldonh#
41164893Ssheldonhif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
41264893Ssheldonh	chflags 0 /dev/tty[pqrsPQRS]*
41364893Ssheldonh	chmod 666 /dev/tty[pqrsPQRS]*
41464893Ssheldonh	chown root:wheel /dev/tty[pqrsPQRS]*
41564893Ssheldonhfi
4167487Srgrimes
41751231Ssheldonh# Clean up left-over files
41851231Ssheldonh#
41938237Sbrianclean_var			# If it hasn't already been done
42038237Sbrianrm /var/run/clean_var
42138237Sbrian
42231192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
42331192Ssteve# help in any way for long-living systems, and it might accidentally
42431192Ssteve# clobber files you would rather like to have preserved after a crash
42531192Ssteve# (if not using mfs /tmp anyway).
42631192Ssteve#
42731192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
42831192Ssteve#
42951231Ssheldonhcase ${clear_tmp_enable} in
43051231Ssheldonh[Yy][Ee][Ss])
43170109Sdougb	echo -n 'Clearing /tmp:'
43231192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
43331192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
43431192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
43551231Ssheldonh		find -d . ! -name . ! -name lost+found ! -name quota.user \
43651231Ssheldonh		! -name quota.group -exec rm -rf -- {} \;)
43770109Sdougb	echo '.'
43851231Ssheldonh	;;
43951231Ssheldonhesac
44031192Ssteve
44151231Ssheldonh# Remove X lock files, since they will prevent you from restarting X11
44238915Scracauer# after a system crash.
44351231Ssheldonh#
44438915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
44538915Scracauer
44651231Ssheldonh# Snapshot any kernel -c changes back to disk here <someday>.
44751231Ssheldonh# This has changed with ELF and /kernel.config.
4487487Srgrimes
44970109Sdougbecho -n 'Additional daemons:'
45051231Ssheldonh
45151231Ssheldonh# Start system logging and name service.  Named needs to start before syslogd
45251231Ssheldonh# if you don't have a /etc/resolv.conf.
4537259Sjkh#
45451231Ssheldonhcase ${syslogd_enable} in
45551231Ssheldonh[Yy][Ee][Ss])
45624463Spst	# Transitional symlink (for the next couple of years :) until all
45751231Ssheldonh	# binaries have had a chance to move towards /var/run/log.
45875525Sphk	if [ ! -L /dev/log ]; then
45924463Spst		# might complain for r/o root f/s
46024463Spst		ln -sf /var/run/log /dev/log
46124463Spst	fi
46224463Spst
46324463Spst	rm -f /var/run/log
46478905Sdd	echo -n ' syslogd';
46578905Sdd	${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
46651231Ssheldonh	;;
46751231Ssheldonhesac
46851231Ssheldonh
46925339Sjkhecho '.'
47025339Sjkh
47167445Sphk# Build device name databases if we are not using DEVFS
47267040Sache#
47367445Sphkif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
47470109Sdougb	rm -f /var/run/dev.db
47567445Sphkelse
47667445Sphk	dev_mkdb
47767445Sphkfi
47867040Sache
47951231Ssheldonh# Enable dumpdev so that savecore can see it.
48032340Sjoerg# /var/crash should be a directory or a symbolic link
48132340Sjoerg# to the crash directory if core dumps are to be saved.
48251231Ssheldonh#
48351231Ssheldonhcase ${dumpdev} in
48451231Ssheldonh[Nn][Oo] | '')
48551231Ssheldonh	;;
48651231Ssheldonh*)
48751231Ssheldonh	if [ -e "${dumpdev}" -a -d /var/crash ]; then
48874140Sdougb		/sbin/dumpon -v ${dumpdev}
48970109Sdougb		echo -n 'Checking for core dump: '
49074140Sdougb		/sbin/savecore ${savecore_flags} /var/crash
49151231Ssheldonh	fi
49251231Ssheldonh	;;
49351231Ssheldonhesac
49432340Sjoerg
49550357Ssheldonhif [ -n "${network_pass1_done}" ]; then
49639384Sbrian	network_pass2
497857Sdgfi
49837Srgrimes
49944818Sbillf# Enable/Check the quotas (must be after ypbind if using NIS)
50051231Ssheldonh#
50151231Ssheldonhcase ${enable_quotas} in
50251231Ssheldonh[Yy][Ee][Ss])
50351231Ssheldonh	case ${check_quotas} in
50451231Ssheldonh	[Yy][Ee][Ss])
50570109Sdougb		echo -n 'Checking quotas:'
50651231Ssheldonh		quotacheck -a
50751231Ssheldonh		echo ' done.'
50851231Ssheldonh		;;
50951231Ssheldonh	esac
51044818Sbillf
51170109Sdougb	echo -n 'Enabling quotas:'
51251231Ssheldonh	quotaon -a
51351231Ssheldonh	echo ' done.'
51451231Ssheldonh	;;
51551231Ssheldonhesac
51644818Sbillf
51750357Ssheldonhif [ -n "${network_pass2_done}" ]; then
51839384Sbrian	network_pass3
5197477Sachefi
5207477Sache
52151231Ssheldonh# Check the password temp/lock file
52251231Ssheldonh#
52351231Ssheldonhif [ -e /etc/ptmp ]; then
5247487Srgrimes	logger -s -p auth.err \
5257487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
5267238Sachefi
5277238Sache
52851231Ssheldonhcase ${accounting_enable} in
52951231Ssheldonh[Yy][Ee][Ss])
53051231Ssheldonh	if [ -d /var/account ]; then
53170109Sdougb		echo 'Turning on accounting:'
53251231Ssheldonh		if [ ! -e /var/account/acct ]; then
53351231Ssheldonh			touch /var/account/acct
53451231Ssheldonh		fi
53551231Ssheldonh		accton /var/account/acct
53611992Sache	fi
53751231Ssheldonh	;;
53851231Ssheldonhesac
5397238Sache
54027365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
54127365Sjkh# add your own entries or you may come to grief.
54251231Ssheldonh#
54364520Sjdpldconfig="/sbin/ldconfig"
54464520Sjdpcase ${ldconfig_insecure} in
54564520Sjdp[Yy][Ee][Ss])
54664520Sjdp	ldconfig="${ldconfig} -i"
54764520Sjdp	;;
54864520Sjdpesac
54938512Sgpalmerif [ -x /sbin/ldconfig ]; then
55051231Ssheldonh	case `/usr/bin/objformat` in
55151231Ssheldonh	elf)
55239329Sjdp		_LDC=/usr/lib
55350357Ssheldonh		for i in ${ldconfig_paths}; do
55451231Ssheldonh			if [ -d "${i}" ]; then
55550357Ssheldonh				_LDC="${_LDC} ${i}"
55639329Sjdp			fi
55739329Sjdp		done
55870109Sdougb		echo 'ELF ldconfig path:' ${_LDC}
55964520Sjdp		${ldconfig} -elf ${_LDC}
56051231Ssheldonh		;;
56151231Ssheldonh	esac
56239329Sjdp
56341648Sjb	# Legacy aout support for i386 only
56451231Ssheldonh	case `sysctl -n hw.machine` in
56551231Ssheldonh	i386)
56643951Sjkh		# Default the a.out ldconfig path.
56741648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
56841648Sjb		_LDC=/usr/lib/aout
56950357Ssheldonh		for i in ${ldconfig_paths_aout}; do
57051231Ssheldonh			if [ -d "${i}" ]; then
57150357Ssheldonh				_LDC="${_LDC} ${i}"
57241648Sjb			fi
57341648Sjb		done
57470109Sdougb		echo 'a.out ldconfig path:' ${_LDC}
57564520Sjdp		${ldconfig} -aout ${_LDC}
57651231Ssheldonh		;;
57751231Ssheldonh	esac
57838512Sgpalmerfi
5797296Sjkh
58017210Spst# Now start up miscellaneous daemons that don't belong anywhere else
58117210Spst#
58270109Sdougbecho -n 'Starting standard daemons:'
58351231Ssheldonhcase ${inetd_enable} in
58451231Ssheldonh[Nn][Oo])
58551231Ssheldonh	;;
58651231Ssheldonh*)
58778905Sdd	echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
58851231Ssheldonh	;;
58951231Ssheldonhesac
59017210Spst
59151231Ssheldonhcase ${cron_enable} in
59251231Ssheldonh[Nn][Oo])
59351231Ssheldonh	;;
59451231Ssheldonh*)
59571340Sdougb	echo -n ' cron';	${cron_program:-/usr/sbin/cron} ${cron_flags}
59651231Ssheldonh	;;
59751231Ssheldonhesac
59826727Spst
59951231Ssheldonhcase ${lpd_enable} in
60051231Ssheldonh[Yy][Ee][Ss])
60151231Ssheldonh	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
60251231Ssheldonh	;;
60351231Ssheldonhesac
60417210Spst
60557572Smarkmcase ${sshd_enable} in
60657572Smarkm[Yy][Ee][Ss])
60757572Smarkm	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
60857572Smarkm		echo -n ' sshd';
60957572Smarkm		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
61057572Smarkm	fi
61157572Smarkm	;;
61257572Smarkmesac
61357572Smarkm
61451231Ssheldonhcase ${usbd_enable} in
61551231Ssheldonh[Yy][Ee][Ss])
61642498Sn_hibma	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
61751231Ssheldonh	;;
61851231Ssheldonhesac
61942498Sn_hibma
62074198Speterif [ -r /etc/mail/sendmail.cf ]; then
62174198Speter	case ${sendmail_enable} in
62274198Speter	[Yy][Ee][Ss])
62374198Speter		echo -n ' sendmail'
62474198Speter		/usr/sbin/sendmail ${sendmail_flags}
62574198Speter		;;
62674198Speter	*)
62774198Speter		case ${sendmail_outbound_enable} in
62874198Speter		[Yy][Ee][Ss])
62974198Speter			echo -n ' sendmail'
63074198Speter			/usr/sbin/sendmail ${sendmail_outbound_flags}
63174198Speter			;;
63274198Speter		esac
63374198Speter		;;
63474198Speter	esac
63574198Speterfi
63674198Speter
63717161Spstecho '.'
63817161Spst
63916671Spst# Recover vi editor files.
64050612Simpfind /var/tmp/vi.recover ! -type f -a ! -type d -delete
64119314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
64250357Ssheldonhif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
64370109Sdougb	echo -n 'Recovering vi editor sessions:'
64455511Speter	for i in /var/tmp/vi.recover/vi.*; do
64519314Speter		# Only test files that are readable.
64651231Ssheldonh		if [ ! -r "${i}" ]; then
64719314Speter			continue
64819314Speter		fi
64919314Speter
65019314Speter		# Unmodified nvi editor backup files either have the
65119314Speter		# execute bit set or are zero length.  Delete them.
65251231Ssheldonh		if [ -x "${i}" -o ! -s "${i}" ]; then
65355451Speter			rm -f "${i}"
65419314Speter		fi
65516671Spst	done
65619314Speter
65719314Speter	# It is possible to get incomplete recovery files, if the editor
65819314Speter	# crashes at the right time.
65919314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
66050357Ssheldonh	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
66155511Speter		for i in /var/tmp/vi.recover/recover.*; do
66219314Speter			# Only test files that are readable.
66351231Ssheldonh			if [ ! -r "${i}" ]; then
66419314Speter				continue
66519314Speter			fi
66619314Speter
66719314Speter			# Delete any recovery files that are zero length,
66819314Speter			# corrupted, or that have no corresponding backup file.
66919314Speter			# Else send mail to the user.
67055453Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
67151231Ssheldonh			if [ -n "${recfile}" -a -s "${recfile}" ]; then
67255451Speter				sendmail -t < "${i}"
67319314Speter			else
67455451Speter				rm -f "${i}"
67519314Speter			fi
67619314Speter		done
67719314Speter	fi
67870109Sdougb	echo '.'
67916671Spstfi
68016671Spst
68151231Ssheldonh# Make a bounds file for msgs(1) if there isn't one already
68251231Ssheldonh#
68370109Sdougbif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
68437899Snectar	echo 0 > /var/msgs/bounds
68537899Snectarfi
68637899Snectar
68751231Ssheldonhcase ${update_motd} in
68851231Ssheldonh[Nn][Oo] | '')
68951231Ssheldonh	;;
69051231Ssheldonh*)
69151231Ssheldonh	if T=`mktemp /tmp/_motd.XXXXXX`; then
69250357Ssheldonh		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
69350357Ssheldonh		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
69450357Ssheldonh		cmp -s ${T} /etc/motd || {
69550357Ssheldonh			cp ${T} /etc/motd
69649451Speter			chmod 644 /etc/motd
69749451Speter		}
69850357Ssheldonh		rm -f ${T}
69949451Speter	fi
70051231Ssheldonh	;;
70151231Ssheldonhesac
70251231Ssheldonh
70351617Snsayer# Configure implementation specific stuff
70451617Snsayer#
70551617Snsayerarch=`uname -m`
70651617Snsayerif [ -r /etc/rc.${arch} ]; then
70751617Snsayer	. /etc/rc.${arch}
70851617Snsayerfi
70951617Snsayer
71070856Sjhb# Configure the system console
71170856Sjhb#
71270856Sjhbif [ -r /etc/rc.syscons ]; then
71370856Sjhb	. /etc/rc.syscons
71470856Sjhbfi
71570856Sjhb
71651231Ssheldonh# Run rc.devfs if readable to customize devfs
71751231Ssheldonh#
71851231Ssheldonhif [ -r /etc/rc.devfs ]; then
71951231Ssheldonh	sh /etc/rc.devfs
72041704Sdillonfi
72141704Sdillon
72270109Sdougbecho -n 'Additional ABI support:'
72364684Sobrien
72471121Sdes# Load the SysV IPC API if requested.
72571121Sdescase ${sysvipc_enable} in
72671121Sdes[Yy][Ee][Ss])
72771121Sdes	echo -n ' sysvipc'
72871121Sdes	kldload sysvmsg >/dev/null 2>&1
72971121Sdes	kldload sysvsem >/dev/null 2>&1
73071121Sdes	kldload sysvshm >/dev/null 2>&1
73171121Sdes	;;
73271121Sdesesac
73371121Sdes
73464684Sobrien# Start the Linux binary compatibility if requested.
73564684Sobrien#
73664684Sobriencase ${linux_enable} in
73764684Sobrien[Yy][Ee][Ss])
73864809Ssheldonh	echo -n ' linux'
73964809Ssheldonh	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
74064809Ssheldonh		kldload linux > /dev/null 2>&1
74164809Ssheldonh	fi
74264809Ssheldonh	if [ -x /compat/linux/sbin/ldconfig ]; then
74364809Ssheldonh		/compat/linux/sbin/ldconfig
74464809Ssheldonh	fi
74564684Sobrien	;;
74664684Sobrienesac
74764684Sobrien
74864684Sobrien# Start the SysVR4 binary emulation if requested.
74964684Sobrien#
75064684Sobriencase ${svr4_enable} in
75164684Sobrien[Yy][Ee][Ss])
75276553Speter	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
75364684Sobrien	;;
75464684Sobrienesac
75564684Sobrien
75670109Sdougbecho '.'
75764810Ssheldonh
75841704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
75943951Sjkh# use this file and want to make it programmatic, source /etc/defaults/rc.conf
76043951Sjkh# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
76143951Sjkh# shown below.  Please do not put local extensions into /etc/rc itself.
76241704Sdillon# Use /etc/rc.local
76341704Sdillon#
76451231Ssheldonh# ---- rc.local ----
76551231Ssheldonh#	if [ -r /etc/defaults/rc.conf ]; then
76651231Ssheldonh#		. /etc/defaults/rc.conf
76759674Ssheldonh#		source_rc_confs
76859674Ssheldonh#	elif [ -r /etc/rc.conf ]; then
76959674Ssheldonh#		. /etc/rc.conf
77051231Ssheldonh#	fi
77151231Ssheldonh#
77251231Ssheldonh#	... additional startup conditionals ...
77351231Ssheldonh# ---- rc.local ----
77451231Ssheldonh#
77551231Ssheldonhif [ -r /etc/rc.local ]; then
77670109Sdougb	echo -n 'Starting local daemons:'
77751231Ssheldonh	sh /etc/rc.local
77843197Sdillon	echo '.'
77941704Sdillonfi
78041704Sdillon
78151617Snsayer# For each valid dir in $local_startup, search for init scripts matching *.sh
78251617Snsayer#
78351617Snsayercase ${local_startup} in
78451617Snsayer[Nn][Oo] | '')
78551617Snsayer	;;
78651617Snsayer*)
78751617Snsayer	echo -n 'Local package initialization:'
78879825Sroam	slist=""
78951617Snsayer	for dir in ${local_startup}; do
79051617Snsayer		if [ -d "${dir}" ]; then
79151617Snsayer			for script in ${dir}/*.sh; do
79279825Sroam				slist="${slist}${script_name_sep}${script}"
79351617Snsayer			done
79451617Snsayer		fi
79551617Snsayer	done
79679825Sroam	script_save_sep="$IFS"
79779825Sroam	IFS="${script_name_sep}"
79879825Sroam	for script in ${slist}; do
79979825Sroam		if [ -x "${script}" ]; then
80079825Sroam			(set -T
80179825Sroam			trap 'exit 1' 2
80283871Sobrien			sh ${script} start)
80379825Sroam		fi
80479825Sroam	done
80579825Sroam	IFS="${script_save_sep}"
80670109Sdougb	echo '.'
80751617Snsayer	;;
80851617Snsayeresac
80951617Snsayer
81053314Sacheif [ -n "${network_pass3_done}" ]; then
81153314Sache	network_pass4
81253314Sachefi
81353314Sache
81437106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
81537106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
81651231Ssheldonh#
81751231Ssheldonhcase ${kern_securelevel_enable} in
81851231Ssheldonh[Yy][Ee][Ss])
81951231Ssheldonh	if [ "${kern_securelevel}" -ge 0 ]; then
82070109Sdougb		echo 'Raising kernel security level: '
82151231Ssheldonh		sysctl -w kern.securelevel=${kern_securelevel}
82251231Ssheldonh	fi
82351231Ssheldonh	;;
82451231Ssheldonhesac
82537106Sjkoshy
82676946Sdd# Start background fsck checks if necessary
82776946Sddcase ${background_fsck} in
82876946Sdd[Yy][Ee][Ss])
82976946Sdd	echo 'Starting background filesystem checks'
83076946Sdd	nice -4 fsck -B -p 2>&1 | logger -p daemon.notice &
83176946Sdd	;;
83276946Sddesac
83376460Smckusick
83470109Sdougbecho ''
83570109Sdougb
83637Srgrimesdate
83770109Sdougb
83837Srgrimesexit 0
83970109Sdougb
840