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