10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# $FreeBSD$ 40696600cSBjoern A. Zeeb# 50696600cSBjoern A. Zeeb 60696600cSBjoern A. Zeeb# PROVIDE: dumpon 70696600cSBjoern A. Zeeb# BEFORE: disks 80696600cSBjoern A. Zeeb# KEYWORD: nojail 90696600cSBjoern A. Zeeb 100696600cSBjoern A. Zeeb. /etc/rc.subr 110696600cSBjoern A. Zeeb 120696600cSBjoern A. Zeebname="dumpon" 130696600cSBjoern A. Zeebdesc="Dump kernel corefiles from swap to disk" 140696600cSBjoern A. Zeebstart_cmd="dumpon_start" 150696600cSBjoern A. Zeebstop_cmd="dumpon_stop" 160696600cSBjoern A. Zeeb 170696600cSBjoern A. Zeebdumpon_try() 180696600cSBjoern A. Zeeb{ 190696600cSBjoern A. Zeeb local flags 200696600cSBjoern A. Zeeb 210696600cSBjoern A. Zeeb flags=${dumpon_flags} 220696600cSBjoern A. Zeeb if [ -n "${dumppubkey}" ]; then 230696600cSBjoern A. Zeeb warn "The dumppubkey variable is deprecated. Use dumpon_flags." 240696600cSBjoern A. Zeeb flags="${flags} -k ${dumppubkey}" 250696600cSBjoern A. Zeeb fi 260696600cSBjoern A. Zeeb /sbin/dumpon ${flags} "${1}" 270696600cSBjoern A. Zeeb if [ $? -eq 0 ]; then 280696600cSBjoern A. Zeeb # Make a symlink in devfs for savecore 290696600cSBjoern A. Zeeb ln -fs "${1}" /dev/dumpdev 300696600cSBjoern A. Zeeb return 0 310696600cSBjoern A. Zeeb fi 320696600cSBjoern A. Zeeb warn "unable to specify $1 as a dump device" 330696600cSBjoern A. Zeeb return 1 340696600cSBjoern A. Zeeb} 350696600cSBjoern A. Zeeb 3667e751f1SEd Mastedumpon_warn_unencrypted() 3767e751f1SEd Maste{ 3867e751f1SEd Maste if [ -n "${dumppubkey}" ]; then 3967e751f1SEd Maste return 4067e751f1SEd Maste fi 4167e751f1SEd Maste for flag in ${dumpon_flags}; do 4267e751f1SEd Maste if [ $flag = -k ]; then 4367e751f1SEd Maste return 4467e751f1SEd Maste fi 4567e751f1SEd Maste done 4667e751f1SEd Maste warn "Kernel dumps will be written to the swap partition without encryption." 4767e751f1SEd Maste} 4867e751f1SEd Maste 490696600cSBjoern A. Zeebdumpon_start() 500696600cSBjoern A. Zeeb{ 510696600cSBjoern A. Zeeb # Enable dumpdev so that savecore can see it. Enable it 520696600cSBjoern A. Zeeb # early so a crash early in the boot process can be caught. 530696600cSBjoern A. Zeeb # 540696600cSBjoern A. Zeeb case ${dumpdev} in 55*ccc806a0SEugene Grosbein [Nn][Oo]) 560696600cSBjoern A. Zeeb ;; 57*ccc806a0SEugene Grosbein [Aa][Uu][Tt][Oo] | '') 58f30f11f8SChuck Tuffli root_hold_wait 590696600cSBjoern A. Zeeb dev=$(/bin/kenv -q dumpdev) 600696600cSBjoern A. Zeeb if [ -n "${dev}" ] ; then 610696600cSBjoern A. Zeeb dumpon_try "${dev}" 620696600cSBjoern A. Zeeb return $? 630696600cSBjoern A. Zeeb fi 64*ccc806a0SEugene Grosbein if [ -z ${dumpdev} ] ; then 65*ccc806a0SEugene Grosbein return 66*ccc806a0SEugene Grosbein fi 670696600cSBjoern A. Zeeb while read dev mp type more ; do 680696600cSBjoern A. Zeeb [ "${type}" = "swap" ] || continue 6967e751f1SEd Maste case ${dev} in 7067e751f1SEd Maste *.bde|*.eli) 7167e751f1SEd Maste dumpon_warn_unencrypted 7267e751f1SEd Maste dev=${dev%.*} 7367e751f1SEd Maste ;; 7467e751f1SEd Maste esac 750696600cSBjoern A. Zeeb [ -c "${dev}" ] || continue 760696600cSBjoern A. Zeeb dumpon_try "${dev}" 2>/dev/null && return 0 770696600cSBjoern A. Zeeb done </etc/fstab 780696600cSBjoern A. Zeeb echo "No suitable dump device was found." 1>&2 790696600cSBjoern A. Zeeb return 1 800696600cSBjoern A. Zeeb ;; 810696600cSBjoern A. Zeeb *) 82f30f11f8SChuck Tuffli root_hold_wait 830696600cSBjoern A. Zeeb dumpon_try "${dumpdev}" 840696600cSBjoern A. Zeeb ;; 850696600cSBjoern A. Zeeb esac 860696600cSBjoern A. Zeeb} 870696600cSBjoern A. Zeeb 880696600cSBjoern A. Zeebdumpon_stop() 890696600cSBjoern A. Zeeb{ 900696600cSBjoern A. Zeeb case ${dumpdev} in 91*ccc806a0SEugene Grosbein [Nn][Oo]) 920696600cSBjoern A. Zeeb ;; 930696600cSBjoern A. Zeeb *) 940696600cSBjoern A. Zeeb rm -f /dev/dumpdev 950696600cSBjoern A. Zeeb /sbin/dumpon -v off 960696600cSBjoern A. Zeeb ;; 970696600cSBjoern A. Zeeb esac 980696600cSBjoern A. Zeeb} 990696600cSBjoern A. Zeeb 1000696600cSBjoern A. Zeebload_rc_config $name 1010696600cSBjoern A. Zeebrun_rc_command "$1" 102