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