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