1#! /bin/ksh 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# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24# 25 26# Script to wrap a non-windowing clean script to provide a prompt 27# before the dtterm window closes, and to catch abnormal terminations. 28 29# For any abnormal termination of the clean script, kill our parent 30# process so that our grandparent will know that the script did not 31# terminate normally. (We expect our parent to be dtterm, and our 32# grandparent to be allocate.) 33 34# Trap any signal that would cause abnormal termination of the script, 35# This catches use of ^C, ^Z, etc., and it also catches the HUP signal 36# when the dtterm window is closed before the script is finished. 37 38PARENT_KILLED=no 39 40killparent() { 41 if [ $PARENT_KILLED = "no" ]; then 42 PARENT_KILLED=yes 43 kill -9 $PPID 44 fi 45} 46 47trap "killparent" HUP INT TERM QUIT TSTP ABRT 48 49SCRIPT=$1 50shift 51 52if [ ! -e $SCRIPT ]; then 53 echo **** Clean script $SCRIPT not found **** 54 echo "**** Press RETURN to close window ****" 55 read 56 kill -9 $PPID 57fi 58 59echo "**** Device cleanup for $2 ****\n" 60 61$SCRIPT "$@" 62STAT=$? 63 64echo "\n**** Press RETURN to close window ****" 65read 66 67# If the script returned a non-zero exit status, kill our dtterm 68# parent process. 69 70if [ $STAT != 0 ]; then 71 killparent 72fi 73