rc revision 108191
1#!/bin/sh
2#
3# Copyright (c) 2000  The FreeBSD Project
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27#	@(#)rc	5.27 (Berkeley) 6/5/91
28# $FreeBSD: head/etc/rc 108191 2002-12-22 22:18:41Z dillon $
29#
30
31# System startup script run by init on autoboot
32# or after single-user.
33# Output and error are redirected to console by init,
34# and the console is the controlling terminal.
35
36# Note that almost all of the user-configurable behavior is no longer in
37# this file, but rather in /etc/defaults/rc.conf.  Please check that file
38# first before contemplating any changes here.  If you do need to change
39# this file for some reason, we would like to know about it.
40
41stty status '^T'
42
43# Set shell to ignore SIGINT (2), but not children;
44# shell catches SIGQUIT (3) and returns to single user after fsck.
45#
46trap : 2
47trap : 3	# shouldn't be needed
48
49HOME=/
50PATH=/sbin:/bin:/usr/sbin:/usr/bin
51export HOME PATH
52
53# If there is a global system configuration file, suck it in.
54# XXX - The only purpose of duplicating it here is to catch rc_ng="YES"
55#
56if [ -r /etc/defaults/rc.conf ]; then
57	. /etc/defaults/rc.conf
58	source_rc_confs
59elif [ -r /etc/rc.conf ]; then
60	. /etc/rc.conf
61fi
62
63# Diskless setups have to depend on a different mechanism since
64# their config files haven't been retargeted yet.
65#
66[ -e /.rcng_yes ] && rc_ng="YES"
67
68case ${rc_ng} in
69[Yy][Ee][Ss])
70	. /etc/rc.subr
71
72	# Note: the system configuration files are loaded as part of
73	# the RCNG system (rc.d/rccond).  Do not load them here as it may
74	# interfere with diskless booting.
75	#
76	if [ "$1" = autoboot ]; then
77		autoboot=yes
78		_boot="faststart"
79		rc_fast=yes        # run_rc_command(): do fast booting
80	else
81		autoboot=no
82		_boot="start"
83	fi
84
85	os=`eval ${CMD_OSTYPE}`
86	files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null`
87
88	for _rc_elem in ${files}; do
89		run_rc_script ${_rc_elem} ${_boot}
90	done
91
92	echo ''
93	date
94	exit 0
95	;;
96*)
97	# fall-through to the old rc scripts
98	;;
99esac
100
101bootmode=$1
102
103# BOOTP diskless boot.  We have to run the rc file early in order to
104# retarget various config files.
105#
106if [ -r /etc/rc.diskless1 ]; then
107	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
108	if [ ${dlv:=0} != 0 ]; then
109		. /etc/rc.diskless1
110	fi
111fi
112
113# If there is a global system configuration file, suck it in.
114#
115if [ -r /etc/defaults/rc.conf ]; then
116	. /etc/defaults/rc.conf
117	source_rc_confs
118elif [ -r /etc/rc.conf ]; then
119	. /etc/rc.conf
120fi
121
122# XXX - Deprecated variable name support
123#	for rpcbind and ntpd
124#
125[ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable"
126[ -n "$portmap_program" ] && rpcbind_program="$portmap_program"
127[ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags"
128[ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable"
129[ -n "$xntpd_enable" ] && ntpd_enable="$xntpd_enable"
130[ -n "$xntpd_program" ] && ntpd_program="$xntpd_program"
131[ -n "$xntpd_flags" ] && ntpd_flags="$xntpd_flags"
132
133feed_dev_random() {
134	if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
135#		echo "Using ${1} as an entropy file"
136		cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
137	fi
138}
139
140chkdepend() {
141	svc=$1
142	svc_var=$2
143	dep=$3
144	dep_var=$4
145
146	eval svc_val=\${$svc_var}
147	eval dep_val=\${$dep_var}
148
149	case ${svc_val} in
150	[Yy][Ee][Ss])
151		case ${dep_val} in
152		[Yy][Ee][Ss])
153			;;
154		*)
155			eval ${dep_var}="YES"
156			echo "DEPENDENCY NOTE: ${dep} will be enabled" \
157			"to support ${svc}"
158			;;
159		esac
160		;;
161	esac
162}
163
164chkdepend amd amd_enable        rpcbind rpcbind_enable
165chkdepend amd amd_enable        NFS nfs_client_enable
166chkdepend NFS nfs_server_enable rpcbind rpcbind_enable
167chkdepend NIS nis_server_enable rpcbind rpcbind_enable
168chkdepend NIS nis_client_enable rpcbind rpcbind_enable
169
170# Enable dumpdev early so that a crash during the boot process can be caught.
171#
172case ${dumpdev} in
173[Nn][Oo] | '')
174	dumpdev='NO'
175	;;
176*)
177	/sbin/dumpon -v ${dumpdev}
178	;;
179esac
180
181# Enable harvesting of entropy via devices.  The sooner this happens the
182# better so that we can take advantage of the boot process.
183#
184echo -n 'Entropy harvesting:'
185
186case ${harvest_interrupt} in
187[Nn][Oo])
188	;;
189*)
190	if [ -w /dev/random ]; then
191		/sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null
192		echo -n ' interrupts'
193	fi
194	;;
195esac
196
197case ${harvest_ethernet} in
198[Nn][Oo])
199	;;
200*)
201	if [ -w /dev/random ]; then
202		/sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null
203		echo -n ' ethernet'
204	fi
205	;;
206esac
207
208case ${harvest_p_to_p} in
209[Nn][Oo])
210	;;
211*)
212	if [ -w /dev/random ]; then
213	/sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null
214		echo -n ' point_to_point'
215	fi
216	;;
217esac
218
219echo '.'
220
221# First pass at reseeding /dev/random.
222#
223case ${entropy_file} in
224[Nn][Oo] | '')
225	;;
226*)
227	if [ -w /dev/random ]; then
228		feed_dev_random "${entropy_file}"
229	fi
230	;;
231esac
232
233# XXX temporary until we can get the entropy
234# harvesting rate up
235# Entropy below is not great,
236# but better than nothing.
237( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \
238    | dd of=/dev/random bs=8k 2>/dev/null
239cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
240
241# Configure ccd devices.
242#
243if [ -r /etc/ccd.conf ]; then
244	ccdconfig -C
245fi
246
247case ${start_vinum} in
248[Yy][Ee][Ss])
249	vinum start
250	;;
251esac
252
253swapon -a
254
255# Last chance to do things before potentially waiting for
256# operator to do fsck related tasks
257if [ -r /etc/rc.early ]; then
258	. /etc/rc.early
259fi
260
261case ${bootmode} in
262autoboot)
263	echo 'Automatic boot in progress...'
264	case ${background_fsck} in
265	[Yy][Ee][Ss])
266		fsck -F -p
267		;;
268	*)
269		fsck -p
270		;;
271	esac
272	case $? in
273	0)
274		;;
275	2)
276		exit 1
277		;;
278	4)
279		reboot
280		echo 'Reboot failed... help!'
281		exit 1
282		;;
283	8)
284		case ${fsck_y_enable} in
285		[Yy][Ee][Ss])
286			echo 'File system preen failed, trying fsck -y . . .'
287			fsck -y
288			case $? in
289			0)
290				;;
291			*)
292			echo 'Automatic filesystem check failed . . . help!'
293				exit 1
294				;;
295			esac
296			;;
297		*)
298			echo 'Automatic filesystem check failed . . . help!'
299			exit 1
300			;;
301		esac
302		;;
303	12)
304		echo 'Reboot interrupted'
305		exit 1
306		;;
307	130)
308		# interrupt before catcher installed
309		exit 1
310		;;
311	*)
312		echo 'Unknown error in reboot'
313		exit 1
314		;;
315	esac
316	;;
317*)
318	echo 'Skipping disk checks ...'
319	;;
320esac
321
322set -T
323trap "echo 'Reboot interrupted'; exit 1" 3
324
325# root normally must be read/write, but if this is a BOOTP NFS
326# diskless boot it does not have to be.
327#
328case ${root_rw_mount} in
329[Nn][Oo] | '')
330	;;
331*)
332	if ! mount -u -o rw / ; then
333		echo 'Mounting root filesystem rw failed, startup aborted'
334		exit 1
335	fi
336	;;
337esac
338
339umount -a >/dev/null 2>&1
340
341# Set up the list of network filesystem types for which mounting should be
342# delayed until after network initialization.
343networkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL'
344case ${extra_netfs_types} in
345[Nn][Oo])
346	;;
347*)
348	networkfs_types="${networkfs_types} ${extra_netfs_types}"
349	;;
350esac
351
352# Mount everything except nfs filesystems.
353mount_excludes='no'
354for i in ${networkfs_types}; do
355	fstype=${i%:*}
356	mount_excludes="${mount_excludes}${fstype},"
357done
358mount_excludes=${mount_excludes%,}
359mount -a -t ${mount_excludes}
360
361case $? in
3620)
363	;;
364*)
365	echo 'Mounting /etc/fstab filesystems failed, startup aborted'
366	exit 1
367	;;
368esac
369
370# Run custom disk mounting function here
371#
372if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
373		sh ${diskless_mount}
374fi
375
376# If we booted a special kernel remove the record so we will boot
377# the default kernel next time
378rm -f /boot/nextboot.conf
379
380# Reseed /dev/random with previously stored entropy.
381case ${entropy_dir} in
382[Nn][Oo])
383	;;
384*)
385	entropy_dir=${entropy_dir:-/var/db/entropy}
386	if [ -d "${entropy_dir}" ]; then
387		if [ -w /dev/random ]; then
388			for seedfile in ${entropy_dir}/*; do
389				feed_dev_random "${seedfile}"
390			done
391		fi
392	fi
393	;;
394esac
395
396case ${entropy_file} in
397[Nn][Oo] | '')
398	;;
399*)
400	if [ -w /dev/random ]; then
401		feed_dev_random "${entropy_file}"
402	fi
403	;;
404esac
405
406adjkerntz -i
407
408purgedir() {
409	local dir file
410
411	if [ $# -eq 0 ]; then
412		purgedir .
413	else
414		for dir
415		do
416		(
417			cd "$dir" && for file in .* *
418			do
419				[ ."$file" = .. -o ."$file" = ... ] && continue
420				if [ -d "$file" -a ! -L "$file" ]
421				then
422					purgedir "$file"
423				else
424					rm -f -- "$file"
425				fi
426			done
427		)
428		done
429	fi
430}
431
432clean_var() {
433	if [ -d /var/run -a ! -f /var/run/clean_var ]; then
434		purgedir /var/run
435		# Keep a copy of the boot messages around
436		dmesg >/var/run/dmesg.boot
437		# And an initial utmp file
438		(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
439		>/var/run/clean_var
440	fi
441	if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
442		purgedir /var/spool/lock
443		>/var/spool/lock/clean_var
444	fi
445	rm -rf /var/spool/uucp/.Temp/*
446}
447
448# network_pass1() *may* end up writing stuff to /var - we don't want to
449# remove it immediately afterwards - *nor* do we want to fail to clean
450# an NFS-mounted /var.
451rm -f /var/run/clean_var /var/spool/lock/clean_var
452clean_var
453
454# Add additional swapfile, if configured.
455#
456case ${swapfile} in
457[Nn][Oo] | '')
458	;;
459*)
460	if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
461		echo "Adding ${swapfile} as additional swap"
462		mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
463	fi
464	;;
465esac
466
467# Early pass to set the variables we can
468#
469if [ -r /etc/rc.sysctl ]; then
470	sh /etc/rc.sysctl first
471fi
472
473# Configure serial devices
474#
475if [ -r /etc/rc.serial ]; then
476	. /etc/rc.serial
477fi
478
479# Start up PC-card configuration
480#
481if [ -r /etc/rc.pccard ]; then
482	. /etc/rc.pccard
483fi
484
485# Start up the initial network configuration.
486#
487if [ -r /etc/rc.network ]; then
488	. /etc/rc.network	# We only need to do this once.
489	network_pass1
490fi
491
492case ${ipv6_enable} in
493[Yy][Ee][Ss])
494	if [ -r /etc/rc.network6 ]; then
495		. /etc/rc.network6	# We only need to do this once also.
496		network6_pass1
497	fi
498	;;
499esac
500
501# Mount NFS filesystems if present in /etc/fstab
502#
503# XXX When the vfsload() issues with nfsclient support and related sysctls
504# have been resolved, this block can be removed, and the condition that
505# skips nfs in the following block (for "other network filesystems") can
506# be removed.
507case "`mount -d -a -t nfs 2> /dev/null`" in
508*mount_nfs*)
509	# Handle absent nfs client support
510	nfsclient_in_kernel=0
511	if sysctl vfs.nfs >/dev/null 2>&1; then
512		nfsclient_in_kernel=1
513	else
514		kldload nfsclient && nfsclient_in_kernel=1
515	fi
516
517	case ${nfsclient_in_kernel} in
518	1)
519		echo -n 'Mounting NFS filesystem:'
520		mount -a -t nfs
521		echo '.'
522		;;
523	*)
524		echo 'Warning: nfs mount requested, but no nfs client in kernel'
525		;;
526	esac
527	;;
528esac
529
530# Mount other network filesystems if present in /etc/fstab
531for i in ${networkfs_types}; do
532	fstype=${i%:*}
533	fsdecr=${i#*:}
534
535	if [ "${fstype}" = "nfs" ]; then
536		continue
537	fi
538	case "`mount -d -a -t ${fstype}`" in
539	*mount_${fstype}*)
540		echo -n "Mounting ${fsdecr} filesystems:"
541		mount -a -t ${fstype}
542		echo '.'
543		;;
544	esac
545done
546
547# Whack the pty perms back into shape.
548#
549if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
550	chflags 0 /dev/tty[pqrsPQRS]*
551	chmod 666 /dev/tty[pqrsPQRS]*
552	chown root:wheel /dev/tty[pqrsPQRS]*
553fi
554
555# Clean up left-over files
556#
557clean_var			# If it hasn't already been done
558rm /var/run/clean_var /var/spool/lock/clean_var
559
560# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
561# help in any way for long-living systems, and it might accidentally
562# clobber files you would rather like to have preserved after a crash
563# (if not using mfs /tmp anyway).
564#
565# See also the example of another cleanup policy in /etc/periodic/daily.
566#
567case ${clear_tmp_enable} in
568[Yy][Ee][Ss])
569	echo -n 'Clearing /tmp:'
570	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
571	# (not needed with mfs /tmp, but doesn't hurt there...)
572	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
573		find -d . ! -name . ! -name lost+found ! -name quota.user \
574		! -name quota.group -exec rm -rf -- {} \;)
575	echo '.'
576	;;
577esac
578
579# Remove X lock files, since they will prevent you from restarting X11
580# after a system crash.
581#
582rm -f /tmp/.X*-lock
583rm -fr /tmp/.X11-unix
584mkdir -m 1777 /tmp/.X11-unix
585
586# Snapshot any kernel -c changes back to disk here <someday>.
587# This has changed with ELF and /kernel.config.
588
589# Load LOMAC(4) security if wanted.
590case ${lomac_enable} in
591[Yy][Ee][Ss])
592	kldload mac_lomac >/dev/null 2>&1
593	;;
594esac
595
596echo -n 'Additional daemons:'
597
598# Start system logging and name service.  Named needs to start before syslogd
599# if you don't have a /etc/resolv.conf.
600#
601case ${syslogd_enable} in
602[Yy][Ee][Ss])
603	# Transitional symlink (for the next couple of years :) until all
604	# binaries have had a chance to move towards /var/run/log.
605	if [ ! -L /dev/log ]; then
606		# might complain for r/o root f/s
607		ln -sf /var/run/log /dev/log
608	fi
609
610	rm -f /var/run/log
611	echo -n ' syslogd';
612	${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
613	;;
614esac
615
616echo '.'
617
618# Build device name databases if we are not using DEVFS
619#
620if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
621	rm -f /var/run/dev.db
622else
623	dev_mkdb
624fi
625
626# $dumpdir should be a directory or a symbolic link
627# to the crash directory if core dumps are to be saved.
628#
629if [ "${dumpdev}" != 'NO' ]; then
630	case ${dumpdir} in
631	'')
632		dumpdir='/var/crash'
633		;;
634	[Nn][Oo])
635		dumpdir='NO'
636		;;
637	esac
638
639	if [ "${dumpdir}" != 'NO' ]; then
640		echo -n 'Checking for core dump: '
641		/sbin/savecore ${savecore_flags} "${dumpdir}"
642	fi
643fi
644
645if [ -n "${network_pass1_done}" ]; then
646	network_pass2
647fi
648
649# Enable/Check the quotas (must be after ypbind if using NIS)
650#
651case ${enable_quotas} in
652[Yy][Ee][Ss])
653	case ${check_quotas} in
654	[Yy][Ee][Ss])
655		echo -n 'Checking quotas:'
656		quotacheck -a
657		echo ' done.'
658		;;
659	esac
660
661	echo -n 'Enabling quotas:'
662	quotaon -a
663	echo ' done.'
664	;;
665esac
666
667if [ -n "${network_pass2_done}" ]; then
668	network_pass3
669fi
670
671# Check the password temp/lock file
672#
673if [ -e /etc/ptmp ]; then
674	logger -s -p auth.err \
675	"password file may be incorrect -- /etc/ptmp exists"
676fi
677
678case ${accounting_enable} in
679[Yy][Ee][Ss])
680	if [ -d /var/account ]; then
681		echo 'Turning on accounting:'
682		if [ ! -e /var/account/acct ]; then
683			touch /var/account/acct
684		fi
685		accton /var/account/acct
686	fi
687	;;
688esac
689
690# Make shared lib searching a little faster.  Leave /usr/lib first if you
691# add your own entries or you may come to grief.
692#
693ldconfig="/sbin/ldconfig"
694case ${ldconfig_insecure} in
695[Yy][Ee][Ss])
696	ldconfig="${ldconfig} -i"
697	;;
698esac
699if [ -x /sbin/ldconfig ]; then
700	_LDC=/usr/lib
701	for i in ${ldconfig_paths}; do
702		if [ -d "${i}" ]; then
703			_LDC="${_LDC} ${i}"
704		fi
705	done
706	echo 'ELF ldconfig path:' ${_LDC}
707	${ldconfig} ${_LDC}
708
709	# Legacy aout support for i386 only
710	case `sysctl -n hw.machine_arch` in
711	i386)
712		# Default the a.out ldconfig path.
713		: ${ldconfig_paths_aout=${ldconfig_paths}}
714		_LDC=/usr/lib/aout
715		for i in ${ldconfig_paths_aout}; do
716			if [ -d "${i}" ]; then
717				_LDC="${_LDC} ${i}"
718			fi
719		done
720		echo 'a.out ldconfig path:' ${_LDC}
721		${ldconfig} -aout ${_LDC}
722		;;
723	esac
724fi
725
726# Now start up miscellaneous daemons that don't belong anywhere else
727#
728echo -n 'Starting standard daemons:'
729case ${inetd_enable} in
730[Nn][Oo])
731	;;
732*)
733	echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
734	;;
735esac
736
737case ${cron_enable} in
738[Nn][Oo])
739	;;
740*)
741	echo -n ' cron';	${cron_program:-/usr/sbin/cron} ${cron_flags}
742	;;
743esac
744
745case ${lpd_enable} in
746[Yy][Ee][Ss])
747	echo -n ' printer';	${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
748	;;
749esac
750
751case ${sshd_enable} in
752[Yy][Ee][Ss])
753	if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
754		echo -n ' sshd';
755		${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
756	fi
757	;;
758esac
759
760case ${usbd_enable} in
761[Yy][Ee][Ss])
762	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
763	;;
764esac
765
766case ${mta_start_script} in
767/*)
768	if [ -r ${mta_start_script} ]; then
769		sh ${mta_start_script}
770	fi
771	;;
772esac
773
774echo '.'
775
776# Recover vi editor files.
777find /var/tmp/vi.recover ! -type f -a ! -type d -delete
778vibackup=`echo /var/tmp/vi.recover/vi.*`
779if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
780	echo -n 'Recovering vi editor sessions:'
781	for i in /var/tmp/vi.recover/vi.*; do
782		# Only test files that are readable.
783		if [ ! -r "${i}" ]; then
784			continue
785		fi
786
787		# Unmodified nvi editor backup files either have the
788		# execute bit set or are zero length.  Delete them.
789		if [ -x "${i}" -o ! -s "${i}" ]; then
790			rm -f "${i}"
791		fi
792	done
793
794	# It is possible to get incomplete recovery files, if the editor
795	# crashes at the right time.
796	virecovery=`echo /var/tmp/vi.recover/recover.*`
797	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
798		for i in /var/tmp/vi.recover/recover.*; do
799			# Only test files that are readable.
800			if [ ! -r "${i}" ]; then
801				continue
802			fi
803
804			# Delete any recovery files that are zero length,
805			# corrupted, or that have no corresponding backup file.
806			# Else send mail to the user.
807			recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
808			if [ -n "${recfile}" -a -s "${recfile}" ]; then
809				sendmail -t < "${i}"
810			else
811				rm -f "${i}"
812			fi
813		done
814	fi
815	echo '.'
816fi
817
818# Make a bounds file for msgs(1) if there isn't one already
819#
820if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
821	echo 0 > /var/msgs/bounds
822fi
823
824case ${update_motd} in
825[Nn][Oo] | '')
826	;;
827*)
828	if T=`mktemp /tmp/_motd.XXXXXX`; then
829		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
830		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
831		cmp -s ${T} /etc/motd || {
832			cp ${T} /etc/motd
833			chmod 644 /etc/motd
834		}
835		rm -f ${T}
836	fi
837	;;
838esac
839
840# Run rc.devfs if readable to customize devfs
841#
842if [ -r /etc/rc.devfs ]; then
843	sh /etc/rc.devfs
844fi
845
846# Configure implementation specific stuff
847#
848arch=`uname -p`
849if [ -r /etc/rc.${arch} ]; then
850	. /etc/rc.${arch}
851fi
852
853# Configure the system console
854#
855if [ -r /etc/rc.syscons ]; then
856	. /etc/rc.syscons
857fi
858
859echo -n 'Additional ABI support:'
860
861# Load the SysV IPC API if requested.
862case ${sysvipc_enable} in
863[Yy][Ee][Ss])
864	echo -n ' sysvipc'
865	kldload sysvmsg >/dev/null 2>&1
866	kldload sysvsem >/dev/null 2>&1
867	kldload sysvshm >/dev/null 2>&1
868	;;
869esac
870
871# Start the Linux binary compatibility if requested.
872#
873case ${linux_enable} in
874[Yy][Ee][Ss])
875	echo -n ' linux'
876	if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
877		kldload linux > /dev/null 2>&1
878	fi
879	if [ -x /compat/linux/sbin/ldconfig ]; then
880		/compat/linux/sbin/ldconfig
881	fi
882	;;
883esac
884
885# Start the SysVR4 binary emulation if requested.
886#
887case ${svr4_enable} in
888[Yy][Ee][Ss])
889	echo -n ' svr4';	kldload svr4 > /dev/null 2>&1
890	;;
891esac
892
893echo '.'
894
895# Do traditional (but rather obsolete) rc.local file if it exists.  If you
896# use this file and want to make it programmatic, source /etc/defaults/rc.conf
897# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
898# shown below.  Please do not put local extensions into /etc/rc itself.
899# Use /etc/rc.local
900#
901# ---- rc.local ----
902#	if [ -r /etc/defaults/rc.conf ]; then
903#		. /etc/defaults/rc.conf
904#		source_rc_confs
905#	elif [ -r /etc/rc.conf ]; then
906#		. /etc/rc.conf
907#	fi
908#
909#	... additional startup conditionals ...
910# ---- rc.local ----
911#
912if [ -r /etc/rc.local ]; then
913	echo -n 'Starting local daemons:'
914	sh /etc/rc.local
915	echo '.'
916fi
917
918# For each valid dir in $local_startup, search for init scripts matching *.sh
919#
920case ${local_startup} in
921[Nn][Oo] | '')
922	;;
923*)
924	echo -n 'Local package initialization:'
925	slist=""
926	if [ -z "${script_name_sep}" ]; then
927		script_name_sep=" "
928	fi
929	for dir in ${local_startup}; do
930		if [ -d "${dir}" ]; then
931			for script in ${dir}/*.sh; do
932				slist="${slist}${script_name_sep}${script}"
933			done
934		fi
935	done
936	script_save_sep="$IFS"
937	IFS="${script_name_sep}"
938	for script in ${slist}; do
939		if [ -x "${script}" ]; then
940			(set -T
941			trap 'exit 1' 2
942			${script} start)
943		elif [ -f "${script}" -o -L "${script}" ]; then
944			echo -n " (skipping ${script##*/}, not executable)"
945		fi
946	done
947	IFS="${script_save_sep}"
948	echo '.'
949	;;
950esac
951
952if [ -n "${network_pass3_done}" ]; then
953	network_pass4
954fi
955
956# Late pass to set variables we missed the first time
957#
958if [ -r /etc/rc.sysctl ]; then
959	sh /etc/rc.sysctl last
960fi
961
962# Raise kernel security level.  This should be done only after `fsck' has
963# repaired local filesystems if you want the securelevel to be greater than 1.
964#
965case ${kern_securelevel_enable} in
966[Yy][Ee][Ss])
967	if [ "${kern_securelevel}" -ge 0 ]; then
968		echo 'Raising kernel security level: '
969		sysctl kern.securelevel=${kern_securelevel}
970	fi
971	;;
972esac
973
974# Start background fsck checks if necessary
975case ${background_fsck} in
976[Yy][Ee][Ss])
977	bgfsck_msg='Starting background file system checks'
978	if [ ${background_fsck_delay:=0} -gt 0 ]; then
979		bgfsck_msg="${bgfsck_msg} in ${background_fsck_delay} seconds"
980	fi
981	echo "${bgfsck_msg}."
982
983	(sleep ${background_fsck_delay}; nice -4 fsck -B -p) 2>&1 | \
984	    logger -p daemon.notice &
985	;;
986esac
987
988echo ''
989
990date
991
992exit 0
993
994