Annotation of src/etc/rc, Revision 1.573
1.573 ! deraadt 1: # $OpenBSD: rc,v 1.572 2023/10/01 20:15:23 naddy Exp $
1.1 deraadt 2:
1.450 rpe 3: # System startup script run by init on autoboot or after single-user.
4: # Output and error are redirected to console by init, and the console is the
5: # controlling terminal.
1.454 rpe 6:
7: # Turn off Strict Bourne shell.
8: set +o sh
1.1 deraadt 9:
1.131 millert 10: # Subroutines (have to come first).
11:
1.456 rpe 12: # Strip in- and whole-line comments from a file.
13: # Strip leading and trailing whitespace if IFS is set.
14: # Usage: stripcom /path/to/file
1.131 millert 15: stripcom() {
1.456 rpe 16: local _file=$1 _line
1.131 millert 17:
1.456 rpe 18: [[ -s $_file ]] || return
19:
20: while read _line ; do
21: _line=${_line%%#*}
22: [[ -n $_line ]] && print -r -- "$_line"
23: done <$_file
1.131 millert 24: }
25:
1.456 rpe 26: # Update resource limits based on login.conf settings.
27: # Usage: update_limit -flag capability
1.265 millert 28: update_limit() {
1.456 rpe 29: local _flag=$1 # ulimit flag
30: local _cap=$2 _val # login.conf capability and its value
31: local _suffix
32:
1.490 otto 33: for _suffix in {,-max,-cur}; do
1.456 rpe 34: _val=$(getcap -f /etc/login.conf -s ${_cap}${_suffix} daemon 2>/dev/null)
35: [[ -n $_val ]] || continue
36: [[ $_val == infinity ]] && _val=unlimited
37:
38: case $_suffix in
39: -cur) ulimit -S $_flag $_val
40: ;;
41: -max) ulimit -H $_flag $_val
42: ;;
43: *) ulimit $_flag $_val
44: return
45: ;;
46: esac
1.265 millert 47: done
48: }
49:
1.457 rpe 50: # Apply sysctl.conf(5) settings.
1.265 millert 51: sysctl_conf() {
1.520 bluhm 52: # do not use a pipe as limits would only be applied to the subshell
53: set -- $(stripcom /etc/sysctl.conf)
54: while [[ $# > 0 ]] ; do
55: sysctl "$1"
1.267 millert 56:
1.520 bluhm 57: case "$1" in
1.265 millert 58: kern.maxproc=*)
1.520 bluhm 59: update_limit -p maxproc
60: ;;
1.265 millert 61: kern.maxfiles=*)
1.520 bluhm 62: update_limit -n openfiles
63: ;;
1.265 millert 64: esac
1.520 bluhm 65: shift
1.265 millert 66: done
67: }
68:
1.457 rpe 69: # Apply mixerctl.conf(5) settings.
1.452 rpe 70: mixerctl_conf() {
1.457 rpe 71: stripcom /etc/mixerctl.conf |
72: while read _line; do
73: mixerctl -q "$_line" 2>/dev/null
1.265 millert 74: done
75: }
76:
1.457 rpe 77: # Apply wsconsctl.conf(5) settings.
1.452 rpe 78: wsconsctl_conf() {
1.457 rpe 79: [[ -x /sbin/wsconsctl ]] || return
1.267 millert 80:
1.457 rpe 81: stripcom /etc/wsconsctl.conf |
82: while read _line; do
1.458 rpe 83: eval "wsconsctl $_line"
1.267 millert 84: done
85: }
86:
1.495 rpe 87: # Push the old seed into the kernel, create a future seed and create a seed
88: # file for the boot-loader.
1.452 rpe 89: random_seed() {
1.427 bluhm 90: dd if=/var/db/host.random of=/dev/random bs=65536 count=1 status=none
91: chmod 600 /var/db/host.random
92: dd if=/dev/random of=/var/db/host.random bs=65536 count=1 status=none
93: dd if=/dev/random of=/etc/random.seed bs=512 count=1 status=none
94: chmod 600 /etc/random.seed
1.312 djm 95: }
96:
1.450 rpe 97: # Populate net.inet.(tcp|udp).baddynamic with the contents of /etc/services so
98: # as to avoid randomly allocating source ports that correspond to well-known
1.451 rpe 99: # services.
1.459 rpe 100: # Usage: fill_baddynamic tcp|udp
1.452 rpe 101: fill_baddynamic() {
1.390 halex 102: local _service=$1
1.318 djm 103: local _sysctl="net.inet.${_service}.baddynamic"
1.459 rpe 104:
1.390 halex 105: stripcom /etc/services |
106: {
1.459 rpe 107: _ban=
1.390 halex 108: while IFS=" /" read _name _port _srv _junk; do
1.459 rpe 109: [[ $_srv == $_service ]] || continue
110:
111: _ban="${_ban:+$_ban,}+$_port"
112:
1.390 halex 113: # Flush before argv gets too long
1.459 rpe 114: if ((${#_ban} > 1024)); then
115: sysctl -q "$_sysctl=$_ban"
116: _ban=
1.390 halex 117: fi
118: done
1.459 rpe 119: [[ -n $_ban ]] && sysctl -q "$_sysctl=$_ban"
1.390 halex 120: }
1.318 djm 121: }
122:
1.450 rpe 123: # Start daemon using the rc.d daemon control scripts.
1.451 rpe 124: # Usage: start_daemon daemon1 daemon2 daemon3
1.452 rpe 125: start_daemon() {
1.460 rpe 126: local _daemon
127:
128: for _daemon; do
129: eval "_do=\${${_daemon}_flags}"
130: [[ $_do != NO ]] && /etc/rc.d/${_daemon} start
1.353 robert 131: done
132: }
133:
1.469 tim 134: # Generate keys for isakmpd, iked and sshd if they don't exist yet.
1.452 rpe 135: make_keys() {
1.460 rpe 136: local _isakmpd_key=/etc/isakmpd/private/local.key
137: local _isakmpd_pub=/etc/isakmpd/local.pub
138: local _iked_key=/etc/iked/private/local.key
139: local _iked_pub=/etc/iked/local.pub
1.572 naddy 140: local _ssh_pub=/etc/ssh/ssh_host_ed25519_key.pub _show_ssh_fp=false
1.460 rpe 141:
142: if [[ ! -f $_isakmpd_key ]]; then
1.560 tobhe 143: echo -n "openssl: generating isakmpd RSA keys... "
1.460 rpe 144: if openssl genrsa -out $_isakmpd_key 2048 >/dev/null 2>&1 &&
145: chmod 600 $_isakmpd_key &&
146: openssl rsa -out $_isakmpd_pub -in $_isakmpd_key \
147: -pubout >/dev/null 2>&1; then
1.373 deraadt 148: echo done.
149: else
150: echo failed.
151: fi
152: fi
153:
1.460 rpe 154: if [[ ! -f $_iked_key ]]; then
1.560 tobhe 155: echo -n "openssl: generating iked ECDSA keys... "
156: if openssl ecparam -genkey -name prime256v1 -out $_iked_key >/dev/null 2>&1 &&
157: chmod 600 $_iked_key &&
158: openssl ec -out $_iked_pub -in $_iked_key \
159: -pubout >/dev/null 2>&1; then
160: echo done.
161: else
162: echo failed.
163: fi
1.373 deraadt 164: fi
165:
1.572 naddy 166: [[ -f $_ssh_pub ]] || _show_ssh_fp=true
1.373 deraadt 167: ssh-keygen -A
1.572 naddy 168: $_show_ssh_fp && ssh-keygen -lf $_ssh_pub |
169: (read sz fp comm type && echo "sshd: $type $fp")
1.524 florian 170:
171: if [[ ! -f /etc/soii.key ]]; then
1.525 rpe 172: openssl rand -hex 16 > /etc/soii.key &&
1.524 florian 173: chmod 600 /etc/soii.key && sysctl -q \
174: "net.inet6.ip6.soiikey=$(</etc/soii.key)"
175: fi
1.373 deraadt 176: }
177:
1.483 rpe 178: # Re-link libraries, placing the objects in a random order.
1.481 rpe 179: reorder_libs() {
1.521 rpe 180: local _error=false _dkdev _liba _libas _mp _ro_list _tmpdir
1.522 rpe 181: local _relink=/usr/share/relink
1.498 tb 182:
183: [[ $library_aslr == NO ]] && return
184:
1.521 rpe 185: # Skip if /usr/lib, /usr/libexec or /usr/share/relink are on nfs mounted
186: # filesystems, otherwise record which ones are mounted read-only.
1.533 kn 187: for _dkdev in $(df /usr/{lib,libexec} $_relink |
188: sed '1d;s/ .*//' | sort -u); do
189: _mp=$(mount -t ffs | grep "^$_dkdev") || return
190: if [[ $_mp == *read-only* ]]; then
191: _ro_list="$_ro_list ${_mp%% *}"
1.521 rpe 192: fi
193: done
1.484 rpe 194:
1.569 deraadt 195: echo 'reordering:'
1.523 tb 196:
1.556 jsg 197: # Remount the (read-only) filesystems in _ro_list as read-write.
1.521 rpe 198: for _mp in $_ro_list; do
199: if ! mount -u -w $_mp; then
1.565 cheloha 200: echo '(failed).'
1.481 rpe 201: return
202: fi
1.521 rpe 203: done
1.509 tb 204:
205: # Only choose the latest version of the libraries.
1.522 rpe 206: for _liba in $_relink/usr/lib/lib{c,crypto}; do
1.513 zhuk 207: _libas="$_libas $(ls $_liba.so.+([0-9.]).a | sort -rV | head -1)"
1.509 tb 208: done
1.481 rpe 209:
1.522 rpe 210: for _liba in $_relink/usr/libexec/ld.so.a $_libas; do
211: _tmpdir=$(mktemp -dq $_relink/_rebuild.XXXXXXXXXXXX) &&
1.517 rpe 212: (
213: set -o errexit
1.534 kn 214: _install='install -F -o root -g bin -m 0444'
1.517 rpe 215: _lib=${_liba##*/}
216: _lib=${_lib%.a}
1.522 rpe 217: _lib_dir=${_liba#$_relink}
1.523 tb 218: _lib_dir=${_lib_dir%/*}
1.517 rpe 219: cd $_tmpdir
220: ar x $_liba
221: if [[ $_lib == ld.so ]]; then
1.566 florian 222: echo " $_lib"
1.537 guenther 223: args="-g -x -e _dl_start \
1.517 rpe 224: --version-script=Symbols.map --shared -Bsymbolic \
1.537 guenther 225: --no-undefined"
226: [[ -f ld.script ]] && args="$args -T ld.script"
227: ld $args -o ld.so.test $(ls *.o | sort -R)
1.517 rpe 228: chmod u+x test-ld.so
229: [[ $(./test-ld.so ok) == './test-ld.so: ok!' ]]
230: $_install /usr/libexec/ld.so /usr/libexec/ld.so.save
1.521 rpe 231: $_install ld.so.test $_lib_dir/ld.so
1.517 rpe 232: else
1.566 florian 233: echo " ${_lib%%.*}"
1.541 naddy 234: cc -shared -o $_lib $(ls *.so | sort -R) $(<.ldadd)
1.475 deraadt 235: [[ -s $_lib ]] && file $_lib | fgrep -q 'shared object'
236: LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir awk 'BEGIN {exit 0}'
1.500 deraadt 237: LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir openssl \
238: x509 -in /etc/ssl/cert.pem -out /dev/null
1.521 rpe 239: $_install $_lib $_lib_dir/$_lib
1.517 rpe 240: fi
1.485 rpe 241: ) || { _error=true; break; }
1.475 deraadt 242: done
1.481 rpe 243:
1.569 deraadt 244: for _bin in $_relink/usr/sbin/sshd; do
245: _tmpdir=$(mktemp -dq $_relink/_rebuild.XXXXXXXXXXXX) &&
246: (
247: set -o errexit
248: cd $_tmpdir
249: _binn=${_bin##*/}
250: _bint=${_bin}/${_binn}.tar
251: if [[ -f $_bint ]]; then
252: echo " $_binn"
253: tar xf $_bint
1.573 ! deraadt 254: if [[ -f install.sh ]]; then
! 255: sh install.sh >/dev/null 2>&1
! 256: else
! 257: make -f Makefile.relink relink >/dev/null 2>&1
! 258: fi
1.569 deraadt 259: fi
260: ) || { _error=true; break; }
261: done
1.570 asou 262:
1.522 rpe 263: rm -rf $_relink/_rebuild.*
1.485 rpe 264:
1.481 rpe 265: # Restore previous mount state if it was changed.
1.521 rpe 266: for _mp in $_ro_list; do
267: mount -u -r $_mp || _error=true
268: done
1.482 deraadt 269:
1.485 rpe 270: if $_error; then
1.565 cheloha 271: echo '(failed).'
1.485 rpe 272: else
1.565 cheloha 273: echo '.'
1.485 rpe 274: fi
1.475 deraadt 275: }
276:
1.566 florian 277: # Read output of reorder_libs co-process and output on console.
278: wait_reorder_libs() {
279: local _line
1.568 kn 280:
281: [[ $library_aslr == NO ]] && return
1.567 kn 282:
1.566 florian 283: while IFS= read -p _line; do
284: echo -n "$_line"
285: done
286: echo
287: }
288:
1.483 rpe 289: # Run rc.* script and email output to root.
290: # Usage: run_upgrade_script firsttime|sysmerge
1.477 ajacouto 291: run_upgrade_script() {
292: local _suffix=$1
1.491 rpe 293:
1.477 ajacouto 294: [[ -n $_suffix ]] || return 1
1.491 rpe 295:
1.477 ajacouto 296: if [[ -f /etc/rc.$_suffix ]]; then
1.516 ajacouto 297: echo "running rc.$_suffix"
1.477 ajacouto 298: mv /etc/rc.$_suffix /etc/rc.$_suffix.run
299: . /etc/rc.$_suffix.run 2>&1 | tee /dev/tty |
300: mail -Es "$(hostname) rc.$_suffix output" root >/dev/null
301: fi
302: rm -f /etc/rc.$_suffix.run
303: }
304:
1.462 rpe 305: # Check filesystems, optionally by using a fsck(8) flag.
306: # Usage: do_fsck [-flag]
1.452 rpe 307: do_fsck() {
1.462 rpe 308: fsck -p "$@"
1.429 claudio 309: case $? in
1.462 rpe 310: 0) ;;
311: 2) exit 1
1.429 claudio 312: ;;
1.462 rpe 313: 4) echo "Rebooting..."
1.429 claudio 314: reboot
315: echo "Reboot failed; help!"
316: exit 1
317: ;;
1.462 rpe 318: 8) echo "Automatic file system check failed; help!"
1.429 claudio 319: exit 1
320: ;;
1.462 rpe 321: 12) echo "Boot interrupted."
1.429 claudio 322: exit 1
323: ;;
1.462 rpe 324: 130) # Interrupt before catcher installed.
1.429 claudio 325: exit 1
326: ;;
1.462 rpe 327: *) echo "Unknown error; help!"
1.429 claudio 328: exit 1
329: ;;
330: esac
331: }
332:
1.450 rpe 333: # End subroutines.
1.131 millert 334:
1.1 deraadt 335: stty status '^T'
336:
1.450 rpe 337: # Set shell to ignore SIGINT (2), but not children; shell catches SIGQUIT (3)
338: # and returns to single user after fsck.
1.1 deraadt 339: trap : 2
1.450 rpe 340: trap : 3 # Shouldn't be needed.
1.1 deraadt 341:
1.463 rpe 342: export HOME=/
343: export INRC=1
344: export PATH=/sbin:/bin:/usr/sbin:/usr/bin
1.544 deraadt 345:
346: # /etc/myname contains my symbolic name.
347: if [[ -f /etc/myname ]]; then
348: hostname "$(stripcom /etc/myname)"
349: fi
1.395 deraadt 350:
1.450 rpe 351: # Must set the domainname before rc.conf, so YP startup choices can be made.
1.563 miod 352: if [[ -s /etc/defaultdomain && -z "$(sysctl -n kern.domainname)" ]]; then
1.463 rpe 353: domainname "$(stripcom /etc/defaultdomain)"
1.395 deraadt 354: fi
1.108 deraadt 355:
1.495 rpe 356: # Get local functions from rc.subr to load rc.conf into scope.
1.428 robert 357: FUNCS_ONLY=1 . /etc/rc.d/rc.subr
358: _rc_parse_conf
1.343 robert 359:
1.495 rpe 360: # If executed with the 'shutdown' parameter by the halt, reboot or shutdown:
361: # - update seed files
362: # - execute the rc.d scripts specified by $pkg_scripts in reverse order
363: # - bring carp interfaces down gracefully
1.463 rpe 364: if [[ $1 == shutdown ]]; then
1.525 rpe 365: if echo 2>/dev/null >>/var/db/host.random ||
1.437 bluhm 366: echo 2>/dev/null >>/etc/random.seed; then
367: random_seed
368: else
369: echo warning: cannot write random seed to disk
370: fi
1.416 rpe 371:
1.469 tim 372: # If we are in secure level 0, assume single user mode.
1.463 rpe 373: if (($(sysctl -n kern.securelevel) == 0)); then
374: echo 'single user: not running shutdown scripts'
375: else
1.514 rpe 376: set -A _d -- $pkg_scripts
377: _i=${#_d[*]}
378: if ((_i)); then
1.413 deraadt 379: echo -n 'stopping package daemons:'
1.514 rpe 380: while ((--_i >= 0)); do
381: [[ -x /etc/rc.d/${_d[_i]} ]] &&
382: /etc/rc.d/${_d[_i]} stop
1.413 deraadt 383: done
1.527 sthen 384: echo '.'
385: fi
386:
387: if /etc/rc.d/vmd check > /dev/null; then
388: echo -n 'stopping VMs'
389: /etc/rc.d/vmd stop > /dev/null
1.413 deraadt 390: echo '.'
391: fi
392:
1.463 rpe 393: [[ -f /etc/rc.shutdown ]] && sh /etc/rc.shutdown
1.413 deraadt 394: fi
1.240 mcbride 395:
1.463 rpe 396: ifconfig | while read _if _junk; do
1.474 rpe 397: [[ $_if == carp+([0-9]): ]] && ifconfig ${_if%:} down
1.413 deraadt 398: done
1.246 mcbride 399:
1.108 deraadt 400: exit 0
1.1 deraadt 401: fi
1.98 jakob 402:
1.540 deraadt 403: # If bootblocks failed to give us random, try to cause some churn
404: (dmesg; sysctl hw.{uuid,serialno,sensors} ) >/dev/random 2>&1
405:
1.482 deraadt 406: # Add swap block-devices.
1.172 miod 407: swapctl -A -t blk
1.170 deraadt 408:
1.495 rpe 409: # Run filesystem check unless a /fastboot file exists.
1.463 rpe 410: if [[ -e /fastboot ]]; then
1.1 deraadt 411: echo "Fast boot: skipping disk checks."
1.463 rpe 412: elif [[ $1 == autoboot ]]; then
1.1 deraadt 413: echo "Automatic boot in progress: starting file system checks."
1.429 claudio 414: do_fsck
1.1 deraadt 415: fi
416:
1.495 rpe 417: # From now on, allow user to interrupt (^C) the boot process.
1.1 deraadt 418: trap "echo 'Boot interrupted.'; exit 1" 3
419:
1.495 rpe 420: # Unmount all filesystems except root.
1.1 deraadt 421: umount -a >/dev/null 2>&1
1.495 rpe 422:
423: # Mount all filesystems except those of type NFS and VND.
1.303 grunk 424: mount -a -t nonfs,vnd
1.177 deraadt 425:
1.495 rpe 426: # Re-mount the root filesystem read/writeable. (root on nfs requires this,
427: # others aren't hurt.)
428: mount -uw /
1.499 deraadt 429: chmod og-rwx /bsd
1.503 deraadt 430: ln -fh /bsd /bsd.booted
1.495 rpe 431:
432: rm -f /fastboot
433:
1.505 tedu 434: # Set flags on ttys.
1.1 deraadt 435: ttyflags -a
1.77 angelos 436:
1.464 rpe 437: # Set keyboard encoding.
438: if [[ -x /sbin/kbd && -s /etc/kbdtype ]]; then
1.541 naddy 439: kbd "$(</etc/kbdtype)"
1.252 mcbride 440: fi
441:
1.279 deraadt 442: wsconsctl_conf
443:
1.464 rpe 444: # Set initial temporary pf rule set.
445: if [[ $pf != NO ]]; then
1.511 rpe 446: RULES="
1.510 rpe 447: block all
448: pass on lo0
449: pass in proto tcp from any to any port ssh keep state
450: pass out proto { tcp, udp } from any to any port domain keep state
451: pass out inet proto icmp all icmp-type echoreq keep state
452: pass out inet proto udp from any port bootpc to any port bootps
1.511 rpe 453: pass in inet proto udp from any port bootps to any port bootpc"
1.510 rpe 454:
1.257 grange 455: if ifconfig lo0 inet6 >/dev/null 2>&1; then
1.510 rpe 456: RULES="$RULES
457: pass out inet6 proto icmp6 all icmp6-type neighbrsol
1.571 phessler 458: pass inet6 proto icmp6 all icmp6-type neighbradv no state
1.510 rpe 459: pass out inet6 proto icmp6 all icmp6-type routersol
460: pass in inet6 proto icmp6 all icmp6-type routeradv
461: pass out inet6 proto udp from any port dhcpv6-client to any port dhcpv6-server
462: pass in inet6 proto udp from any port dhcpv6-server to any port dhcpv6-client"
1.257 grange 463: fi
1.510 rpe 464:
465: RULES="$RULES
466: pass in proto carp keep state (no-sync)
467: pass out proto carp !received-on any keep state (no-sync)"
468:
1.545 naddy 469: if (($(sysctl -n vfs.mounts.nfs 2>/dev/null)+0 > 0)); then
1.511 rpe 470: # Don't kill NFS.
1.510 rpe 471: RULES="set reassemble yes no-df
472: $RULES
473: pass in proto { tcp, udp } from any port { sunrpc, nfsd } to any
474: pass out proto { tcp, udp } from any to any port { sunrpc, nfsd } !received-on any"
1.474 rpe 475: fi
1.511 rpe 476:
1.464 rpe 477: print -- "$RULES" | pfctl -f -
1.269 dhartmei 478: pfctl -e
1.176 kjell 479: fi
1.318 djm 480:
481: fill_baddynamic udp
482: fill_baddynamic tcp
1.176 kjell 483:
1.267 millert 484: sysctl_conf
1.260 jsg 485:
1.557 florian 486: mount -s /var >/dev/null 2>&1 # cannot be on NFS
487: mount -s /var/log >/dev/null 2>&1 # cannot be on NFS
1.564 deraadt 488: mount -s /usr >/dev/null 2>&1 # if NFS, fstab must use IP address
1.557 florian 489:
1.566 florian 490: reorder_libs 2>&1 |&
491:
1.557 florian 492: start_daemon slaacd dhcpleased resolvd >/dev/null 2>&1
1.501 florian 493:
1.1 deraadt 494: echo 'starting network'
1.464 rpe 495:
496: # Set carp interlock by increasing the demotion counter.
497: # Prevents carp from preempting until the system is booted.
1.536 tedu 498: ifconfig -g carp carpdemote 128
1.464 rpe 499:
1.439 ajacouto 500: sh /etc/netstart
1.542 deraadt 501:
1.557 florian 502: start_daemon unwind >/dev/null 2>&1
1.542 deraadt 503:
1.550 deraadt 504: random_seed
505:
1.566 florian 506: wait_reorder_libs
1.550 deraadt 507:
1.450 rpe 508: # Load pf rules and bring up pfsync interface.
1.464 rpe 509: if [[ $pf != NO ]]; then
510: if [[ -f /etc/pf.conf ]]; then
1.449 ajacouto 511: pfctl -f /etc/pf.conf
1.309 mpf 512: fi
1.464 rpe 513: if [[ -f /etc/hostname.pfsync0 ]]; then
1.435 deraadt 514: sh /etc/netstart pfsync0
1.367 deraadt 515: fi
1.176 kjell 516: fi
1.29 deraadt 517:
1.450 rpe 518: # Clean up left-over files.
1.492 jca 519: rm -f /etc/nologin /var/spool/lock/LCK.*
1.247 henning 520: (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1.196 beck 521: (cd /var/authpf && rm -rf -- *)
1.96 alex 522:
1.495 rpe 523: # Save a copy of the boot messages.
524: dmesg >/var/run/dmesg.boot
1.55 deraadt 525:
1.373 deraadt 526: make_keys
527:
1.379 deraadt 528: echo -n 'starting early daemons:'
1.543 tedu 529: start_daemon syslogd ldattach pflogd nsd unbound ntpd
1.429 claudio 530: start_daemon iscsid isakmpd iked sasyncd ldapd npppd
1.353 robert 531: echo '.'
1.280 hshoexer 532:
1.450 rpe 533: # Load IPsec rules.
1.464 rpe 534: if [[ $ipsec != NO && -f /etc/ipsec.conf ]]; then
535: ipsecctl -f /etc/ipsec.conf
1.40 provos 536: fi
1.1 deraadt 537:
1.379 deraadt 538: echo -n 'starting RPC daemons:'
1.562 deraadt 539: start_daemon portmap
1.464 rpe 540: if [[ -n $(domainname) ]]; then
1.562 deraadt 541: start_daemon ypldap ypserv ypbind
1.376 deraadt 542: fi
1.399 dlg 543: start_daemon mountd nfsd lockd statd amd
1.1 deraadt 544: echo '.'
1.58 deraadt 545:
1.464 rpe 546: # Check and mount remaining file systems and enable additional swap.
1.278 otto 547: mount -a
1.172 miod 548: swapctl -A -t noblk
1.429 claudio 549: do_fsck -N
550: mount -a -N
1.1 deraadt 551:
1.549 deraadt 552: # Build kvm(3) and /dev databases.
553: kvm_mkdb
554: dev_mkdb
555:
1.450 rpe 556: # /var/crash should be a directory or a symbolic link to the crash directory
557: # if core dumps are to be saved.
1.464 rpe 558: if [[ -d /var/crash ]]; then
559: savecore $savecore_flags /var/crash
1.487 rpe 560: fi
561:
562: # Store ACPI tables in /var/db/acpi to be used by sendbug(1).
563: if [[ -x /usr/sbin/acpidump ]]; then
1.530 kettenis 564: acpidump -q -o /var/db/acpi/
1.90 art 565: fi
566:
1.464 rpe 567: if [[ $check_quotas == YES ]]; then
1.41 downsj 568: echo -n 'checking quotas:'
569: quotacheck -a
570: echo ' done.'
571: quotaon -a
572: fi
1.464 rpe 573:
574: # Set proper permission for the tty device files.
1.101 deraadt 575: chmod 666 /dev/tty[pqrstuvwxyzPQRST]*
1.226 millert 576: chown root:wheel /dev/tty[pqrstuvwxyzPQRST]*
1.1 deraadt 577:
1.495 rpe 578: # Check for the password temp/lock file.
1.467 rpe 579: if [[ -f /etc/ptmp ]]; then
1.1 deraadt 580: logger -s -p auth.err \
1.376 deraadt 581: 'password file may be incorrect -- /etc/ptmp exists'
1.32 deraadt 582: fi
583:
1.49 millert 584: echo clearing /tmp
585:
1.450 rpe 586: # Prune quickly with one rm, then use find to clean up /tmp/[lqv]*
587: # (not needed with mfs /tmp, but doesn't hurt there...).
1.444 deraadt 588: (cd /tmp && rm -rf [a-km-pr-uw-zA-Z]*)
1.339 sthen 589: (cd /tmp &&
1.443 millert 590: find . -maxdepth 1 ! -name . ! -name lost+found ! -name quota.user \
1.444 deraadt 591: ! -name quota.group ! -name vi.recover -execdir rm -rf -- {} \;)
1.373 deraadt 592:
1.462 rpe 593: # Create Unix sockets directories for X if needed and make sure they have
594: # correct permissions.
595: [[ -d /usr/X11R6/lib ]] && mkdir -m 1777 /tmp/.{X11,ICE}-unix
1.203 hugh 596:
1.467 rpe 597: [[ -f /etc/rc.securelevel ]] && sh /etc/rc.securelevel
598:
1.450 rpe 599: # rc.securelevel did not specifically set -1 or 2, so select the default: 1.
1.467 rpe 600: (($(sysctl -n kern.securelevel) == 0)) && sysctl kern.securelevel=1
601:
1.1 deraadt 602:
1.450 rpe 603: # Patch /etc/motd.
1.467 rpe 604: if [[ ! -f /etc/motd ]]; then
1.34 deraadt 605: install -c -o root -g wheel -m 664 /dev/null /etc/motd
606: fi
1.467 rpe 607: if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then
1.451 rpe 608: sysctl -n kern.version | sed 1q >$T
1.494 schwarze 609: sed -n '/^$/,$p' </etc/motd >>$T
1.102 millert 610: cmp -s $T /etc/motd || cp $T /etc/motd
611: rm -f $T
612: fi
1.34 deraadt 613:
1.467 rpe 614: if [[ $accounting == YES ]]; then
615: [[ ! -f /var/account/acct ]] && touch /var/account/acct
616: echo 'turning on accounting'
617: accton /var/account/acct
1.1 deraadt 618: fi
619:
1.467 rpe 620: if [[ -x /sbin/ldconfig ]]; then
1.115 deraadt 621: echo 'creating runtime link editor directory cache.'
1.471 rpe 622: [[ -d /usr/local/lib ]] && shlib_dirs="/usr/local/lib $shlib_dirs"
1.467 rpe 623: [[ -d /usr/X11R6/lib ]] && shlib_dirs="/usr/X11R6/lib $shlib_dirs"
1.115 deraadt 624: ldconfig $shlib_dirs
1.231 millert 625: fi
626:
1.451 rpe 627: echo 'preserving editor files.'; /usr/libexec/vi.recover
1.244 markus 628:
1.477 ajacouto 629: # If rc.sysmerge exists, run it just once, and make sure it is deleted.
630: run_upgrade_script sysmerge
631:
1.353 robert 632: echo -n 'starting network daemons:'
1.555 claudio 633: start_daemon ldomd sshd snmpd ldpd ripd ospfd ospf6d bgpd ifstated
1.529 florian 634: start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd route6d
1.559 claudio 635: start_daemon rad hostapd lpd smtpd slowcgi bgplgd httpd ftpd
1.461 sthen 636: start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd
1.488 reyk 637: start_daemon rbootd mopd vmd spamd spamlogd sndiod
1.377 robert 638: echo '.'
1.335 deraadt 639:
1.450 rpe 640: # If rc.firsttime exists, run it just once, and make sure it is deleted.
1.477 ajacouto 641: run_upgrade_script firsttime
1.352 ajacouto 642:
1.450 rpe 643: # Run rc.d(8) scripts from packages.
1.467 rpe 644: if [[ -n $pkg_scripts ]]; then
1.352 ajacouto 645: echo -n 'starting package daemons:'
1.467 rpe 646: for _daemon in $pkg_scripts; do
647: if [[ -x /etc/rc.d/$_daemon ]]; then
648: start_daemon $_daemon
1.410 espie 649: else
1.467 rpe 650: echo -n " ${_daemon}(absent)"
1.410 espie 651: fi
1.352 ajacouto 652: done
653: echo '.'
654: fi
1.17 deraadt 655:
1.467 rpe 656: [[ -f /etc/rc.local ]] && sh /etc/rc.local
1.73 millert 657:
1.495 rpe 658: # Disable carp interlock.
1.536 tedu 659: ifconfig -g carp -carpdemote 128
1.286 mcbride 660:
1.379 deraadt 661: mixerctl_conf
1.467 rpe 662:
1.379 deraadt 663: echo -n 'starting local daemons:'
1.493 matthieu 664: start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xenodm
1.73 millert 665: echo '.'
1.502 rpe 666:
1.515 rpe 667: # Re-link the kernel, placing the objects in a random order.
668: # Replace current with relinked kernel and inform root about it.
669: /usr/libexec/reorder_kernel &
1.1 deraadt 670:
671: date
672: exit 0