xref: /freebsd/libexec/rc/rc.d/savecore (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1#!/bin/sh
2#
3#
4
5# PROVIDE: savecore
6# REQUIRE: dumpon ddb syslogd
7# KEYWORD: nojail
8
9. /etc/rc.subr
10
11name="savecore"
12rcvar="savecore_enable"
13desc="Save a core dump of the operating system"
14start_cmd="savecore_start"
15start_precmd="savecore_prestart"
16stop_cmd=":"
17
18savecore_prestart()
19{
20	# Quit if we have no dump device
21	case ${dumpdev} in
22	[Nn][Oo])
23		debug 'No dump device. Quitting.'
24		return 1
25		;;
26	[Aa][Uu][Tt][Oo] | '')
27		if [ ! -L /dev/dumpdev ]; then
28			return 1
29		fi
30		dumpdev=`/bin/realpath /dev/dumpdev`
31		;;
32	esac
33
34	# If there is no crash directory set it now
35	case ${dumpdir} in
36	'')
37		dumpdir='/var/crash'
38		;;
39	[Nn][Oo])
40		dumpdir='NO'
41		;;
42	esac
43
44	if [ ! -c "${dumpdev}" ]; then
45		warn "Dump device does not exist.  Savecore not run."
46		return 1
47	fi
48
49	if [ ! -d "${dumpdir}" ]; then
50		warn "Dump directory does not exist.  Savecore not run."
51		return 1
52	fi
53	return 0
54}
55
56savecore_start()
57{
58	local dev
59
60	case "${dumpdev}" in
61	[Aa][Uu][Tt][Oo])
62		dev=
63		;;
64	*)
65		dev="${dumpdev}"
66		;;
67	esac
68
69	if savecore -C "${dev}" >/dev/null; then
70		savecore ${savecore_flags} ${dumpdir} ${dumpdev}
71		if checkyesno crashinfo_enable; then
72			${crashinfo_program} -b -d ${dumpdir}
73		fi
74		sync
75	else
76		startmsg 'No core dumps found.'
77	fi
78}
79
80load_rc_config $name
81run_rc_command "$1"
82