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

Annotation of src/etc/rc, Revision 1.490

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