xref: /titanic_44/usr/src/cmd/allocate/wdwwrapper.sh (revision f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01)
1*f875b4ebSrica#! /bin/ksh
2*f875b4ebSrica#
3*f875b4ebSrica# CDDL HEADER START
4*f875b4ebSrica#
5*f875b4ebSrica# The contents of this file are subject to the terms of the
6*f875b4ebSrica# Common Development and Distribution License (the "License").
7*f875b4ebSrica# You may not use this file except in compliance with the License.
8*f875b4ebSrica#
9*f875b4ebSrica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*f875b4ebSrica# or http://www.opensolaris.org/os/licensing.
11*f875b4ebSrica# See the License for the specific language governing permissions
12*f875b4ebSrica# and limitations under the License.
13*f875b4ebSrica#
14*f875b4ebSrica# When distributing Covered Code, include this CDDL HEADER in each
15*f875b4ebSrica# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*f875b4ebSrica# If applicable, add the following below this CDDL HEADER, with the
17*f875b4ebSrica# fields enclosed by brackets "[]" replaced with your own identifying
18*f875b4ebSrica# information: Portions Copyright [yyyy] [name of copyright owner]
19*f875b4ebSrica#
20*f875b4ebSrica# CDDL HEADER END
21*f875b4ebSrica#
22*f875b4ebSrica# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*f875b4ebSrica# Use is subject to license terms.
24*f875b4ebSrica#
25*f875b4ebSrica#pragma ident	"%Z%%M%	%I%	%E% SMI"
26*f875b4ebSrica#
27*f875b4ebSrica
28*f875b4ebSrica
29*f875b4ebSrica# Script to wrap a non-windowing clean script to provide a prompt
30*f875b4ebSrica# before the dtterm window closes, and to catch abnormal terminations.
31*f875b4ebSrica
32*f875b4ebSrica# For any abnormal termination of the clean script, kill our parent
33*f875b4ebSrica# process so that our grandparent will know that the script did not
34*f875b4ebSrica# terminate normally.  (We expect our parent to be dtterm, and our
35*f875b4ebSrica# grandparent to be allocate.)
36*f875b4ebSrica
37*f875b4ebSrica# Trap any signal that would cause abnormal termination of the script,
38*f875b4ebSrica# This catches use of ^C, ^Z, etc., and it also catches the HUP signal
39*f875b4ebSrica# when the dtterm window is closed before the script is finished.
40*f875b4ebSrica
41*f875b4ebSricaPARENT_KILLED=no
42*f875b4ebSrica
43*f875b4ebSricakillparent() {
44*f875b4ebSrica  if [ $PARENT_KILLED = "no" ]; then
45*f875b4ebSrica    PARENT_KILLED=yes
46*f875b4ebSrica    kill -9 $PPID
47*f875b4ebSrica  fi
48*f875b4ebSrica}
49*f875b4ebSrica
50*f875b4ebSricatrap "killparent" HUP INT TERM QUIT TSTP ABRT
51*f875b4ebSrica
52*f875b4ebSricaSCRIPT=$1
53*f875b4ebSricashift
54*f875b4ebSrica
55*f875b4ebSricaif [ ! -e $SCRIPT ]; then
56*f875b4ebSrica	echo **** Clean script $SCRIPT not found ****
57*f875b4ebSrica	echo "**** Press RETURN to close window ****"
58*f875b4ebSrica	read
59*f875b4ebSrica	kill -9 $PPID
60*f875b4ebSricafi
61*f875b4ebSrica
62*f875b4ebSricaecho "**** Device cleanup for $2 ****\n"
63*f875b4ebSrica
64*f875b4ebSrica$SCRIPT "$@"
65*f875b4ebSricaSTAT=$?
66*f875b4ebSrica
67*f875b4ebSricaecho "\n**** Press RETURN to close window ****"
68*f875b4ebSricaread
69*f875b4ebSrica
70*f875b4ebSrica# If the script returned a non-zero exit status, kill our dtterm
71*f875b4ebSrica# parent process.
72*f875b4ebSrica
73*f875b4ebSricaif [ $STAT != 0 ]; then
74*f875b4ebSrica	killparent
75*f875b4ebSricafi
76