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