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

Annotation of src/etc/rc, Revision 1.508

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