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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 24# 25 26. /lib/svc/share/smf_include.sh 27. /lib/svc/share/fs_include.sh 28 29# 30# mksavedir 31# Make sure that $DUMPADM_SAVDIR is set and exists. 32# 33mksavedir () 34{ 35 [ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n` 36 [ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR 37} 38 39# 40# We haven't run savecore on a dump device yet 41# 42savedev=none 43 44# 45# If we previously crashed early in boot before dumpadm was used to configure 46# an alternate dump device, then the dump is in the primary swap partition, 47# which was configured as the dump device by the first swapadd early in boot. 48# Thus before we run dumpadm to configure the dump device, we first run 49# savecore to check the swap partition for a dump; this is run in the 50# foreground to reduce the chances of overwriting the dump. 51# 52# This does not apply for zfs root systems that use a zvol for dump; 53# for such systems the dedicated dump device is appointed during startup 54# of the filesystem/usr:default instance before any swap is added. 55# Therefore we must check that the dump device is a swap device here - 56# if not then we'll run savecore here in the foreground and prevent 57# our dependent services coming online until we're done. 58# 59 60rootiszfs=0 61alreadydedicated=0 62 63readmnttab / </etc/mnttab 64if [ "$fstype" = zfs ] ; then 65 rootiszfs=1 66 if [ -x /usr/sbin/dumpadm ]; then 67 if /usr/sbin/dumpadm 2>/dev/null | grep "Dump device:" | \ 68 grep '(dedicated)' > /dev/null 2>&1; then 69 alreadydedicated=1 70 fi 71 fi 72fi 73 74if [ -x /usr/bin/savecore -a \ 75 \( ! $rootiszfs -eq 1 -o $alreadydedicated -eq 0 \) ]; then 76 [ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf 77 78 if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then 79 /usr/bin/savecore $DUMPADM_SAVDIR 80 shift $# 81 set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'` 82 savedev=${3:-none} 83 else 84 # 85 # dumpadm -n is in effect, but we can still run savecore 86 # to raise an event with initial panic detail extracted 87 # from the dump header. 88 # 89 /usr/bin/savecore -c 90 fi 91fi 92 93if [ ! -x /usr/bin/savecore ]; then 94 echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2 95fi 96 97# 98# Now run dumpadm to configure the dump device based on the settings 99# previously saved by dumpadm. See dumpadm(1m) for instructions on 100# how to modify the dump settings. 101# 102if [ -x /usr/sbin/dumpadm ]; then 103 /usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG 104else 105 echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2 106 exit $SMF_EXIT_ERR_CONFIG 107fi 108 109if [ -r /etc/dumpadm.conf ]; then 110 . /etc/dumpadm.conf 111else 112 echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2 113 exit $SMF_EXIT_ERR_CONFIG 114fi 115 116# 117# If the savecore executable is absent then we're done 118# 119if [ ! -x /usr/bin/savecore ]; then 120 exit $SMF_EXIT_ERR_CONFIG 121fi 122 123# 124# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again 125# because the dump device may have changed. If the earlier savecore had 126# saved the dump, savecore will just exit immediately. 127# 128 129isswap=0 130swapchanged=0 131if /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \ 132 >/dev/null 2>&1; then 133 isswap=1 134 if [ "x$savedev" != "x$DUMPADM_DEVICE" ]; then 135 swapchanged=1 136 fi 137fi 138 139if [ "x$DUMPADM_ENABLE" != xno ]; then 140 if [ $isswap -eq 1 ]; then 141 # 142 # If the dump device is part of swap, we only need to run 143 # savecore a second time if the device is different from the 144 # swap device on which we initially ran savecore. 145 # 146 if [ $swapchanged -eq 1 ]; then 147 mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 148 fi 149 else 150 # 151 # The dump device couldn't have been dedicated before we 152 # ran dumpadm, so we must execute savecore again. 153 # 154 mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 155 fi 156else 157 # 158 # savecore not enabled. Check whether a valid dump is 159 # present on the device and raise an event to signal that, 160 # but avoid sending a duplicate event from the savecore -c 161 # earlier. 162 # 163 if [ $isswap -eq 0 -o $swapchanged -eq 1 ]; then 164 /usr/bin/savecore -c 165 fi 166fi 167 168exit $SMF_EXIT_OK 169