10Sstevel@tonic-gate#!/sbin/sh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 61471Seschrock# Common Development and Distribution License (the "License"). 71471Seschrock# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 220Sstevel@tonic-gate# 23*12967Sgavin.maltby@oracle.com# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate# 250Sstevel@tonic-gate 260Sstevel@tonic-gate. /lib/svc/share/smf_include.sh 27*12967Sgavin.maltby@oracle.com. /lib/svc/share/fs_include.sh 280Sstevel@tonic-gate 290Sstevel@tonic-gate# 300Sstevel@tonic-gate# mksavedir 310Sstevel@tonic-gate# Make sure that $DUMPADM_SAVDIR is set and exists. 320Sstevel@tonic-gate# 330Sstevel@tonic-gatemksavedir () 340Sstevel@tonic-gate{ 350Sstevel@tonic-gate [ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n` 360Sstevel@tonic-gate [ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR 370Sstevel@tonic-gate} 380Sstevel@tonic-gate 390Sstevel@tonic-gate# 400Sstevel@tonic-gate# We haven't run savecore on a dump device yet 410Sstevel@tonic-gate# 420Sstevel@tonic-gatesavedev=none 430Sstevel@tonic-gate 440Sstevel@tonic-gate# 450Sstevel@tonic-gate# If we previously crashed early in boot before dumpadm was used to configure 460Sstevel@tonic-gate# an alternate dump device, then the dump is in the primary swap partition, 470Sstevel@tonic-gate# which was configured as the dump device by the first swapadd early in boot. 480Sstevel@tonic-gate# Thus before we run dumpadm to configure the dump device, we first run 49*12967Sgavin.maltby@oracle.com# savecore to check the swap partition for a dump; this is run in the 50*12967Sgavin.maltby@oracle.com# foreground to reduce the chances of overwriting the dump. 51*12967Sgavin.maltby@oracle.com# 52*12967Sgavin.maltby@oracle.com# This does not apply for zfs root systems that use a zvol for dump; 53*12967Sgavin.maltby@oracle.com# for such systems the dedicated dump device is appointed during startup 54*12967Sgavin.maltby@oracle.com# of the filesystem/usr:default instance before any swap is added. 55*12967Sgavin.maltby@oracle.com# Therefore we must check that the dump device is a swap device here - 56*12967Sgavin.maltby@oracle.com# if not then we'll run savecore here in the foreground and prevent 57*12967Sgavin.maltby@oracle.com# our dependent services coming online until we're done. 580Sstevel@tonic-gate# 59*12967Sgavin.maltby@oracle.com 60*12967Sgavin.maltby@oracle.comrootiszfs=0 61*12967Sgavin.maltby@oracle.comalreadydedicated=0 62*12967Sgavin.maltby@oracle.com 63*12967Sgavin.maltby@oracle.comreadmnttab / </etc/mnttab 64*12967Sgavin.maltby@oracle.comif [ "$fstype" = zfs ] ; then 65*12967Sgavin.maltby@oracle.com rootiszfs=1 66*12967Sgavin.maltby@oracle.com if [ -x /usr/sbin/dumpadm ]; then 67*12967Sgavin.maltby@oracle.com if /usr/sbin/dumpadm 2>/dev/null | grep "Dump device:" | \ 68*12967Sgavin.maltby@oracle.com grep '(dedicated)' > /dev/null 2>&1; then 69*12967Sgavin.maltby@oracle.com alreadydedicated=1 70*12967Sgavin.maltby@oracle.com fi 71*12967Sgavin.maltby@oracle.com fi 72*12967Sgavin.maltby@oracle.comfi 73*12967Sgavin.maltby@oracle.com 74*12967Sgavin.maltby@oracle.comif [ -x /usr/bin/savecore -a \ 75*12967Sgavin.maltby@oracle.com \( ! $rootiszfs -eq 1 -o $alreadydedicated -eq 0 \) ]; then 760Sstevel@tonic-gate [ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf 770Sstevel@tonic-gate 780Sstevel@tonic-gate if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then 790Sstevel@tonic-gate /usr/bin/savecore $DUMPADM_SAVDIR 800Sstevel@tonic-gate shift $# 810Sstevel@tonic-gate set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'` 820Sstevel@tonic-gate savedev=${3:-none} 83*12967Sgavin.maltby@oracle.com else 84*12967Sgavin.maltby@oracle.com # 85*12967Sgavin.maltby@oracle.com # dumpadm -n is in effect, but we can still run savecore 86*12967Sgavin.maltby@oracle.com # to raise an event with initial panic detail extracted 87*12967Sgavin.maltby@oracle.com # from the dump header. 88*12967Sgavin.maltby@oracle.com # 89*12967Sgavin.maltby@oracle.com /usr/bin/savecore -c 900Sstevel@tonic-gate fi 91*12967Sgavin.maltby@oracle.comfi 92*12967Sgavin.maltby@oracle.com 93*12967Sgavin.maltby@oracle.comif [ ! -x /usr/bin/savecore ]; then 940Sstevel@tonic-gate echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2 950Sstevel@tonic-gatefi 960Sstevel@tonic-gate 970Sstevel@tonic-gate# 980Sstevel@tonic-gate# Now run dumpadm to configure the dump device based on the settings 990Sstevel@tonic-gate# previously saved by dumpadm. See dumpadm(1m) for instructions on 1000Sstevel@tonic-gate# how to modify the dump settings. 1010Sstevel@tonic-gate# 1020Sstevel@tonic-gateif [ -x /usr/sbin/dumpadm ]; then 1030Sstevel@tonic-gate /usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG 1040Sstevel@tonic-gateelse 1050Sstevel@tonic-gate echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2 1060Sstevel@tonic-gate exit $SMF_EXIT_ERR_CONFIG 1070Sstevel@tonic-gatefi 1080Sstevel@tonic-gate 1090Sstevel@tonic-gateif [ -r /etc/dumpadm.conf ]; then 1100Sstevel@tonic-gate . /etc/dumpadm.conf 1110Sstevel@tonic-gateelse 1120Sstevel@tonic-gate echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2 1130Sstevel@tonic-gate exit $SMF_EXIT_ERR_CONFIG 1140Sstevel@tonic-gatefi 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate# 117*12967Sgavin.maltby@oracle.com# If the savecore executable is absent then we're done 118*12967Sgavin.maltby@oracle.com# 119*12967Sgavin.maltby@oracle.comif [ ! -x /usr/bin/savecore ]; then 120*12967Sgavin.maltby@oracle.com exit $SMF_EXIT_ERR_CONFIG 121*12967Sgavin.maltby@oracle.comfi 122*12967Sgavin.maltby@oracle.com 123*12967Sgavin.maltby@oracle.com# 1240Sstevel@tonic-gate# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again 1250Sstevel@tonic-gate# because the dump device may have changed. If the earlier savecore had 1260Sstevel@tonic-gate# saved the dump, savecore will just exit immediately. 1270Sstevel@tonic-gate# 128*12967Sgavin.maltby@oracle.com 129*12967Sgavin.maltby@oracle.comisswap=0 130*12967Sgavin.maltby@oracle.comswapchanged=0 131*12967Sgavin.maltby@oracle.comif /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \ 132*12967Sgavin.maltby@oracle.com >/dev/null 2>&1; then 133*12967Sgavin.maltby@oracle.com isswap=1 134*12967Sgavin.maltby@oracle.com if [ "x$savedev" != "x$DUMPADM_DEVICE" ]; then 135*12967Sgavin.maltby@oracle.com swapchanged=1 136*12967Sgavin.maltby@oracle.com fi 137*12967Sgavin.maltby@oracle.comfi 138*12967Sgavin.maltby@oracle.com 1390Sstevel@tonic-gateif [ "x$DUMPADM_ENABLE" != xno ]; then 140*12967Sgavin.maltby@oracle.com if [ $isswap -eq 1 ]; then 1410Sstevel@tonic-gate # 1420Sstevel@tonic-gate # If the dump device is part of swap, we only need to run 1430Sstevel@tonic-gate # savecore a second time if the device is different from the 1440Sstevel@tonic-gate # swap device on which we initially ran savecore. 1450Sstevel@tonic-gate # 146*12967Sgavin.maltby@oracle.com if [ $swapchanged -eq 1 ]; then 1470Sstevel@tonic-gate mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 148*12967Sgavin.maltby@oracle.com fi 1490Sstevel@tonic-gate else 1500Sstevel@tonic-gate # 1510Sstevel@tonic-gate # The dump device couldn't have been dedicated before we 1520Sstevel@tonic-gate # ran dumpadm, so we must execute savecore again. 1530Sstevel@tonic-gate # 1540Sstevel@tonic-gate mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 1550Sstevel@tonic-gate fi 156*12967Sgavin.maltby@oracle.comelse 157*12967Sgavin.maltby@oracle.com # 158*12967Sgavin.maltby@oracle.com # savecore not enabled. Check whether a valid dump is 159*12967Sgavin.maltby@oracle.com # present on the device and raise an event to signal that, 160*12967Sgavin.maltby@oracle.com # but avoid sending a duplicate event from the savecore -c 161*12967Sgavin.maltby@oracle.com # earlier. 162*12967Sgavin.maltby@oracle.com # 163*12967Sgavin.maltby@oracle.com if [ $isswap -eq 0 -o $swapchanged -eq 1 ]; then 164*12967Sgavin.maltby@oracle.com /usr/bin/savecore -c 165*12967Sgavin.maltby@oracle.com fi 1660Sstevel@tonic-gatefi 1670Sstevel@tonic-gate 1680Sstevel@tonic-gateexit $SMF_EXIT_OK 169