xref: /freebsd/libexec/rc/rc.d/dumpon (revision 19261079b74319502c6ffa1249920079f0f69a72)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: dumpon
7# BEFORE: disks
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="dumpon"
13desc="Dump kernel corefiles from swap to disk"
14start_cmd="dumpon_start"
15stop_cmd="dumpon_stop"
16
17dumpon_try()
18{
19	local flags
20
21	flags=${dumpon_flags}
22	if [ -n "${dumppubkey}" ]; then
23		warn "The dumppubkey variable is deprecated.  Use dumpon_flags."
24		flags="${flags} -k ${dumppubkey}"
25	fi
26	/sbin/dumpon ${flags} "${1}"
27	if [ $? -eq 0 ]; then
28		# Make a symlink in devfs for savecore
29		ln -fs "${1}" /dev/dumpdev
30		return 0
31	fi
32	warn "unable to specify $1 as a dump device"
33	return 1
34}
35
36dumpon_start()
37{
38	# Enable dumpdev so that savecore can see it. Enable it
39	# early so a crash early in the boot process can be caught.
40	#
41	case ${dumpdev} in
42	[Nn][Oo] | '')
43		;;
44	[Aa][Uu][Tt][Oo])
45		root_hold_wait
46		dev=$(/bin/kenv -q dumpdev)
47		if [ -n "${dev}" ] ; then
48			dumpon_try "${dev}"
49			return $?
50		fi
51		while read dev mp type more ; do
52			[ "${type}" = "swap" ] || continue
53			[ -c "${dev}" ] || continue
54			dumpon_try "${dev}" 2>/dev/null && return 0
55		done </etc/fstab
56		echo "No suitable dump device was found." 1>&2
57		return 1
58		;;
59	*)
60		root_hold_wait
61		dumpon_try "${dumpdev}"
62		;;
63	esac
64}
65
66dumpon_stop()
67{
68	case ${dumpdev} in
69	[Nn][Oo] | '')
70		;;
71	*)
72		rm -f /dev/dumpdev
73		/sbin/dumpon -v off
74		;;
75	esac
76}
77
78load_rc_config $name
79run_rc_command "$1"
80