rc revision 70109
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 70109 2000-12-17 08:24:49Z dougb $
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
7469988Sbsdchkdepend() {
7569988Sbsd	svc=$1
7669988Sbsd	svc_var=$2
7769988Sbsd	dep=$3
7869988Sbsd	dep_var=$4
7969988Sbsd
8069988Sbsd	eval svc_val=\${$svc_var}
8169988Sbsd	eval dep_val=\${$dep_var}
8269988Sbsd
8369988Sbsd	case ${svc_val} in
8469876Sobrien	[Yy][Ee][Ss])
8569988Sbsd		case ${dep_val} in
8669949Sbsd		[Yy][Ee][Ss])
8769988Sbsd		    ;;
8869949Sbsd		*)
8969988Sbsd		    eval ${dep_var}="YES"
9069988Sbsd		    echo "DEPENDENCY NOTE: ${dep} will be enabled" \
9169988Sbsd			 "to support ${svc}"
9269988Sbsd		    ;;
9369949Sbsd		esac
9469876Sobrien		;;
9569876Sobrien	esac
9669988Sbsd}
9767179Sjwd
9869988Sbsdchkdepend amd amd_enable        portmap portmap_enable
9969988Sbsdchkdepend NFS nfs_server_enable portmap portmap_enable
10069876Sobrien
10167179Sjwd# First pass at entropy recovery so the rebooting /dev/random can reseed.
10267113Smarkm#
10367113Smarkmcase ${entropy_file} in
10467113Smarkm[Nn][Oo] | '')
10567113Smarkm	;;
10667113Smarkm*)
10767113Smarkm	if [ -w /dev/random ]; then
10867179Sjwd		if [ -f "${entropy_file}" -a -r "${entropy_file}" -a \
10967179Sjwd		    -s "${entropy_file}" ]; then
11067179Sjwd			echo "Using ${entropy_file} as an entropy file"
11167113Smarkm			cat ${entropy_file} > /dev/random 2> /dev/random
11267179Sjwd			entropy_reseeded=yes
11367113Smarkm		fi
11467113Smarkm	fi
11567113Smarkm	;;
11667113Smarkmesac
11767113Smarkm
11815568Sasami# Configure ccd devices.
11951231Ssheldonh#
12051231Ssheldonhif [ -r /etc/ccd.conf ]; then
12115568Sasami	ccdconfig -C
12215568Sasamifi
12315568Sasami
12451231Ssheldonhcase ${start_vinum} in
12551231Ssheldonh[Yy][Ee][Ss])
12645239Sgrog	vinum start
12751231Ssheldonh	;;
12851231Ssheldonhesac
12942741Sgrog
13043803Sdillonswapon -a
1313843Sdg
13268985Sdougbcase ${bootmode} in
13351231Ssheldonhautoboot)
13470109Sdougb	echo 'Automatic boot in progress...'
13537Srgrimes	fsck -p
13637Srgrimes	case $? in
13737Srgrimes	0)
13837Srgrimes		;;
13937Srgrimes	2)
14037Srgrimes		exit 1
14137Srgrimes		;;
14237Srgrimes	4)
14337Srgrimes		reboot
14470109Sdougb		echo 'Reboot failed... help!'
14537Srgrimes		exit 1
14637Srgrimes		;;
14737Srgrimes	8)
14870109Sdougb		echo 'Automatic file system check failed... help!'
14937Srgrimes		exit 1
15037Srgrimes		;;
15137Srgrimes	12)
15270109Sdougb		echo 'Reboot interrupted'
15337Srgrimes		exit 1
15437Srgrimes		;;
15537Srgrimes	130)
15637Srgrimes		# interrupt before catcher installed
15737Srgrimes		exit 1
15837Srgrimes		;;
15937Srgrimes	*)
16070109Sdougb		echo 'Unknown error in reboot'
16137Srgrimes		exit 1
16237Srgrimes		;;
16337Srgrimes	esac
16451231Ssheldonh	;;
16551231Ssheldonh*)
16670109Sdougb	echo 'Skipping disk checks ...'
16751231Ssheldonh	;;
16851231Ssheldonhesac
16937Srgrimes
17045222Scracauerset -T
17137Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
17237Srgrimes
17343197Sdillon# root normally must be read/write, but if this is a BOOTP NFS
17443197Sdillon# diskless boot it does not have to be.
17543197Sdillon#
17651231Ssheldonhcase ${root_rw_mount} in
17751231Ssheldonh[Nn][Oo] | '')
17851231Ssheldonh	;;
17951231Ssheldonh*)
18051231Ssheldonh	if ! mount -u -o rw / ; then
18170109Sdougb		echo 'Mounting root filesystem rw failed, startup aborted'
18251231Ssheldonh		exit 1
18351231Ssheldonh	fi
18451231Ssheldonh	;;
18551231Ssheldonhesac
1861692Sphk
18743803Sdillonumount -a >/dev/null 2>&1
18843197Sdillon
18956038Sgreen# Mount everything except nfs filesystems.
19056038Sgreenmount -a -t nonfs
19151231Ssheldonh
19251231Ssheldonhcase $? in
19351231Ssheldonh0)
19451231Ssheldonh	;;
19551231Ssheldonh*)
19670109Sdougb	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
19743803Sdillon	exit 1
19851231Ssheldonh	;;
19951231Ssheldonhesac
20037Srgrimes
20143197Sdillon# Run custom disk mounting function here
20243197Sdillon#
20351231Ssheldonhif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
20450357Ssheldonh		sh ${diskless_mount}
20543197Sdillonfi
20643197Sdillon
20767179Sjwd# Second attempt at reseeding, if needed.
20867179Sjwd#
20967179Sjwdcase ${entropy_reseeded} in
21067179Sjwdyes)
21167179Sjwd	;;
21267179Sjwd*)
21367179Sjwd	case ${entropy_file} in
21467179Sjwd	[Nn][Oo] | '')
21567179Sjwd		;;
21667179Sjwd	*)
21767179Sjwd		if [ -w /dev/random ]; then
21867179Sjwd			if [ -f "${entropy_file}" -a -r "${entropy_file}" -a \
21967179Sjwd			    -s "${entropy_file}" ]; then
22067179Sjwd				echo "Using ${entropy_file} as an entropy file"
22167179Sjwd				cat ${entropy_file} > /dev/random 2> /dev/random
22267179Sjwd			elif [ "${entropy_file}" != /var/db/entropy -a \
22367179Sjwd			    -f /var/db/entropy -a -r /var/db/entropy -a \
22467179Sjwd			    -s /var/db/entropy ]; then
22570109Sdougb				echo 'Using /var/db/entropy as an entropy file'
22667179Sjwd				cat /var/db/entropy > /dev/random 2> /dev/random
22767179Sjwd			else
22867181Sjwd    echo "Can't use ${entropy_file} as an entropy file, trying other sources"
22967179Sjwd				# XXX temporary until we can get the entropy
23067179Sjwd				# harvesting rate up
23167181Sjwd				# Entropy below is not great,
23267181Sjwd				# but better than nothing.
23367181Sjwd				(ps -gauxwww; iostat; vmstat; sysctl -a;
23467383Sjkh				    dmesg) | /bin/dd of=/dev/random bs=8k 2>/dev/null
23567179Sjwd				( for i in /etc /var/run ; do
23667179Sjwd					cd $i ; ls -al ; cat *
23767383Sjkh				done ) | /bin/dd of=/dev/random bs=8k 2>/dev/null
23867179Sjwd			fi
23967179Sjwd		fi
24067179Sjwd		;;
24167179Sjwd	esac
24267179Sjwd	;;
24367179Sjwdesac
24467179Sjwd
24567179Sjwd# Remove these to prevent problems on future reboots
24667179Sjwdrm -f "${entropy_file}" /var/db/entropy
24767179Sjwd
2484091Sacheadjkerntz -i
249872Sache
25064400Sbrianpurgedir() {
25164400Sbrian	local dir file
25264400Sbrian
25364400Sbrian	if [ $# -eq 0 ]; then
25464400Sbrian		purgedir .
25564400Sbrian	else
25664400Sbrian		for dir
25764400Sbrian		do
25864400Sbrian		(
25964449Sbrian			cd "$dir" && for file in .* *
26064400Sbrian			do
26164449Sbrian				[ ."$file" = .. -o ."$file" = ... ] && continue
26264449Sbrian				[ -d "$file" -a ! -L "$file" ] &&
26364449Sbrian					purgedir "$file"
26464449Sbrian				[ -f "$file" ] && rm -f -- "$file"
26564400Sbrian			done
26664400Sbrian		)
26764400Sbrian		done
26864400Sbrian	fi
26964400Sbrian}
27064400Sbrian
27138237Sbrianclean_var() {
27239384Sbrian	if [ ! -f /var/run/clean_var ]; then
27339384Sbrian		rm -rf /var/run/*
27464400Sbrian		purgedir /var/spool/lock
27539384Sbrian		rm -rf /var/spool/uucp/.Temp/*
27639384Sbrian		# Keep a copy of the boot messages around
27739384Sbrian		dmesg >/var/run/dmesg.boot
27839384Sbrian		# And an initial utmp file
27951231Ssheldonh		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
28039384Sbrian		>/var/run/clean_var
28139384Sbrian	fi
28238237Sbrian}
28326450Sache
28438237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
28539384Sbrian	# network_pass1() *may* end up writing stuff to /var - we don't want to
28639384Sbrian	# remove it immediately afterwards - *nor* to we want to fail to clean
28739384Sbrian	# an nfs-mounted /var.
28839384Sbrian	clean_var
28938237Sbrianfi
29021197Sphk
29117767Sjkh# Add additional swapfile, if configured.
29251231Ssheldonh#
29351231Ssheldonhcase ${swapfile} in
29451231Ssheldonh[Nn][Oo] | '')
29551231Ssheldonh	;;
29651231Ssheldonh*)
29756969Snsayer	if [ -w "${swapfile}" -a -c /dev/vn0b ]; then
29870109Sdougb		echo "Adding ${swapfile} as additional swap"
29951231Ssheldonh		vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
30051231Ssheldonh	fi
30151231Ssheldonh	;;
30251231Ssheldonhesac
30317767Sjkh
30451231Ssheldonh# Set sysctl variables as early as we can
30551231Ssheldonh#
30651231Ssheldonhif [ -r /etc/rc.sysctl ]; then
30745096Simp	. /etc/rc.sysctl
30845096Simpfi
30945096Simp
31051231Ssheldonh# Configure serial devices
31151231Ssheldonh#
31251231Ssheldonhif [ -r /etc/rc.serial ]; then
3137293Sjkh	. /etc/rc.serial
3141675Sachefi
3151675Sache
31651231Ssheldonh# Start up PC-card configuration
31751231Ssheldonh#
31851231Ssheldonhif [ -r /etc/rc.pccard ]; then
31914624Snate	. /etc/rc.pccard
32014596Snatefi
32114596Snate
32251231Ssheldonh# Start up the initial network configuration.
32351231Ssheldonh#
32451231Ssheldonhif [ -r /etc/rc.network ]; then
32525184Sjkh	. /etc/rc.network	# We only need to do this once.
32625184Sjkh	network_pass1
3277460Sjkhfi
3287460Sjkh
32957398Sshincase ${ipv6_enable} in
33057398Sshin[Yy][Ee][Ss])
33157398Sshin	if [ -r /etc/rc.network6 ]; then
33257398Sshin		. /etc/rc.network6	# We only need to do this once also.
33357398Sshin		network6_pass1
33457398Sshin	fi
33557398Sshin	;;
33657398Sshinesac
33757398Sshin
33858566Sdan# Mount NFS filesystems if present in /etc/fstab
33961065Sasmodaicase "`mount -d -a -t nfs`" in
34061065Sasmodai*mount_nfs*)
34170109Sdougb	echo -n 'Mounting NFS file systems:'
34258566Sdan	mount -a -t nfs
34370109Sdougb	echo '.'
34461065Sasmodai	;;
34561065Sasmodaiesac
3467487Srgrimes
3477487Srgrimes# Whack the pty perms back into shape.
34851231Ssheldonh#
34964893Ssheldonhif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
35064893Ssheldonh	chflags 0 /dev/tty[pqrsPQRS]*
35164893Ssheldonh	chmod 666 /dev/tty[pqrsPQRS]*
35264893Ssheldonh	chown root:wheel /dev/tty[pqrsPQRS]*
35364893Ssheldonhfi
3547487Srgrimes
35551231Ssheldonh# Clean up left-over files
35651231Ssheldonh#
35738237Sbrianclean_var			# If it hasn't already been done
35838237Sbrianrm /var/run/clean_var
35938237Sbrian
36031192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
36131192Ssteve# help in any way for long-living systems, and it might accidentally
36231192Ssteve# clobber files you would rather like to have preserved after a crash
36331192Ssteve# (if not using mfs /tmp anyway).
36431192Ssteve#
36531192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
36631192Ssteve#
36751231Ssheldonhcase ${clear_tmp_enable} in
36851231Ssheldonh[Yy][Ee][Ss])
36970109Sdougb	echo -n 'Clearing /tmp:'
37031192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
37131192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
37231192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
37351231Ssheldonh		find -d . ! -name . ! -name lost+found ! -name quota.user \
37451231Ssheldonh		! -name quota.group -exec rm -rf -- {} \;)
37570109Sdougb	echo '.'
37651231Ssheldonh	;;
37751231Ssheldonhesac
37831192Ssteve
37951231Ssheldonh# Remove X lock files, since they will prevent you from restarting X11
38038915Scracauer# after a system crash.
38151231Ssheldonh#
38238915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
38338915Scracauer
38451231Ssheldonh# Snapshot any kernel -c changes back to disk here <someday>.
38551231Ssheldonh# This has changed with ELF and /kernel.config.
3867487Srgrimes
38770109Sdougbecho -n 'Additional daemons:'
38851231Ssheldonh
38951231Ssheldonh# Start system logging and name service.  Named needs to start before syslogd
39051231Ssheldonh# if you don't have a /etc/resolv.conf.
3917259Sjkh#
39251231Ssheldonhcase ${syslogd_enable} in
39351231Ssheldonh[Yy][Ee][Ss])
39424463Spst	# Transitional symlink (for the next couple of years :) until all
39551231Ssheldonh	# binaries have had a chance to move towards /var/run/log.
39651231Ssheldonh	if [ ! -h /dev/log ]; then
39724463Spst		# might complain for r/o root f/s
39824463Spst		ln -sf /var/run/log /dev/log
39924463Spst	fi
40024463Spst
40124463Spst	rm -f /var/run/log
40251231Ssheldonh	echo -n ' syslogd';	syslogd ${syslogd_flags}
40351231Ssheldonh	;;
40451231Ssheldonhesac
40551231Ssheldonh
40625339Sjkhecho '.'
40725339Sjkh
40867445Sphk# Build device name databases if we are not using DEVFS
40967040Sache#
41067445Sphkif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
41170109Sdougb	rm -f /var/run/dev.db
41267445Sphkelse
41367445Sphk	dev_mkdb
41467445Sphkfi
41567040Sache
41651231Ssheldonh# Enable dumpdev so that savecore can see it.
41732340Sjoerg# /var/crash should be a directory or a symbolic link
41832340Sjoerg# to the crash directory if core dumps are to be saved.
41951231Ssheldonh#
42051231Ssheldonhcase ${dumpdev} in
42151231Ssheldonh[Nn][Oo] | '')
42251231Ssheldonh	;;
42351231Ssheldonh*)
42451231Ssheldonh	if [ -e "${dumpdev}" -a -d /var/crash ]; then
42567008Sru		dumpon -v ${dumpdev}
42670109Sdougb		echo -n 'Checking for core dump: '
42751231Ssheldonh		savecore /var/crash
42851231Ssheldonh	fi
42951231Ssheldonh	;;
43051231Ssheldonhesac
43132340Sjoerg
43250357Ssheldonhif [ -n "${network_pass1_done}" ]; then
43339384Sbrian	network_pass2
434857Sdgfi
43537Srgrimes
43644818Sbillf# Enable/Check the quotas (must be after ypbind if using NIS)
43751231Ssheldonh#
43851231Ssheldonhcase ${enable_quotas} in
43951231Ssheldonh[Yy][Ee][Ss])
44051231Ssheldonh	case ${check_quotas} in
44151231Ssheldonh	[Yy][Ee][Ss])
44270109Sdougb		echo -n 'Checking quotas:'
44351231Ssheldonh		quotacheck -a
44451231Ssheldonh		echo ' done.'
44551231Ssheldonh		;;
44651231Ssheldonh	esac
44744818Sbillf
44870109Sdougb	echo -n 'Enabling quotas:'
44951231Ssheldonh	quotaon -a
45051231Ssheldonh	echo ' done.'
45151231Ssheldonh	;;
45251231Ssheldonhesac
45344818Sbillf
45450357Ssheldonhif [ -n "${network_pass2_done}" ]; then
45539384Sbrian	network_pass3
4567477Sachefi
4577477Sache
45851231Ssheldonh# Check the password temp/lock file
45951231Ssheldonh#
46051231Ssheldonhif [ -e /etc/ptmp ]; then
4617487Srgrimes	logger -s -p auth.err \
4627487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
4637238Sachefi
4647238Sache
46551231Ssheldonhcase ${accounting_enable} in
46651231Ssheldonh[Yy][Ee][Ss])
46751231Ssheldonh	if [ -d /var/account ]; then
46870109Sdougb		echo 'Turning on accounting:'
46951231Ssheldonh		if [ ! -e /var/account/acct ]; then
47051231Ssheldonh			touch /var/account/acct
47151231Ssheldonh		fi
47251231Ssheldonh		accton /var/account/acct
47311992Sache	fi
47451231Ssheldonh	;;
47551231Ssheldonhesac
4767238Sache
47727365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
47827365Sjkh# add your own entries or you may come to grief.
47951231Ssheldonh#
48064520Sjdpldconfig="/sbin/ldconfig"
48164520Sjdpcase ${ldconfig_insecure} in
48264520Sjdp[Yy][Ee][Ss])
48364520Sjdp	ldconfig="${ldconfig} -i"
48464520Sjdp	;;
48564520Sjdpesac
48638512Sgpalmerif [ -x /sbin/ldconfig ]; then
48751231Ssheldonh	case `/usr/bin/objformat` in
48851231Ssheldonh	elf)
48939329Sjdp		_LDC=/usr/lib
49050357Ssheldonh		for i in ${ldconfig_paths}; do
49151231Ssheldonh			if [ -d "${i}" ]; then
49250357Ssheldonh				_LDC="${_LDC} ${i}"
49339329Sjdp			fi
49439329Sjdp		done
49570109Sdougb		echo 'ELF ldconfig path:' ${_LDC}
49664520Sjdp		${ldconfig} -elf ${_LDC}
49751231Ssheldonh		;;
49851231Ssheldonh	esac
49939329Sjdp
50041648Sjb	# Legacy aout support for i386 only
50151231Ssheldonh	case `sysctl -n hw.machine` in
50251231Ssheldonh	i386)
50343951Sjkh		# Default the a.out ldconfig path.
50441648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
50541648Sjb		_LDC=/usr/lib/aout
50650357Ssheldonh		for i in ${ldconfig_paths_aout}; do
50751231Ssheldonh			if [ -d "${i}" ]; then
50850357Ssheldonh				_LDC="${_LDC} ${i}"
50941648Sjb			fi
51041648Sjb		done
51170109Sdougb		echo 'a.out ldconfig path:' ${_LDC}
51264520Sjdp		${ldconfig} -aout ${_LDC}
51351231Ssheldonh		;;
51451231Ssheldonh	esac
51538512Sgpalmerfi
5167296Sjkh
51717210Spst# Now start up miscellaneous daemons that don't belong anywhere else
51817210Spst#
51970109Sdougbecho -n 'Starting standard daemons:'
52051231Ssheldonhcase ${inetd_enable} in
52151231Ssheldonh[Nn][Oo])
52251231Ssheldonh	;;
52351231Ssheldonh*)
52426727Spst	echo -n ' inetd';	inetd ${inetd_flags}
52551231Ssheldonh	;;
52651231Ssheldonhesac
52717210Spst
52851231Ssheldonhcase ${cron_enable} in
52951231Ssheldonh[Nn][Oo])
53051231Ssheldonh	;;
53151231Ssheldonh*)
53226727Spst	echo -n ' cron';	cron
53351231Ssheldonh	;;
53451231Ssheldonhesac
53526727Spst
53651231Ssheldonhcase ${lpd_enable} in
53751231Ssheldonh[Yy][Ee][Ss])
53851231Ssheldonh	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
53951231Ssheldonh	;;
54051231Ssheldonhesac
54117210Spst
54251231Ssheldonhcase ${sendmail_enable} in
54351231Ssheldonh[Yy][Ee][Ss])
54454843Sobrien	if [ -r /etc/mail/sendmail.cf ]; then
54551231Ssheldonh		echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
54651231Ssheldonh	fi
54751231Ssheldonh	;;
54851231Ssheldonhesac
54917161Spst
55057572Smarkmcase ${sshd_enable} in
55157572Smarkm[Yy][Ee][Ss])
55257572Smarkm	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
55357572Smarkm		echo -n ' sshd';
55457572Smarkm		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
55557572Smarkm	fi
55657572Smarkm	;;
55757572Smarkmesac
55857572Smarkm
55951231Ssheldonhcase ${usbd_enable} in
56051231Ssheldonh[Yy][Ee][Ss])
56142498Sn_hibma	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
56251231Ssheldonh	;;
56351231Ssheldonhesac
56442498Sn_hibma
56517161Spstecho '.'
56617161Spst
56716671Spst# Recover vi editor files.
56850612Simpfind /var/tmp/vi.recover ! -type f -a ! -type d -delete
56919314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
57050357Ssheldonhif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
57170109Sdougb	echo -n 'Recovering vi editor sessions:'
57255511Speter	for i in /var/tmp/vi.recover/vi.*; do
57319314Speter		# Only test files that are readable.
57451231Ssheldonh		if [ ! -r "${i}" ]; then
57519314Speter			continue
57619314Speter		fi
57719314Speter
57819314Speter		# Unmodified nvi editor backup files either have the
57919314Speter		# execute bit set or are zero length.  Delete them.
58051231Ssheldonh		if [ -x "${i}" -o ! -s "${i}" ]; then
58155451Speter			rm -f "${i}"
58219314Speter		fi
58316671Spst	done
58419314Speter
58519314Speter	# It is possible to get incomplete recovery files, if the editor
58619314Speter	# crashes at the right time.
58719314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
58850357Ssheldonh	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
58955511Speter		for i in /var/tmp/vi.recover/recover.*; do
59019314Speter			# Only test files that are readable.
59151231Ssheldonh			if [ ! -r "${i}" ]; then
59219314Speter				continue
59319314Speter			fi
59419314Speter
59519314Speter			# Delete any recovery files that are zero length,
59619314Speter			# corrupted, or that have no corresponding backup file.
59719314Speter			# Else send mail to the user.
59855453Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
59951231Ssheldonh			if [ -n "${recfile}" -a -s "${recfile}" ]; then
60055451Speter				sendmail -t < "${i}"
60119314Speter			else
60255451Speter				rm -f "${i}"
60319314Speter			fi
60419314Speter		done
60519314Speter	fi
60670109Sdougb	echo '.'
60716671Spstfi
60816671Spst
60951231Ssheldonh# Make a bounds file for msgs(1) if there isn't one already
61051231Ssheldonh#
61170109Sdougbif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
61237899Snectar	echo 0 > /var/msgs/bounds
61337899Snectarfi
61437899Snectar
61551231Ssheldonhcase ${update_motd} in
61651231Ssheldonh[Nn][Oo] | '')
61751231Ssheldonh	;;
61851231Ssheldonh*)
61951231Ssheldonh	if T=`mktemp /tmp/_motd.XXXXXX`; then
62050357Ssheldonh		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
62150357Ssheldonh		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
62250357Ssheldonh		cmp -s ${T} /etc/motd || {
62350357Ssheldonh			cp ${T} /etc/motd
62449451Speter			chmod 644 /etc/motd
62549451Speter		}
62650357Ssheldonh		rm -f ${T}
62749451Speter	fi
62851231Ssheldonh	;;
62951231Ssheldonhesac
63051231Ssheldonh
63151617Snsayer# Configure implementation specific stuff
63251617Snsayer#
63351617Snsayerarch=`uname -m`
63451617Snsayerif [ -r /etc/rc.${arch} ]; then
63551617Snsayer	. /etc/rc.${arch}
63651617Snsayerfi
63751617Snsayer
63851231Ssheldonh# Run rc.devfs if readable to customize devfs
63951231Ssheldonh#
64051231Ssheldonhif [ -r /etc/rc.devfs ]; then
64151231Ssheldonh	sh /etc/rc.devfs
64241704Sdillonfi
64341704Sdillon
64470109Sdougbecho -n 'Additional ABI support:'
64564684Sobrien
64664684Sobrien# Start the Linux binary compatibility if requested.
64764684Sobrien#
64864684Sobriencase ${linux_enable} in
64964684Sobrien[Yy][Ee][Ss])
65064809Ssheldonh	echo -n ' linux'
65164809Ssheldonh	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
65264809Ssheldonh		kldload linux > /dev/null 2>&1
65364809Ssheldonh	fi
65464809Ssheldonh	if [ -x /compat/linux/sbin/ldconfig ]; then
65564809Ssheldonh		/compat/linux/sbin/ldconfig
65664809Ssheldonh	fi
65764684Sobrien	;;
65864684Sobrienesac
65964684Sobrien
66064684Sobrien# Start the SysVR4 binary emulation if requested.
66164684Sobrien#
66264684Sobriencase ${svr4_enable} in
66364684Sobrien[Yy][Ee][Ss])
66464809Ssheldonh	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
66564684Sobrien	;;
66664684Sobrienesac
66764684Sobrien
66870109Sdougbecho '.'
66964810Ssheldonh
67041704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
67143951Sjkh# use this file and want to make it programmatic, source /etc/defaults/rc.conf
67243951Sjkh# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
67343951Sjkh# shown below.  Please do not put local extensions into /etc/rc itself.
67441704Sdillon# Use /etc/rc.local
67541704Sdillon#
67651231Ssheldonh# ---- rc.local ----
67751231Ssheldonh#	if [ -r /etc/defaults/rc.conf ]; then
67851231Ssheldonh#		. /etc/defaults/rc.conf
67959674Ssheldonh#		source_rc_confs
68059674Ssheldonh#	elif [ -r /etc/rc.conf ]; then
68159674Ssheldonh#		. /etc/rc.conf
68251231Ssheldonh#	fi
68351231Ssheldonh#
68451231Ssheldonh#	... additional startup conditionals ...
68551231Ssheldonh# ---- rc.local ----
68651231Ssheldonh#
68751231Ssheldonhif [ -r /etc/rc.local ]; then
68870109Sdougb	echo -n 'Starting local daemons:'
68951231Ssheldonh	sh /etc/rc.local
69043197Sdillon	echo '.'
69141704Sdillonfi
69241704Sdillon
69351617Snsayer# For each valid dir in $local_startup, search for init scripts matching *.sh
69451617Snsayer#
69551617Snsayercase ${local_startup} in
69651617Snsayer[Nn][Oo] | '')
69751617Snsayer	;;
69851617Snsayer*)
69951617Snsayer	echo -n 'Local package initialization:'
70051617Snsayer	for dir in ${local_startup}; do
70151617Snsayer		if [ -d "${dir}" ]; then
70251617Snsayer			for script in ${dir}/*.sh; do
70351617Snsayer				if [ -x "${script}" ]; then
70451617Snsayer					(set -T
70551617Snsayer					 trap 'exit 1' 2
70651617Snsayer					 ${script} start)
70751617Snsayer				fi
70851617Snsayer			done
70951617Snsayer		fi
71051617Snsayer	done
71170109Sdougb	echo '.'
71251617Snsayer	;;
71351617Snsayeresac
71451617Snsayer
71553314Sacheif [ -n "${network_pass3_done}" ]; then
71653314Sache	network_pass4
71753314Sachefi
71853314Sache
71937106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
72037106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
72151231Ssheldonh#
72251231Ssheldonhcase ${kern_securelevel_enable} in
72351231Ssheldonh[Yy][Ee][Ss])
72451231Ssheldonh	if [ "${kern_securelevel}" -ge 0 ]; then
72570109Sdougb		echo 'Raising kernel security level: '
72651231Ssheldonh		sysctl -w kern.securelevel=${kern_securelevel}
72751231Ssheldonh	fi
72851231Ssheldonh	;;
72951231Ssheldonhesac
73037106Sjkoshy
73170109Sdougbecho ''
73270109Sdougb
73337Srgrimesdate
73470109Sdougb
73537Srgrimesexit 0
73670109Sdougb
737