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