xref: /titanic_44/usr/src/cmd/dumpadm/svc-dumpadm (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27
28. /lib/svc/share/smf_include.sh
29
30#
31# mksavedir
32# Make sure that $DUMPADM_SAVDIR is set and exists.
33#
34mksavedir ()
35{
36	[ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n`
37	[ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR
38}
39
40#
41# We haven't run savecore on a dump device yet
42#
43savedev=none
44
45#
46# If we previously crashed early in boot before dumpadm was used to configure
47# an alternate dump device, then the dump is in the primary swap partition,
48# which was configured as the dump device by the first swapadd early in boot.
49# Thus before we run dumpadm to configure the dump device, we first run
50# savecore to check the swap partition for a dump.
51#
52if [ -x /usr/bin/savecore ]; then
53	[ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf
54
55	if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then
56		/usr/bin/savecore $DUMPADM_SAVDIR
57		shift $#
58		set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'`
59		savedev=${3:-none}
60	fi
61else
62	echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2
63fi
64
65#
66# Now run dumpadm to configure the dump device based on the settings
67# previously saved by dumpadm.  See dumpadm(1m) for instructions on
68# how to modify the dump settings.
69#
70if [ -x /usr/sbin/dumpadm ]; then
71	/usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG
72else
73	echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2
74	exit $SMF_EXIT_ERR_CONFIG
75fi
76
77if [ -r /etc/dumpadm.conf ]; then
78	. /etc/dumpadm.conf
79else
80	echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2
81	exit $SMF_EXIT_ERR_CONFIG
82fi
83
84#
85# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again
86# because the dump device may have changed.  If the earlier savecore had
87# saved the dump, savecore will just exit immediately.
88#
89if [ "x$DUMPADM_ENABLE" != xno ]; then
90	if /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \
91	    >/dev/null 2>&1; then
92		#
93		# If the dump device is part of swap, we only need to run
94		# savecore a second time if the device is different from the
95		# swap device on which we initially ran savecore.
96		#
97		[ "x$savedev" != "x$DUMPADM_DEVICE" ] && \
98		    mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
99	else
100		#
101		# The dump device couldn't have been dedicated before we
102		# ran dumpadm, so we must execute savecore again.
103		#
104		mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
105	fi
106fi
107
108exit $SMF_EXIT_OK
109