17c478bd9Sstevel@tonic-gate#!/sbin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 67950274eSeschrock# Common Development and Distribution License (the "License"). 77950274eSeschrock# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23f6e214c7SGavin Maltby# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate# 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh 27f6e214c7SGavin Maltby. /lib/svc/share/fs_include.sh 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gate# mksavedir 317c478bd9Sstevel@tonic-gate# Make sure that $DUMPADM_SAVDIR is set and exists. 327c478bd9Sstevel@tonic-gate# 337c478bd9Sstevel@tonic-gatemksavedir () 347c478bd9Sstevel@tonic-gate{ 357c478bd9Sstevel@tonic-gate [ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n` 367c478bd9Sstevel@tonic-gate [ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR 377c478bd9Sstevel@tonic-gate} 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate# 407c478bd9Sstevel@tonic-gate# We haven't run savecore on a dump device yet 417c478bd9Sstevel@tonic-gate# 427c478bd9Sstevel@tonic-gatesavedev=none 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate# 457c478bd9Sstevel@tonic-gate# If we previously crashed early in boot before dumpadm was used to configure 467c478bd9Sstevel@tonic-gate# an alternate dump device, then the dump is in the primary swap partition, 477c478bd9Sstevel@tonic-gate# which was configured as the dump device by the first swapadd early in boot. 487c478bd9Sstevel@tonic-gate# Thus before we run dumpadm to configure the dump device, we first run 49f6e214c7SGavin Maltby# savecore to check the swap partition for a dump; this is run in the 50f6e214c7SGavin Maltby# foreground to reduce the chances of overwriting the dump. 517c478bd9Sstevel@tonic-gate# 52f6e214c7SGavin Maltby# This does not apply for zfs root systems that use a zvol for dump; 53f6e214c7SGavin Maltby# for such systems the dedicated dump device is appointed during startup 54f6e214c7SGavin Maltby# of the filesystem/usr:default instance before any swap is added. 55f6e214c7SGavin Maltby# Therefore we must check that the dump device is a swap device here - 56f6e214c7SGavin Maltby# if not then we'll run savecore here in the foreground and prevent 57f6e214c7SGavin Maltby# our dependent services coming online until we're done. 58f6e214c7SGavin Maltby# 59f6e214c7SGavin Maltby 60f6e214c7SGavin Maltbyrootiszfs=0 61f6e214c7SGavin Maltbyalreadydedicated=0 62f6e214c7SGavin Maltby 63f6e214c7SGavin Maltbyreadmnttab / </etc/mnttab 64f6e214c7SGavin Maltbyif [ "$fstype" = zfs ] ; then 65f6e214c7SGavin Maltby rootiszfs=1 66f6e214c7SGavin Maltby if [ -x /usr/sbin/dumpadm ]; then 67f6e214c7SGavin Maltby if /usr/sbin/dumpadm 2>/dev/null | grep "Dump device:" | \ 68f6e214c7SGavin Maltby grep '(dedicated)' > /dev/null 2>&1; then 69f6e214c7SGavin Maltby alreadydedicated=1 70f6e214c7SGavin Maltby fi 71f6e214c7SGavin Maltby fi 72f6e214c7SGavin Maltbyfi 73f6e214c7SGavin Maltby 74f6e214c7SGavin Maltbyif [ -x /usr/bin/savecore -a \ 75f6e214c7SGavin Maltby \( ! $rootiszfs -eq 1 -o $alreadydedicated -eq 0 \) ]; then 767c478bd9Sstevel@tonic-gate [ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then 797c478bd9Sstevel@tonic-gate /usr/bin/savecore $DUMPADM_SAVDIR 807c478bd9Sstevel@tonic-gate shift $# 817c478bd9Sstevel@tonic-gate set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'` 827c478bd9Sstevel@tonic-gate savedev=${3:-none} 837c478bd9Sstevel@tonic-gate else 84f6e214c7SGavin Maltby # 85f6e214c7SGavin Maltby # dumpadm -n is in effect, but we can still run savecore 86f6e214c7SGavin Maltby # to raise an event with initial panic detail extracted 87f6e214c7SGavin Maltby # from the dump header. 88f6e214c7SGavin Maltby # 89f6e214c7SGavin Maltby /usr/bin/savecore -c 90f6e214c7SGavin Maltby fi 91f6e214c7SGavin Maltbyfi 92f6e214c7SGavin Maltby 93f6e214c7SGavin Maltbyif [ ! -x /usr/bin/savecore ]; then 947c478bd9Sstevel@tonic-gate echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2 957c478bd9Sstevel@tonic-gatefi 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate# 987c478bd9Sstevel@tonic-gate# Now run dumpadm to configure the dump device based on the settings 99*bbf21555SRichard Lowe# previously saved by dumpadm. See dumpadm(8) for instructions on 1007c478bd9Sstevel@tonic-gate# how to modify the dump settings. 1017c478bd9Sstevel@tonic-gate# 1027c478bd9Sstevel@tonic-gateif [ -x /usr/sbin/dumpadm ]; then 1037c478bd9Sstevel@tonic-gate /usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG 1047c478bd9Sstevel@tonic-gateelse 1057c478bd9Sstevel@tonic-gate echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2 1067c478bd9Sstevel@tonic-gate exit $SMF_EXIT_ERR_CONFIG 1077c478bd9Sstevel@tonic-gatefi 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gateif [ -r /etc/dumpadm.conf ]; then 1107c478bd9Sstevel@tonic-gate . /etc/dumpadm.conf 1117c478bd9Sstevel@tonic-gateelse 1127c478bd9Sstevel@tonic-gate echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2 1137c478bd9Sstevel@tonic-gate exit $SMF_EXIT_ERR_CONFIG 1147c478bd9Sstevel@tonic-gatefi 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate# 117f6e214c7SGavin Maltby# If the savecore executable is absent then we're done 118f6e214c7SGavin Maltby# 119f6e214c7SGavin Maltbyif [ ! -x /usr/bin/savecore ]; then 120f6e214c7SGavin Maltby exit $SMF_EXIT_ERR_CONFIG 121f6e214c7SGavin Maltbyfi 122f6e214c7SGavin Maltby 123f6e214c7SGavin Maltby# 1247c478bd9Sstevel@tonic-gate# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again 1257c478bd9Sstevel@tonic-gate# because the dump device may have changed. If the earlier savecore had 1267c478bd9Sstevel@tonic-gate# saved the dump, savecore will just exit immediately. 1277c478bd9Sstevel@tonic-gate# 128f6e214c7SGavin Maltby 129f6e214c7SGavin Maltbyisswap=0 130f6e214c7SGavin Maltbyswapchanged=0 1317950274eSeschrockif /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \ 1327950274eSeschrock >/dev/null 2>&1; then 133f6e214c7SGavin Maltby isswap=1 134f6e214c7SGavin Maltby if [ "x$savedev" != "x$DUMPADM_DEVICE" ]; then 135f6e214c7SGavin Maltby swapchanged=1 136f6e214c7SGavin Maltby fi 137f6e214c7SGavin Maltbyfi 138f6e214c7SGavin Maltby 139f6e214c7SGavin Maltbyif [ "x$DUMPADM_ENABLE" != xno ]; then 140f6e214c7SGavin Maltby if [ $isswap -eq 1 ]; then 1417c478bd9Sstevel@tonic-gate # 1427c478bd9Sstevel@tonic-gate # If the dump device is part of swap, we only need to run 1437c478bd9Sstevel@tonic-gate # savecore a second time if the device is different from the 1447c478bd9Sstevel@tonic-gate # swap device on which we initially ran savecore. 1457c478bd9Sstevel@tonic-gate # 146f6e214c7SGavin Maltby if [ $swapchanged -eq 1 ]; then 1477c478bd9Sstevel@tonic-gate mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 148f6e214c7SGavin Maltby fi 1497c478bd9Sstevel@tonic-gate else 1507c478bd9Sstevel@tonic-gate # 1517c478bd9Sstevel@tonic-gate # The dump device couldn't have been dedicated before we 1527c478bd9Sstevel@tonic-gate # ran dumpadm, so we must execute savecore again. 1537c478bd9Sstevel@tonic-gate # 1547c478bd9Sstevel@tonic-gate mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR & 1557c478bd9Sstevel@tonic-gate fi 156f6e214c7SGavin Maltbyelse 157f6e214c7SGavin Maltby # 158f6e214c7SGavin Maltby # savecore not enabled. Check whether a valid dump is 159f6e214c7SGavin Maltby # present on the device and raise an event to signal that, 160f6e214c7SGavin Maltby # but avoid sending a duplicate event from the savecore -c 161f6e214c7SGavin Maltby # earlier. 162f6e214c7SGavin Maltby # 163f6e214c7SGavin Maltby if [ $isswap -eq 0 -o $swapchanged -eq 1 ]; then 164f6e214c7SGavin Maltby /usr/bin/savecore -c 165f6e214c7SGavin Maltby fi 1667c478bd9Sstevel@tonic-gatefi 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK 169