summaryrefslogtreecommitdiff
path: root/usr/src/cmd/dumpadm/svc-dumpadm
blob: 022bbab3b74d1b90adcec6e1955e57cb49e25e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"%Z%%M%	%I%	%E% SMI"

. /lib/svc/share/smf_include.sh

#
# mksavedir
# Make sure that $DUMPADM_SAVDIR is set and exists.
#
mksavedir ()
{
	[ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n`
	[ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR
}

#
# We haven't run savecore on a dump device yet
#
savedev=none

#
# If we previously crashed early in boot before dumpadm was used to configure
# an alternate dump device, then the dump is in the primary swap partition,
# which was configured as the dump device by the first swapadd early in boot.
# Thus before we run dumpadm to configure the dump device, we first run
# savecore to check the swap partition for a dump.
#
if [ -x /usr/bin/savecore ]; then
	[ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf

	if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then
		/usr/bin/savecore $DUMPADM_SAVDIR
		shift $#
		set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'`
		savedev=${3:-none}
	fi
else
	echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2
fi

#
# Now run dumpadm to configure the dump device based on the settings
# previously saved by dumpadm.  See dumpadm(1m) for instructions on
# how to modify the dump settings.
#
if [ -x /usr/sbin/dumpadm ]; then
	/usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG
else
	echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2
	exit $SMF_EXIT_ERR_CONFIG
fi

if [ -r /etc/dumpadm.conf ]; then
	. /etc/dumpadm.conf
else
	echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2
	exit $SMF_EXIT_ERR_CONFIG
fi

#
# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again
# because the dump device may have changed.  If the earlier savecore had
# saved the dump, savecore will just exit immediately.
#
if [ "x$DUMPADM_ENABLE" != xno ]; then
	if /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \
	    >/dev/null 2>&1; then
		#
		# If the dump device is part of swap, we only need to run
		# savecore a second time if the device is different from the
		# swap device on which we initially ran savecore.
		#
		[ "x$savedev" != "x$DUMPADM_DEVICE" ] && \
		    mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
	else
		#
		# The dump device couldn't have been dedicated before we
		# ran dumpadm, so we must execute savecore again.
		#
		mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
	fi
fi

exit $SMF_EXIT_OK