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 36*67e751f1SEd Mastedumpon_warn_unencrypted() 37*67e751f1SEd Maste{ 38*67e751f1SEd Maste if [ -n "${dumppubkey}" ]; then 39*67e751f1SEd Maste return 40*67e751f1SEd Maste fi 41*67e751f1SEd Maste for flag in ${dumpon_flags}; do 42*67e751f1SEd Maste if [ $flag = -k ]; then 43*67e751f1SEd Maste return 44*67e751f1SEd Maste fi 45*67e751f1SEd Maste done 46*67e751f1SEd Maste warn "Kernel dumps will be written to the swap partition without encryption." 47*67e751f1SEd Maste} 48*67e751f1SEd 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 550696600cSBjoern A. Zeeb [Nn][Oo] | '') 560696600cSBjoern A. Zeeb ;; 570696600cSBjoern A. Zeeb [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 640696600cSBjoern A. Zeeb while read dev mp type more ; do 650696600cSBjoern A. Zeeb [ "${type}" = "swap" ] || continue 66*67e751f1SEd Maste case ${dev} in 67*67e751f1SEd Maste *.bde|*.eli) 68*67e751f1SEd Maste dumpon_warn_unencrypted 69*67e751f1SEd Maste dev=${dev%.*} 70*67e751f1SEd Maste ;; 71*67e751f1SEd Maste esac 720696600cSBjoern A. Zeeb [ -c "${dev}" ] || continue 730696600cSBjoern A. Zeeb dumpon_try "${dev}" 2>/dev/null && return 0 740696600cSBjoern A. Zeeb done </etc/fstab 750696600cSBjoern A. Zeeb echo "No suitable dump device was found." 1>&2 760696600cSBjoern A. Zeeb return 1 770696600cSBjoern A. Zeeb ;; 780696600cSBjoern A. Zeeb *) 79f30f11f8SChuck Tuffli root_hold_wait 800696600cSBjoern A. Zeeb dumpon_try "${dumpdev}" 810696600cSBjoern A. Zeeb ;; 820696600cSBjoern A. Zeeb esac 830696600cSBjoern A. Zeeb} 840696600cSBjoern A. Zeeb 850696600cSBjoern A. Zeebdumpon_stop() 860696600cSBjoern A. Zeeb{ 870696600cSBjoern A. Zeeb case ${dumpdev} in 880696600cSBjoern A. Zeeb [Nn][Oo] | '') 890696600cSBjoern A. Zeeb ;; 900696600cSBjoern A. Zeeb *) 910696600cSBjoern A. Zeeb rm -f /dev/dumpdev 920696600cSBjoern A. Zeeb /sbin/dumpon -v off 930696600cSBjoern A. Zeeb ;; 940696600cSBjoern A. Zeeb esac 950696600cSBjoern A. Zeeb} 960696600cSBjoern A. Zeeb 970696600cSBjoern A. Zeebload_rc_config $name 980696600cSBjoern A. Zeebrun_rc_command "$1" 99