[BACK]Return to rc CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/rc, Revision 1.523

1.523   ! tb          1: #      $OpenBSD: rc,v 1.522 2017/11/06 09:04:18 rpe 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
                    140:
                    141:        if [[ ! -f $_isakmpd_key ]]; then
                    142:                echo -n "openssl: generating isakmpd/iked RSA keys... "
                    143:                if openssl genrsa -out $_isakmpd_key 2048 >/dev/null 2>&1 &&
                    144:                        chmod 600 $_isakmpd_key &&
                    145:                        openssl rsa -out $_isakmpd_pub -in $_isakmpd_key \
                    146:                            -pubout >/dev/null 2>&1; then
1.373     deraadt   147:                        echo done.
                    148:                else
                    149:                        echo failed.
                    150:                fi
                    151:        fi
                    152:
1.460     rpe       153:        if [[ ! -f $_iked_key ]]; then
1.373     deraadt   154:                # Just copy the generated isakmpd key
1.460     rpe       155:                cp $_isakmpd_key $_iked_key
                    156:                chmod 600 $_iked_key
                    157:                cp $_isakmpd_pub $_iked_pub
1.373     deraadt   158:        fi
                    159:
                    160:        ssh-keygen -A
                    161: }
                    162:
1.483     rpe       163: # Re-link libraries, placing the objects in a random order.
1.481     rpe       164: reorder_libs() {
1.521     rpe       165:        local _error=false _dkdev _liba _libas _mp _ro_list _tmpdir
1.522     rpe       166:        local _relink=/usr/share/relink
1.498     tb        167:
                    168:        [[ $library_aslr == NO ]] && return
                    169:
1.521     rpe       170:        # Skip if /usr/lib, /usr/libexec or /usr/share/relink are on nfs mounted
                    171:        # filesystems, otherwise record which ones are mounted read-only.
                    172:        for _d in /usr/{lib,libexec,share/relink}; do
                    173:                _dkdev=$(df $_d | sed '1d;s/ .*//')
                    174:                _mp=$(mount | grep "^$_dkdev")
                    175:                [[ $_mp == *" type nfs "* ]] && return
                    176:                if [[ $_mp == *" type ffs "*"read-only"* &&
                    177:                        $_ro_list != *${_mp%% *}* ]]; then
                    178:                                _ro_list="$_ro_list ${_mp%% *}"
                    179:                fi
                    180:        done
1.484     rpe       181:
1.481     rpe       182:        echo -n 'reordering libraries:'
1.523   ! tb        183:
1.521     rpe       184:        # Remount the (read-only) filessystems in _ro_list as read-write.
                    185:        for _mp in $_ro_list; do
                    186:                if ! mount -u -w $_mp; then
1.481     rpe       187:                        echo ' failed.'
                    188:                        return
                    189:                fi
1.521     rpe       190:        done
1.509     tb        191:
                    192:        # Only choose the latest version of the libraries.
1.522     rpe       193:        for _liba in $_relink/usr/lib/lib{c,crypto}; do
1.513     zhuk      194:                _libas="$_libas $(ls $_liba.so.+([0-9.]).a | sort -rV | head -1)"
1.509     tb        195:        done
1.481     rpe       196:
1.522     rpe       197:        for _liba in $_relink/usr/libexec/ld.so.a $_libas; do
                    198:                _tmpdir=$(mktemp -dq $_relink/_rebuild.XXXXXXXXXXXX) &&
1.517     rpe       199:                (
                    200:                set -o errexit
                    201:                _install='install -F -S -o root -g bin -m 0444'
                    202:                _lib=${_liba##*/}
                    203:                _lib=${_lib%.a}
1.522     rpe       204:                _lib_dir=${_liba#$_relink}
1.523   ! tb        205:                _lib_dir=${_lib_dir%/*}
1.517     rpe       206:                cd $_tmpdir
                    207:                ar x $_liba
                    208:                if [[ $_lib == ld.so ]]; then
                    209:                        ld -g -x -e _dl_start \
                    210:                            --version-script=Symbols.map --shared -Bsymbolic \
                    211:                            --no-undefined -o ld.so.test $(ls *.o | sort -R)
                    212:                        chmod u+x test-ld.so
                    213:                        [[ $(./test-ld.so ok) == './test-ld.so: ok!' ]]
                    214:                        $_install /usr/libexec/ld.so /usr/libexec/ld.so.save
1.521     rpe       215:                        $_install ld.so.test $_lib_dir/ld.so
1.517     rpe       216:                else
1.475     deraadt   217:                        cc -shared -o $_lib $(ls *.so | sort -R) $(cat .ldadd)
                    218:                        [[ -s $_lib ]] && file $_lib | fgrep -q 'shared object'
                    219:                        LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir awk 'BEGIN {exit 0}'
1.500     deraadt   220:                        LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir openssl \
                    221:                            x509 -in /etc/ssl/cert.pem -out /dev/null
1.521     rpe       222:                        $_install $_lib $_lib_dir/$_lib
1.517     rpe       223:                fi
1.485     rpe       224:                ) || { _error=true; break; }
1.475     deraadt   225:        done
1.481     rpe       226:
1.522     rpe       227:        rm -rf $_relink/_rebuild.*
1.485     rpe       228:
1.481     rpe       229:        # Restore previous mount state if it was changed.
1.521     rpe       230:        for _mp in $_ro_list; do
                    231:                mount -u -r $_mp || _error=true
                    232:        done
1.482     deraadt   233:
1.485     rpe       234:        if $_error; then
                    235:                echo ' failed.'
                    236:        else
                    237:                echo ' done.'
                    238:        fi
1.475     deraadt   239: }
                    240:
1.483     rpe       241: # Run rc.* script and email output to root.
                    242: # Usage: run_upgrade_script firsttime|sysmerge
1.477     ajacouto  243: run_upgrade_script() {
                    244:        local _suffix=$1
1.491     rpe       245:
1.477     ajacouto  246:        [[ -n $_suffix ]] || return 1
1.491     rpe       247:
1.477     ajacouto  248:        if [[ -f /etc/rc.$_suffix ]]; then
1.516     ajacouto  249:                echo "running rc.$_suffix"
1.477     ajacouto  250:                mv /etc/rc.$_suffix /etc/rc.$_suffix.run
                    251:                . /etc/rc.$_suffix.run 2>&1 | tee /dev/tty |
                    252:                        mail -Es "$(hostname) rc.$_suffix output" root >/dev/null
                    253:        fi
                    254:        rm -f /etc/rc.$_suffix.run
                    255: }
                    256:
1.462     rpe       257: # Check filesystems, optionally by using a fsck(8) flag.
                    258: # Usage: do_fsck [-flag]
1.452     rpe       259: do_fsck() {
1.462     rpe       260:        fsck -p "$@"
1.429     claudio   261:        case $? in
1.462     rpe       262:        0)      ;;
                    263:        2)      exit 1
1.429     claudio   264:                ;;
1.462     rpe       265:        4)      echo "Rebooting..."
1.429     claudio   266:                reboot
                    267:                echo "Reboot failed; help!"
                    268:                exit 1
                    269:                ;;
1.462     rpe       270:        8)      echo "Automatic file system check failed; help!"
1.429     claudio   271:                exit 1
                    272:                ;;
1.462     rpe       273:        12)     echo "Boot interrupted."
1.429     claudio   274:                exit 1
                    275:                ;;
1.462     rpe       276:        130)    # Interrupt before catcher installed.
1.429     claudio   277:                exit 1
                    278:                ;;
1.462     rpe       279:        *)      echo "Unknown error; help!"
1.429     claudio   280:                exit 1
                    281:                ;;
                    282:        esac
                    283: }
                    284:
1.450     rpe       285: # End subroutines.
1.131     millert   286:
1.1       deraadt   287: stty status '^T'
                    288:
1.450     rpe       289: # Set shell to ignore SIGINT (2), but not children; shell catches SIGQUIT (3)
                    290: # and returns to single user after fsck.
1.1       deraadt   291: trap : 2
1.450     rpe       292: trap : 3       # Shouldn't be needed.
1.1       deraadt   293:
1.463     rpe       294: export HOME=/
                    295: export INRC=1
                    296: export PATH=/sbin:/bin:/usr/sbin:/usr/bin
1.395     deraadt   297:
1.450     rpe       298: # Must set the domainname before rc.conf, so YP startup choices can be made.
1.463     rpe       299: if [[ -s /etc/defaultdomain ]]; then
                    300:        domainname "$(stripcom /etc/defaultdomain)"
1.395     deraadt   301: fi
1.108     deraadt   302:
1.495     rpe       303: # Get local functions from rc.subr to load rc.conf into scope.
1.428     robert    304: FUNCS_ONLY=1 . /etc/rc.d/rc.subr
                    305: _rc_parse_conf
1.343     robert    306:
1.495     rpe       307: # If executed with the 'shutdown' parameter by the halt, reboot or shutdown:
                    308: # - update seed files
                    309: # - execute the rc.d scripts specified by $pkg_scripts in reverse order
                    310: # - bring carp interfaces down gracefully
1.463     rpe       311: if [[ $1 == shutdown ]]; then
1.437     bluhm     312:        if echo 2>/dev/null >>/var/db/host.random || \
                    313:            echo 2>/dev/null >>/etc/random.seed; then
                    314:                random_seed
                    315:        else
                    316:                echo warning: cannot write random seed to disk
                    317:        fi
1.416     rpe       318:
1.469     tim       319:        # If we are in secure level 0, assume single user mode.
1.463     rpe       320:        if (($(sysctl -n kern.securelevel) == 0)); then
                    321:                echo 'single user: not running shutdown scripts'
                    322:        else
1.514     rpe       323:                set -A _d -- $pkg_scripts
                    324:                _i=${#_d[*]}
                    325:                if ((_i)); then
1.413     deraadt   326:                        echo -n 'stopping package daemons:'
1.514     rpe       327:                        while ((--_i >= 0)); do
                    328:                                [[ -x /etc/rc.d/${_d[_i]} ]] &&
                    329:                                        /etc/rc.d/${_d[_i]} stop
1.413     deraadt   330:                        done
                    331:                        echo '.'
                    332:                fi
                    333:
1.463     rpe       334:                [[ -f /etc/rc.shutdown ]] && sh /etc/rc.shutdown
1.413     deraadt   335:        fi
1.240     mcbride   336:
1.463     rpe       337:        ifconfig | while read _if _junk; do
1.474     rpe       338:                [[ $_if == carp+([0-9]): ]] && ifconfig ${_if%:} down
1.413     deraadt   339:        done
1.246     mcbride   340:
1.108     deraadt   341:        exit 0
1.1       deraadt   342: fi
1.98      jakob     343:
1.482     deraadt   344: # Add swap block-devices.
1.172     miod      345: swapctl -A -t blk
1.170     deraadt   346:
1.495     rpe       347: # Run filesystem check unless a /fastboot file exists.
1.463     rpe       348: if [[ -e /fastboot ]]; then
1.1       deraadt   349:        echo "Fast boot: skipping disk checks."
1.463     rpe       350: elif [[ $1 == autoboot ]]; then
1.1       deraadt   351:        echo "Automatic boot in progress: starting file system checks."
1.429     claudio   352:        do_fsck
1.1       deraadt   353: fi
                    354:
1.495     rpe       355: # From now on, allow user to interrupt (^C) the boot process.
1.1       deraadt   356: trap "echo 'Boot interrupted.'; exit 1" 3
                    357:
1.495     rpe       358: # Unmount all filesystems except root.
1.1       deraadt   359: umount -a >/dev/null 2>&1
1.495     rpe       360:
                    361: # Mount all filesystems except those of type NFS and VND.
1.303     grunk     362: mount -a -t nonfs,vnd
1.177     deraadt   363:
1.495     rpe       364: # Re-mount the root filesystem read/writeable. (root on nfs requires this,
                    365: # others aren't hurt.)
                    366: mount -uw /
1.499     deraadt   367: chmod og-rwx /bsd
1.503     deraadt   368: ln -fh /bsd /bsd.booted
1.495     rpe       369:
                    370: rm -f /fastboot
                    371:
1.505     tedu      372: # Set flags on ttys.
1.1       deraadt   373: echo 'setting tty flags'
                    374: ttyflags -a
1.77      angelos   375:
1.464     rpe       376: # Set keyboard encoding.
                    377: if [[ -x /sbin/kbd && -s /etc/kbdtype ]]; then
                    378:        kbd "$(cat /etc/kbdtype)"
1.252     mcbride   379: fi
                    380:
1.279     deraadt   381: wsconsctl_conf
                    382:
1.464     rpe       383: # Set initial temporary pf rule set.
                    384: if [[ $pf != NO ]]; then
1.511     rpe       385:        RULES="
1.510     rpe       386:        block all
                    387:        pass on lo0
                    388:        pass in proto tcp from any to any port ssh keep state
                    389:        pass out proto { tcp, udp } from any to any port domain keep state
                    390:        pass out inet proto icmp all icmp-type echoreq keep state
                    391:        pass out inet proto udp from any port bootpc to any port bootps
1.511     rpe       392:        pass in inet proto udp from any port bootps to any port bootpc"
1.510     rpe       393:
1.257     grange    394:        if ifconfig lo0 inet6 >/dev/null 2>&1; then
1.510     rpe       395:                RULES="$RULES
                    396:                pass out inet6 proto icmp6 all icmp6-type neighbrsol
                    397:                pass in inet6 proto icmp6 all icmp6-type neighbradv
                    398:                pass out inet6 proto icmp6 all icmp6-type routersol
                    399:                pass in inet6 proto icmp6 all icmp6-type routeradv
                    400:                pass out inet6 proto udp from any port dhcpv6-client to any port dhcpv6-server
                    401:                pass in inet6 proto udp from any port dhcpv6-server to any port dhcpv6-client"
1.257     grange    402:        fi
1.510     rpe       403:
                    404:        RULES="$RULES
                    405:        pass in proto carp keep state (no-sync)
                    406:        pass out proto carp !received-on any keep state (no-sync)"
                    407:
1.512     rpe       408:        if (($(sysctl -n vfs.mounts.nfs 2>/dev/null) > 0)); then
1.511     rpe       409:                # Don't kill NFS.
1.510     rpe       410:                RULES="set reassemble yes no-df
                    411:                $RULES
                    412:                pass in proto { tcp, udp } from any port { sunrpc, nfsd } to any
                    413:                pass out proto { tcp, udp } from any to any port { sunrpc, nfsd } !received-on any"
1.474     rpe       414:        fi
1.511     rpe       415:
1.464     rpe       416:        print -- "$RULES" | pfctl -f -
1.269     dhartmei  417:        pfctl -e
1.176     kjell     418: fi
1.318     djm       419:
                    420: fill_baddynamic udp
                    421: fill_baddynamic tcp
1.176     kjell     422:
1.267     millert   423: sysctl_conf
1.260     jsg       424:
1.501     florian   425: start_daemon slaacd >/dev/null 2>&1
                    426:
1.1       deraadt   427: echo 'starting network'
1.464     rpe       428:
                    429: # Set carp interlock by increasing the demotion counter.
                    430: # Prevents carp from preempting until the system is booted.
1.289     henning   431: ifconfig -g carp carpdemote 128
1.464     rpe       432:
1.439     ajacouto  433: sh /etc/netstart
1.464     rpe       434:
1.495     rpe       435: # Any write triggers a rekey.
                    436: dmesg >/dev/random
1.176     kjell     437:
1.450     rpe       438: # Load pf rules and bring up pfsync interface.
1.464     rpe       439: if [[ $pf != NO ]]; then
                    440:        if [[ -f /etc/pf.conf ]]; then
1.449     ajacouto  441:                pfctl -f /etc/pf.conf
1.309     mpf       442:        fi
1.464     rpe       443:        if [[ -f /etc/hostname.pfsync0 ]]; then
1.435     deraadt   444:                sh /etc/netstart pfsync0
1.367     deraadt   445:        fi
1.176     kjell     446: fi
1.1       deraadt   447:
1.278     otto      448: mount -s /usr >/dev/null 2>&1
                    449: mount -s /var >/dev/null 2>&1
1.180     deraadt   450:
1.389     deraadt   451: random_seed
1.475     deraadt   452:
1.481     rpe       453: reorder_libs
1.29      deraadt   454:
1.450     rpe       455: # Clean up left-over files.
1.492     jca       456: rm -f /etc/nologin /var/spool/lock/LCK.*
1.247     henning   457: (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1.196     beck      458: (cd /var/authpf && rm -rf -- *)
1.96      alex      459:
1.495     rpe       460: # Save a copy of the boot messages.
                    461: dmesg >/var/run/dmesg.boot
1.55      deraadt   462:
1.373     deraadt   463: make_keys
                    464:
1.379     deraadt   465: echo -n 'starting early daemons:'
1.501     florian   466: start_daemon syslogd ldattach pflogd nsd rebound unbound ntpd
1.429     claudio   467: start_daemon iscsid isakmpd iked sasyncd ldapd npppd
1.353     robert    468: echo '.'
1.280     hshoexer  469:
1.450     rpe       470: # Load IPsec rules.
1.464     rpe       471: if [[ $ipsec != NO && -f /etc/ipsec.conf ]]; then
                    472:        ipsecctl -f /etc/ipsec.conf
1.40      provos    473: fi
1.1       deraadt   474:
1.379     deraadt   475: echo -n 'starting RPC daemons:'
1.399     dlg       476: start_daemon portmap ypldap
1.466     deraadt   477: rm -f /var/run/ypbind.lock
1.464     rpe       478: if [[ -n $(domainname) ]]; then
1.470     deraadt   479:        start_daemon ypserv ypbind
1.376     deraadt   480: fi
1.399     dlg       481: start_daemon mountd nfsd lockd statd amd
1.1       deraadt   482: echo '.'
1.58      deraadt   483:
1.464     rpe       484: # Check and mount remaining file systems and enable additional swap.
1.278     otto      485: mount -a
1.172     miod      486: swapctl -A -t noblk
1.429     claudio   487: do_fsck -N
                    488: mount -a -N
1.1       deraadt   489:
1.450     rpe       490: # /var/crash should be a directory or a symbolic link to the crash directory
                    491: # if core dumps are to be saved.
1.464     rpe       492: if [[ -d /var/crash ]]; then
                    493:        savecore $savecore_flags /var/crash
1.487     rpe       494: fi
                    495:
                    496: # Store ACPI tables in /var/db/acpi to be used by sendbug(1).
                    497: if [[ -x /usr/sbin/acpidump ]]; then
                    498:        acpidump -o /var/db/acpi/
1.90      art       499: fi
                    500:
1.464     rpe       501: if [[ $check_quotas == YES ]]; then
1.41      downsj    502:        echo -n 'checking quotas:'
                    503:        quotacheck -a
                    504:        echo ' done.'
                    505:        quotaon -a
                    506: fi
1.1       deraadt   507:
1.464     rpe       508: # Build kvm(3) and /dev databases.
                    509: kvm_mkdb
1.1       deraadt   510: dev_mkdb
1.464     rpe       511:
                    512: # Set proper permission for the tty device files.
1.101     deraadt   513: chmod 666 /dev/tty[pqrstuvwxyzPQRST]*
1.226     millert   514: chown root:wheel /dev/tty[pqrstuvwxyzPQRST]*
1.1       deraadt   515:
1.495     rpe       516: # Check for the password temp/lock file.
1.467     rpe       517: if [[ -f /etc/ptmp ]]; then
1.1       deraadt   518:        logger -s -p auth.err \
1.376     deraadt   519:            'password file may be incorrect -- /etc/ptmp exists'
1.32      deraadt   520: fi
                    521:
1.49      millert   522: echo clearing /tmp
                    523:
1.450     rpe       524: # Prune quickly with one rm, then use find to clean up /tmp/[lqv]*
                    525: # (not needed with mfs /tmp, but doesn't hurt there...).
1.444     deraadt   526: (cd /tmp && rm -rf [a-km-pr-uw-zA-Z]*)
1.339     sthen     527: (cd /tmp &&
1.443     millert   528:     find . -maxdepth 1 ! -name . ! -name lost+found ! -name quota.user \
1.444     deraadt   529:        ! -name quota.group ! -name vi.recover -execdir rm -rf -- {} \;)
1.373     deraadt   530:
1.462     rpe       531: # Create Unix sockets directories for X if needed and make sure they have
                    532: # correct permissions.
                    533: [[ -d /usr/X11R6/lib ]] && mkdir -m 1777 /tmp/.{X11,ICE}-unix
1.203     hugh      534:
1.467     rpe       535: [[ -f /etc/rc.securelevel ]] && sh /etc/rc.securelevel
                    536:
1.450     rpe       537: # rc.securelevel did not specifically set -1 or 2, so select the default: 1.
1.467     rpe       538: (($(sysctl -n kern.securelevel) == 0)) && sysctl kern.securelevel=1
                    539:
1.1       deraadt   540:
1.450     rpe       541: # Patch /etc/motd.
1.467     rpe       542: if [[ ! -f /etc/motd ]]; then
1.34      deraadt   543:        install -c -o root -g wheel -m 664 /dev/null /etc/motd
                    544: fi
1.467     rpe       545: if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then
1.451     rpe       546:        sysctl -n kern.version | sed 1q >$T
1.494     schwarze  547:        sed -n '/^$/,$p' </etc/motd >>$T
1.102     millert   548:        cmp -s $T /etc/motd || cp $T /etc/motd
                    549:        rm -f $T
                    550: fi
1.34      deraadt   551:
1.467     rpe       552: if [[ $accounting == YES ]]; then
                    553:        [[ ! -f /var/account/acct ]] && touch /var/account/acct
                    554:        echo 'turning on accounting'
                    555:        accton /var/account/acct
1.1       deraadt   556: fi
                    557:
1.467     rpe       558: if [[ -x /sbin/ldconfig ]]; then
1.115     deraadt   559:        echo 'creating runtime link editor directory cache.'
1.471     rpe       560:        [[ -d /usr/local/lib ]] && shlib_dirs="/usr/local/lib $shlib_dirs"
1.467     rpe       561:        [[ -d /usr/X11R6/lib ]] && shlib_dirs="/usr/X11R6/lib $shlib_dirs"
1.115     deraadt   562:        ldconfig $shlib_dirs
1.231     millert   563: fi
                    564:
1.451     rpe       565: echo 'preserving editor files.'; /usr/libexec/vi.recover
1.244     markus    566:
1.477     ajacouto  567: # If rc.sysmerge exists, run it just once, and make sure it is deleted.
                    568: run_upgrade_script sysmerge
                    569:
1.353     robert    570: echo -n 'starting network daemons:'
1.489     reyk      571: start_daemon ldomd sshd switchd snmpd ldpd ripd ospfd ospf6d bgpd ifstated
1.465     renato    572: start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd
1.127     itojun    573:
                    574: if ifconfig lo0 inet6 >/dev/null 2>&1; then
1.467     rpe       575:        if (($(sysctl -n net.inet6.ip6.forwarding) == 1)); then
1.376     deraadt   576:                start_daemon route6d rtadvd
1.127     itojun    577:        fi
1.281     reyk      578: fi
                    579:
1.442     matthieu  580: start_daemon hostapd lpd smtpd slowcgi httpd ftpd
1.461     sthen     581: start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd
1.488     reyk      582: start_daemon rbootd mopd vmd spamd spamlogd sndiod
1.377     robert    583: echo '.'
1.335     deraadt   584:
1.450     rpe       585: # If rc.firsttime exists, run it just once, and make sure it is deleted.
1.477     ajacouto  586: run_upgrade_script firsttime
1.352     ajacouto  587:
1.450     rpe       588: # Run rc.d(8) scripts from packages.
1.467     rpe       589: if [[ -n $pkg_scripts ]]; then
1.352     ajacouto  590:        echo -n 'starting package daemons:'
1.467     rpe       591:        for _daemon in $pkg_scripts; do
                    592:                if [[ -x /etc/rc.d/$_daemon ]]; then
                    593:                        start_daemon $_daemon
1.410     espie     594:                else
1.467     rpe       595:                        echo -n " ${_daemon}(absent)"
1.410     espie     596:                fi
1.352     ajacouto  597:        done
                    598:        echo '.'
                    599: fi
1.17      deraadt   600:
1.467     rpe       601: [[ -f /etc/rc.local ]] && sh /etc/rc.local
1.73      millert   602:
1.495     rpe       603: # Disable carp interlock.
                    604: ifconfig -g carp -carpdemote 128
1.286     mcbride   605:
1.379     deraadt   606: mixerctl_conf
1.467     rpe       607:
1.379     deraadt   608: echo -n 'starting local daemons:'
1.493     matthieu  609: start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xenodm
1.73      millert   610: echo '.'
1.502     rpe       611:
1.515     rpe       612: # Re-link the kernel, placing the objects in a random order.
                    613: # Replace current with relinked kernel and inform root about it.
                    614: /usr/libexec/reorder_kernel &
1.1       deraadt   615:
                    616: date
                    617: exit 0