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

Annotation of src/etc/rc, Revision 1.493

1.493   ! matthieu    1: #      $OpenBSD: rc,v 1.492 2016/12/27 09:17:52 jca 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
1.491     rpe       223:
1.477     ajacouto  224:        [[ -n $_suffix ]] || return 1
1.491     rpe       225:
1.477     ajacouto  226:        if [[ -f /etc/rc.$_suffix ]]; then
                    227:                mv /etc/rc.$_suffix /etc/rc.$_suffix.run
                    228:                . /etc/rc.$_suffix.run 2>&1 | tee /dev/tty |
                    229:                        mail -Es "$(hostname) rc.$_suffix output" root >/dev/null
                    230:        fi
                    231:        rm -f /etc/rc.$_suffix.run
                    232: }
                    233:
1.462     rpe       234: # Check filesystems, optionally by using a fsck(8) flag.
                    235: # Usage: do_fsck [-flag]
1.452     rpe       236: do_fsck() {
1.462     rpe       237:        fsck -p "$@"
1.429     claudio   238:        case $? in
1.462     rpe       239:        0)      ;;
                    240:        2)      exit 1
1.429     claudio   241:                ;;
1.462     rpe       242:        4)      echo "Rebooting..."
1.429     claudio   243:                reboot
                    244:                echo "Reboot failed; help!"
                    245:                exit 1
                    246:                ;;
1.462     rpe       247:        8)      echo "Automatic file system check failed; help!"
1.429     claudio   248:                exit 1
                    249:                ;;
1.462     rpe       250:        12)     echo "Boot interrupted."
1.429     claudio   251:                exit 1
                    252:                ;;
1.462     rpe       253:        130)    # Interrupt before catcher installed.
1.429     claudio   254:                exit 1
                    255:                ;;
1.462     rpe       256:        *)      echo "Unknown error; help!"
1.429     claudio   257:                exit 1
                    258:                ;;
                    259:        esac
                    260: }
                    261:
1.450     rpe       262: # End subroutines.
1.131     millert   263:
1.1       deraadt   264: stty status '^T'
                    265:
1.450     rpe       266: # Set shell to ignore SIGINT (2), but not children; shell catches SIGQUIT (3)
                    267: # and returns to single user after fsck.
1.1       deraadt   268: trap : 2
1.450     rpe       269: trap : 3       # Shouldn't be needed.
1.1       deraadt   270:
1.463     rpe       271: export HOME=/
                    272: export INRC=1
                    273: export PATH=/sbin:/bin:/usr/sbin:/usr/bin
1.395     deraadt   274:
1.450     rpe       275: # Must set the domainname before rc.conf, so YP startup choices can be made.
1.463     rpe       276: if [[ -s /etc/defaultdomain ]]; then
                    277:        domainname "$(stripcom /etc/defaultdomain)"
1.395     deraadt   278: fi
1.108     deraadt   279:
1.450     rpe       280: # Need to get local functions from rc.subr.
1.428     robert    281: FUNCS_ONLY=1 . /etc/rc.d/rc.subr
                    282:
1.450     rpe       283: # Load rc.conf into scope.
1.428     robert    284: _rc_parse_conf
1.343     robert    285:
1.463     rpe       286: if [[ $1 == shutdown ]]; then
1.437     bluhm     287:        if echo 2>/dev/null >>/var/db/host.random || \
                    288:            echo 2>/dev/null >>/etc/random.seed; then
                    289:                random_seed
                    290:        else
                    291:                echo warning: cannot write random seed to disk
                    292:        fi
1.416     rpe       293:
1.469     tim       294:        # If we are in secure level 0, assume single user mode.
1.463     rpe       295:        if (($(sysctl -n kern.securelevel) == 0)); then
                    296:                echo 'single user: not running shutdown scripts'
                    297:        else
1.421     schwarze  298:                pkg_scripts=${pkg_scripts%%*( )}
1.463     rpe       299:                if [[ -n $pkg_scripts ]]; then
1.413     deraadt   300:                        echo -n 'stopping package daemons:'
1.463     rpe       301:                        while [[ -n $pkg_scripts ]]; do
                    302:                                _d=${pkg_scripts##* }
                    303:                                pkg_scripts=${pkg_scripts%%*( )$_d}
                    304:                                [[ -x /etc/rc.d/$_d ]] && /etc/rc.d/$_d stop
1.413     deraadt   305:                        done
                    306:                        echo '.'
                    307:                fi
                    308:
1.463     rpe       309:                [[ -f /etc/rc.shutdown ]] && sh /etc/rc.shutdown
1.413     deraadt   310:        fi
1.240     mcbride   311:
1.450     rpe       312:        # Bring carp interfaces down gracefully.
1.463     rpe       313:        ifconfig | while read _if _junk; do
1.474     rpe       314:                [[ $_if == carp+([0-9]): ]] && ifconfig ${_if%:} down
1.413     deraadt   315:        done
1.246     mcbride   316:
1.108     deraadt   317:        exit 0
1.1       deraadt   318: fi
1.98      jakob     319:
1.482     deraadt   320: # Add swap block-devices.
1.172     miod      321: swapctl -A -t blk
1.170     deraadt   322:
1.463     rpe       323: if [[ -e /fastboot ]]; then
1.1       deraadt   324:        echo "Fast boot: skipping disk checks."
1.463     rpe       325: elif [[ $1 == autoboot ]]; then
1.1       deraadt   326:        echo "Automatic boot in progress: starting file system checks."
1.429     claudio   327:        do_fsck
1.1       deraadt   328: fi
                    329:
                    330: trap "echo 'Boot interrupted.'; exit 1" 3
                    331:
                    332: umount -a >/dev/null 2>&1
1.303     grunk     333: mount -a -t nonfs,vnd
1.450     rpe       334: mount -uw /            # root on nfs requires this, others aren't hurt.
1.1       deraadt   335: rm -f /fastboot                # XXX (root now writeable)
1.177     deraadt   336:
1.450     rpe       337: # Set flags on ttys.  (Do early, in case they use tty for SLIP in netstart.)
1.1       deraadt   338: echo 'setting tty flags'
                    339: ttyflags -a
1.77      angelos   340:
1.464     rpe       341: # Set keyboard encoding.
                    342: if [[ -x /sbin/kbd && -s /etc/kbdtype ]]; then
                    343:        kbd "$(cat /etc/kbdtype)"
1.252     mcbride   344: fi
                    345:
1.279     deraadt   346: wsconsctl_conf
                    347:
1.464     rpe       348: # Set initial temporary pf rule set.
                    349: if [[ $pf != NO ]]; then
1.211     mcbride   350:        RULES="block all"
1.228     henning   351:        RULES="$RULES\npass on lo0"
1.447     krw       352:        RULES="$RULES\npass in proto tcp from any to any port ssh keep state"
                    353:        RULES="$RULES\npass out proto { tcp, udp } from any to any port domain keep state"
1.215     camield   354:        RULES="$RULES\npass out inet proto icmp all icmp-type echoreq keep state"
1.420     claudio   355:        RULES="$RULES\npass out inet proto udp from any port bootpc to any port bootps"
                    356:        RULES="$RULES\npass in inet proto udp from any port bootps to any port bootpc"
1.257     grange    357:        if ifconfig lo0 inet6 >/dev/null 2>&1; then
1.258     itojun    358:                RULES="$RULES\npass out inet6 proto icmp6 all icmp6-type neighbrsol"
                    359:                RULES="$RULES\npass in inet6 proto icmp6 all icmp6-type neighbradv"
1.257     grange    360:                RULES="$RULES\npass out inet6 proto icmp6 all icmp6-type routersol"
                    361:                RULES="$RULES\npass in inet6 proto icmp6 all icmp6-type routeradv"
1.420     claudio   362:                RULES="$RULES\npass out inet6 proto udp from any port dhcpv6-client to any port dhcpv6-server"
                    363:                RULES="$RULES\npass in inet6 proto udp from any port dhcpv6-server to any port dhcpv6-client"
1.257     grange    364:        fi
1.424     henning   365:        RULES="$RULES\npass in proto carp keep state (no-sync)"
                    366:        RULES="$RULES\npass out proto carp !received-on any keep state (no-sync)"
1.474     rpe       367:        if [[ $(sysctl vfs.mounts.nfs 2>/dev/null) == *[1-9]* ]]; then
1.450     rpe       368:                # Don't kill NFS.
1.324     henning   369:                RULES="set reassemble yes no-df\n$RULES"
1.447     krw       370:                RULES="$RULES\npass in proto { tcp, udp } from any port { sunrpc, nfsd } to any"
                    371:                RULES="$RULES\npass out proto { tcp, udp } from any to any port { sunrpc, nfsd } !received-on any"
1.474     rpe       372:        fi
1.464     rpe       373:        print -- "$RULES" | pfctl -f -
1.269     dhartmei  374:        pfctl -e
1.176     kjell     375: fi
1.318     djm       376:
1.450     rpe       377: # Fill net.inet.(tcp|udp).baddynamic lists from /etc/services.
1.318     djm       378: fill_baddynamic udp
                    379: fill_baddynamic tcp
1.176     kjell     380:
1.267     millert   381: sysctl_conf
1.260     jsg       382:
1.1       deraadt   383: echo 'starting network'
1.464     rpe       384:
                    385: # Set carp interlock by increasing the demotion counter.
                    386: # Prevents carp from preempting until the system is booted.
1.289     henning   387: ifconfig -g carp carpdemote 128
1.464     rpe       388:
                    389: # Recover resolv.conf in case dhclient died hard.
                    390: if [[ -f /etc/resolv.conf.save ]]; then
1.334     deraadt   391:        mv -f /etc/resolv.conf.save /etc/resolv.conf
1.264     deraadt   392:        touch /etc/resolv.conf
                    393: fi
1.464     rpe       394:
1.439     ajacouto  395: sh /etc/netstart
1.464     rpe       396:
1.451     rpe       397: dmesg >/dev/random     # Any write triggers a rekey.
1.176     kjell     398:
1.450     rpe       399: # Load pf rules and bring up pfsync interface.
1.464     rpe       400: if [[ $pf != NO ]]; then
                    401:        if [[ -f /etc/pf.conf ]]; then
1.449     ajacouto  402:                pfctl -f /etc/pf.conf
1.309     mpf       403:        fi
1.464     rpe       404:        if [[ -f /etc/hostname.pfsync0 ]]; then
1.435     deraadt   405:                sh /etc/netstart pfsync0
1.367     deraadt   406:        fi
1.176     kjell     407: fi
1.1       deraadt   408:
1.278     otto      409: mount -s /usr >/dev/null 2>&1
                    410: mount -s /var >/dev/null 2>&1
1.180     deraadt   411:
1.389     deraadt   412: random_seed
1.475     deraadt   413:
1.481     rpe       414: reorder_libs
1.29      deraadt   415:
1.450     rpe       416: # Clean up left-over files.
1.492     jca       417: rm -f /etc/nologin /var/spool/lock/LCK.*
1.247     henning   418: (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1.196     beck      419: (cd /var/authpf && rm -rf -- *)
1.96      alex      420:
1.464     rpe       421: dmesg >/var/run/dmesg.boot     # Save a copy of the boot messages.
1.55      deraadt   422:
1.373     deraadt   423: make_keys
                    424:
1.379     deraadt   425: echo -n 'starting early daemons:'
1.473     rpe       426: start_daemon syslogd ldattach pflogd nsd rebound unbound ntpd
1.429     claudio   427: start_daemon iscsid isakmpd iked sasyncd ldapd npppd
1.353     robert    428: echo '.'
1.280     hshoexer  429:
1.450     rpe       430: # Load IPsec rules.
1.464     rpe       431: if [[ $ipsec != NO && -f /etc/ipsec.conf ]]; then
                    432:        ipsecctl -f /etc/ipsec.conf
1.40      provos    433: fi
1.1       deraadt   434:
1.379     deraadt   435: echo -n 'starting RPC daemons:'
1.399     dlg       436: start_daemon portmap ypldap
1.466     deraadt   437: rm -f /var/run/ypbind.lock
1.464     rpe       438: if [[ -n $(domainname) ]]; then
1.470     deraadt   439:        start_daemon ypserv ypbind
1.376     deraadt   440: fi
1.399     dlg       441: start_daemon mountd nfsd lockd statd amd
1.1       deraadt   442: echo '.'
1.58      deraadt   443:
1.464     rpe       444: # Check and mount remaining file systems and enable additional swap.
1.278     otto      445: mount -a
1.172     miod      446: swapctl -A -t noblk
1.429     claudio   447: do_fsck -N
                    448: mount -a -N
1.1       deraadt   449:
1.450     rpe       450: # /var/crash should be a directory or a symbolic link to the crash directory
                    451: # if core dumps are to be saved.
1.464     rpe       452: if [[ -d /var/crash ]]; then
                    453:        savecore $savecore_flags /var/crash
1.487     rpe       454: fi
                    455:
                    456: # Store ACPI tables in /var/db/acpi to be used by sendbug(1).
                    457: if [[ -x /usr/sbin/acpidump ]]; then
                    458:        acpidump -o /var/db/acpi/
1.90      art       459: fi
                    460:
1.464     rpe       461: if [[ $check_quotas == YES ]]; then
1.41      downsj    462:        echo -n 'checking quotas:'
                    463:        quotacheck -a
                    464:        echo ' done.'
                    465:        quotaon -a
                    466: fi
1.1       deraadt   467:
1.464     rpe       468: # Build kvm(3) and /dev databases.
                    469: kvm_mkdb
1.1       deraadt   470: dev_mkdb
1.464     rpe       471:
                    472: # Set proper permission for the tty device files.
1.101     deraadt   473: chmod 666 /dev/tty[pqrstuvwxyzPQRST]*
1.226     millert   474: chown root:wheel /dev/tty[pqrstuvwxyzPQRST]*
1.1       deraadt   475:
1.450     rpe       476: # Check the password temp/lock file.
1.467     rpe       477: if [[ -f /etc/ptmp ]]; then
1.1       deraadt   478:        logger -s -p auth.err \
1.376     deraadt   479:            'password file may be incorrect -- /etc/ptmp exists'
1.32      deraadt   480: fi
                    481:
1.49      millert   482: echo clearing /tmp
                    483:
1.450     rpe       484: # Prune quickly with one rm, then use find to clean up /tmp/[lqv]*
                    485: # (not needed with mfs /tmp, but doesn't hurt there...).
1.444     deraadt   486: (cd /tmp && rm -rf [a-km-pr-uw-zA-Z]*)
1.339     sthen     487: (cd /tmp &&
1.443     millert   488:     find . -maxdepth 1 ! -name . ! -name lost+found ! -name quota.user \
1.444     deraadt   489:        ! -name quota.group ! -name vi.recover -execdir rm -rf -- {} \;)
1.373     deraadt   490:
1.462     rpe       491: # Create Unix sockets directories for X if needed and make sure they have
                    492: # correct permissions.
                    493: [[ -d /usr/X11R6/lib ]] && mkdir -m 1777 /tmp/.{X11,ICE}-unix
1.203     hugh      494:
1.467     rpe       495: [[ -f /etc/rc.securelevel ]] && sh /etc/rc.securelevel
                    496:
1.450     rpe       497: # rc.securelevel did not specifically set -1 or 2, so select the default: 1.
1.467     rpe       498: (($(sysctl -n kern.securelevel) == 0)) && sysctl kern.securelevel=1
                    499:
1.1       deraadt   500:
1.450     rpe       501: # Patch /etc/motd.
1.467     rpe       502: if [[ ! -f /etc/motd ]]; then
1.34      deraadt   503:        install -c -o root -g wheel -m 664 /dev/null /etc/motd
                    504: fi
1.467     rpe       505: if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then
1.451     rpe       506:        sysctl -n kern.version | sed 1q >$T
                    507:        echo "" >>$T
                    508:        sed '1,/^$/d' </etc/motd >>$T
1.102     millert   509:        cmp -s $T /etc/motd || cp $T /etc/motd
                    510:        rm -f $T
                    511: fi
1.34      deraadt   512:
1.467     rpe       513: if [[ $accounting == YES ]]; then
                    514:        [[ ! -f /var/account/acct ]] && touch /var/account/acct
                    515:        echo 'turning on accounting'
                    516:        accton /var/account/acct
1.1       deraadt   517: fi
                    518:
1.467     rpe       519: if [[ -x /sbin/ldconfig ]]; then
1.115     deraadt   520:        echo 'creating runtime link editor directory cache.'
1.471     rpe       521:        [[ -d /usr/local/lib ]] && shlib_dirs="/usr/local/lib $shlib_dirs"
1.467     rpe       522:        [[ -d /usr/X11R6/lib ]] && shlib_dirs="/usr/X11R6/lib $shlib_dirs"
1.115     deraadt   523:        ldconfig $shlib_dirs
1.231     millert   524: fi
                    525:
1.451     rpe       526: echo 'preserving editor files.'; /usr/libexec/vi.recover
1.244     markus    527:
1.477     ajacouto  528: # If rc.sysmerge exists, run it just once, and make sure it is deleted.
                    529: run_upgrade_script sysmerge
                    530:
1.353     robert    531: echo -n 'starting network daemons:'
1.489     reyk      532: start_daemon ldomd sshd switchd snmpd ldpd ripd ospfd ospf6d bgpd ifstated
1.465     renato    533: start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd
1.127     itojun    534:
                    535: if ifconfig lo0 inet6 >/dev/null 2>&1; then
1.467     rpe       536:        if (($(sysctl -n net.inet6.ip6.forwarding) == 1)); then
1.376     deraadt   537:                start_daemon route6d rtadvd
1.127     itojun    538:        fi
1.281     reyk      539: fi
                    540:
1.442     matthieu  541: start_daemon hostapd lpd smtpd slowcgi httpd ftpd
1.461     sthen     542: start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd
1.488     reyk      543: start_daemon rbootd mopd vmd spamd spamlogd sndiod
1.377     robert    544: echo '.'
1.335     deraadt   545:
1.450     rpe       546: # If rc.firsttime exists, run it just once, and make sure it is deleted.
1.477     ajacouto  547: run_upgrade_script firsttime
1.352     ajacouto  548:
1.450     rpe       549: # Run rc.d(8) scripts from packages.
1.467     rpe       550: if [[ -n $pkg_scripts ]]; then
1.352     ajacouto  551:        echo -n 'starting package daemons:'
1.467     rpe       552:        for _daemon in $pkg_scripts; do
                    553:                if [[ -x /etc/rc.d/$_daemon ]]; then
                    554:                        start_daemon $_daemon
1.410     espie     555:                else
1.467     rpe       556:                        echo -n " ${_daemon}(absent)"
1.410     espie     557:                fi
1.352     ajacouto  558:        done
                    559:        echo '.'
                    560: fi
1.17      deraadt   561:
1.467     rpe       562: [[ -f /etc/rc.local ]] && sh /etc/rc.local
1.73      millert   563:
1.467     rpe       564: ifconfig -g carp -carpdemote 128       # Disable carp interlock.
1.286     mcbride   565:
1.379     deraadt   566: mixerctl_conf
1.467     rpe       567:
1.379     deraadt   568: echo -n 'starting local daemons:'
1.493   ! matthieu  569: start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xenodm
1.73      millert   570: echo '.'
1.1       deraadt   571:
                    572: date
                    573: exit 0