xref: /titanic_51/usr/src/cmd/initpkg/umountall.sh (revision 5fad3ade0b6bf1454149b5f22a06ce99e9c1e4ff)
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
6ef4c14d2Ssetje# Common Development and Distribution License (the "License").
7ef4c14d2Ssetje# 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#
23584b3c47SJerry Gilliam# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
277c478bd9Sstevel@tonic-gate#	  All Rights Reserved
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gateusage () {
327c478bd9Sstevel@tonic-gate	if [ -n "$1" ]; then
337c478bd9Sstevel@tonic-gate		echo "umountall: $1" 1>&2
347c478bd9Sstevel@tonic-gate	fi
35*5fad3adeSPavel Filipensky	echo "Usage:\n\tumountall [-k] [-s] [-F FSType] [-l|-r] [-Z] [-n]" 1>&2
36*5fad3adeSPavel Filipensky	echo "\tumountall [-k] [-s] [-h host] [-Z] [-n]" 1>&2
377c478bd9Sstevel@tonic-gate	exit 2
387c478bd9Sstevel@tonic-gate}
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gateMNTTAB=/etc/mnttab
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate# This script is installed as both /sbin/umountall (as used in some
437c478bd9Sstevel@tonic-gate# /sbin/rc? and /etc/init.d scripts) _and_ as /usr/sbin/umountall (typically
447c478bd9Sstevel@tonic-gate# PATHed from the command line).  As such it should not depend on /usr
457c478bd9Sstevel@tonic-gate# being mounted (if /usr is a separate filesystem).
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate# /sbin/sh Bourne shell builtins we use:
487c478bd9Sstevel@tonic-gate#	echo
497c478bd9Sstevel@tonic-gate#	exit
507c478bd9Sstevel@tonic-gate#	getopts
517c478bd9Sstevel@tonic-gate#	test, [ ]
527c478bd9Sstevel@tonic-gate#	exec
537c478bd9Sstevel@tonic-gate#	read
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gate# /sbin commands we use:
567c478bd9Sstevel@tonic-gate#	/sbin/uname
577c478bd9Sstevel@tonic-gate#	/sbin/umount
587c478bd9Sstevel@tonic-gate#
597c478bd9Sstevel@tonic-gate# The following /usr based commands may be used by this script (depending on
607c478bd9Sstevel@tonic-gate# command line options).  We will set our PATH to find them, but where they
617c478bd9Sstevel@tonic-gate# are not present (eg, if /usr is not mounted) we will catch references to
627c478bd9Sstevel@tonic-gate# them via shell functions conditionally defined after option processing
637c478bd9Sstevel@tonic-gate# (don't use any of these commands before then).
647c478bd9Sstevel@tonic-gate#
657c478bd9Sstevel@tonic-gate#	Command		Command line option and use
667c478bd9Sstevel@tonic-gate# /usr/bin/sleep	-k, to sleep after an fuser -c -k on the mountpoint
677c478bd9Sstevel@tonic-gate# /usr/sbin/fuser	-k, to kill processes keeping a mount point busy
687c478bd9Sstevel@tonic-gate#
697c478bd9Sstevel@tonic-gate# In addition, we use /usr/bin/tail if it is available; if not we use
707c478bd9Sstevel@tonic-gate# slower shell constructs to reverse a file.
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gatePATH=/sbin:/usr/sbin:/usr/bin
737c478bd9Sstevel@tonic-gate
7476bc4030SnadkarniDEFERRED_ACTIVATION_PATCH_FLAG="/var/run/.patch_loopback_mode"
7576bc4030SnadkarniSVC_STARTD="/lib/svc/bin/svc.startd"
7676bc4030Snadkarni
777c478bd9Sstevel@tonic-gate# Clear these in case they were already set in our inherited environment.
787c478bd9Sstevel@tonic-gateFSType=
797c478bd9Sstevel@tonic-gateFFLAG=
807c478bd9Sstevel@tonic-gateHOST=
817c478bd9Sstevel@tonic-gateHFLAG=
827c478bd9Sstevel@tonic-gateRFLAG=
837c478bd9Sstevel@tonic-gateLFLAG=
847c478bd9Sstevel@tonic-gateSFLAG=
857c478bd9Sstevel@tonic-gateKFLAG=
86*5fad3adeSPavel FilipenskyZFLAG=
877c478bd9Sstevel@tonic-gateNFLAG=
887c478bd9Sstevel@tonic-gateLOCALNAME=
897c478bd9Sstevel@tonic-gateUMOUNTFLAG=
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate
92*5fad3adeSPavel Filipenskywhile getopts ?rslkF:h:Zn c
937c478bd9Sstevel@tonic-gatedo
947c478bd9Sstevel@tonic-gate	case $c in
957c478bd9Sstevel@tonic-gate	r)	RFLAG="r";;
967c478bd9Sstevel@tonic-gate	l)	LFLAG="l";;
977c478bd9Sstevel@tonic-gate	s)	SFLAG="s";;
987c478bd9Sstevel@tonic-gate	k) 	KFLAG="k";;
997c478bd9Sstevel@tonic-gate	h)	if [ -n "$HFLAG" ]; then
1007c478bd9Sstevel@tonic-gate			usage "more than one host specified"
1017c478bd9Sstevel@tonic-gate		fi
1027c478bd9Sstevel@tonic-gate		HOST=$OPTARG
1037c478bd9Sstevel@tonic-gate		HFLAG="h"
1047c478bd9Sstevel@tonic-gate		LOCALNAME=`uname -n`
1057c478bd9Sstevel@tonic-gate		;;
1067c478bd9Sstevel@tonic-gate	F)	if [ -n "$FFLAG" ]; then
1077c478bd9Sstevel@tonic-gate			usage "more than one FStype specified"
1087c478bd9Sstevel@tonic-gate		fi
1097c478bd9Sstevel@tonic-gate		FSType=$OPTARG
1107c478bd9Sstevel@tonic-gate		FFLAG="f"
1117c478bd9Sstevel@tonic-gate		case $FSType in
1127c478bd9Sstevel@tonic-gate		?????????*)
1137c478bd9Sstevel@tonic-gate			usage "FSType ${FSType} exceeds 8 characters"
1147c478bd9Sstevel@tonic-gate		esac;
1157c478bd9Sstevel@tonic-gate		;;
116*5fad3adeSPavel Filipensky	Z)	ZFLAG="z";;
1177c478bd9Sstevel@tonic-gate	n)	NFLAG="n"
1187c478bd9Sstevel@tonic-gate		# Alias any commands that would perform real actions to
1197c478bd9Sstevel@tonic-gate		# something that tells what action would have been performed
1207c478bd9Sstevel@tonic-gate		UMOUNTFLAG="-V"
1217c478bd9Sstevel@tonic-gate		fuser () {
1227c478bd9Sstevel@tonic-gate			echo "fuser $*" 1>&2
1237c478bd9Sstevel@tonic-gate		}
1247c478bd9Sstevel@tonic-gate		sleep () {
1257c478bd9Sstevel@tonic-gate			: # No need to show where we'd sleep
1267c478bd9Sstevel@tonic-gate		}
1277c478bd9Sstevel@tonic-gate		;;
1287c478bd9Sstevel@tonic-gate	\?)	usage ""
1297c478bd9Sstevel@tonic-gate		;;
1307c478bd9Sstevel@tonic-gate	esac
1317c478bd9Sstevel@tonic-gatedone
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate# Sanity checking:
1347c478bd9Sstevel@tonic-gate#	1) arguments beyond those supported
1357c478bd9Sstevel@tonic-gate#	2) can't specify both remote and local
1367c478bd9Sstevel@tonic-gate#	3) can't specify a host with -r or -l
1377c478bd9Sstevel@tonic-gate#	4) can't specify a fstype with -h
1387c478bd9Sstevel@tonic-gate#	5) can't specify this host with -h (checks only uname -n)
1397c478bd9Sstevel@tonic-gate#	6) can't be fstype nfs and local
1407c478bd9Sstevel@tonic-gate#	7) only fstype nfs is remote
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gateif [ $# -ge $OPTIND ]; then						# 1
1437c478bd9Sstevel@tonic-gate	usage "additional arguments not supported"
1447c478bd9Sstevel@tonic-gatefi
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gateif [ -n "$RFLAG" -a -n "$LFLAG" ]; then					# 2
1477c478bd9Sstevel@tonic-gate	usage "options -r and -l are incompatible"
1487c478bd9Sstevel@tonic-gatefi
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gateif [ \( -n "$RFLAG" -o -n "$LFLAG" \) -a "$HFLAG" = "h" ]; then		# 3
1517c478bd9Sstevel@tonic-gate	usage "option -${RFLAG}${LFLAG} incompatible with -h option"
1527c478bd9Sstevel@tonic-gatefi
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gateif [ -n "$FFLAG" -a "$HFLAG" = "h" ]; then				# 4
1557c478bd9Sstevel@tonic-gate	usage "Specifying FStype incompatible with -h option"
1567c478bd9Sstevel@tonic-gatefi
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gateif [ -n "$HFLAG" -a "$HOST" = "$LOCALNAME" ]; then			# 5
1597c478bd9Sstevel@tonic-gate	usage "Specifying local host illegal for -h option"
1607c478bd9Sstevel@tonic-gatefi
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gateif [ "$FSType" = "nfs" -a "$LFLAG" = "l" ]; then			# 6
1637c478bd9Sstevel@tonic-gate	usage "option -l and FSType nfs are incompatible"
1647c478bd9Sstevel@tonic-gatefi
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gateif [ -n "$FFLAG" -a "$FSType" != "nfs"  -a -n "$RFLAG" ]; then		# 7
1677c478bd9Sstevel@tonic-gate	usage "option -r and FSType ${FSType} are incompatible"
1687c478bd9Sstevel@tonic-gatefi
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gateZONENAME=`zonename`
1717c478bd9Sstevel@tonic-gate
172ef4c14d2Ssetje# Check and if needed sync the boot archive before unmounting everything.
173b05689eaSsetje#
174584b3c47SJerry Gilliamif [ -z "${RFLAG}${NFLAG}${HFLAG}${FSType}" -a "$ZONENAME" = "global" \
175584b3c47SJerry Gilliam    -a -x /sbin/bootadm ] ; then
176b05689eaSsetje	/sbin/bootadm -a update_all
177b05689eaSsetjefi
178b05689eaSsetje
17976bc4030Snadkarni
18076bc4030Snadkarni#
18176bc4030Snadkarni# If we are in deferred activation patching, and the caller is
18276bc4030Snadkarni# svc.startd, then exit without unmounting any of the remaining
18376bc4030Snadkarni# file systems since the call path is from shutdown.  Note that
18476bc4030Snadkarni# by the time we get here, smf stop methods for nfs, cachefs
18576bc4030Snadkarni# etc, will have run.
18676bc4030Snadkarni#
18776bc4030Snadkarniif [ -f $DEFERRED_ACTIVATION_PATCH_FLAG ] ; then
18876bc4030Snadkarni	ppid=`ps -o ppid= -p $$`	# parent of umountall will be sh
18976bc4030Snadkarni					# from system()
19076bc4030Snadkarni
19176bc4030Snadkarni	ppid=`ps -o ppid= -p $ppid`	# parent of sh will be svc.startd
19276bc4030Snadkarni	COMM=`ps -o comm= -p $ppid`
19376bc4030Snadkarni	if [ "$COMM" = "$SVC_STARTD" ] ; then
19476bc4030Snadkarni		exit
19576bc4030Snadkarni	fi
19676bc4030Snadkarnifi
19776bc4030Snadkarni
1987c478bd9Sstevel@tonic-gate#
1997c478bd9Sstevel@tonic-gate# Take advantage of parallel unmounting at this point if we have no
2007c478bd9Sstevel@tonic-gate# criteria to match and we are in the global zone
2017c478bd9Sstevel@tonic-gate#
202*5fad3adeSPavel Filipenskyif [ -z "${SFLAG}${LFLAG}${RFLAG}${HFLAG}${KFLAG}${FFLAG}${ZFLAG}" -a \
2037c478bd9Sstevel@tonic-gate    "$ZONENAME" = "global" ]; then
2047c478bd9Sstevel@tonic-gate	umount -a ${UMOUNTFLAG}
2057c478bd9Sstevel@tonic-gate	exit			# with return code of the umount -a
2067c478bd9Sstevel@tonic-gatefi
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate#
2097c478bd9Sstevel@tonic-gate# Catch uses of /usr commands when /usr is not mounted
2107c478bd9Sstevel@tonic-gateif [ -n "$KFLAG" -a -z "$NFLAG" ]; then
2117c478bd9Sstevel@tonic-gate	if [ ! -x /usr/sbin/fuser ]; then
2127c478bd9Sstevel@tonic-gate		fuser () {
2137c478bd9Sstevel@tonic-gate			echo "umountall: fuser -k skipped (no /usr)" 1>&2
2147c478bd9Sstevel@tonic-gate			# continue - not fatal
2157c478bd9Sstevel@tonic-gate		}
2167c478bd9Sstevel@tonic-gate		sleep () {
2177c478bd9Sstevel@tonic-gate			: # no point in sleeping if fuser is doing nothing
2187c478bd9Sstevel@tonic-gate		}
2197c478bd9Sstevel@tonic-gate	else
2207c478bd9Sstevel@tonic-gate		if [ ! -x /usr/bin/sleep ]; then
2217c478bd9Sstevel@tonic-gate			sleep () {
2227c478bd9Sstevel@tonic-gate				echo "umountall: sleep after fuser -k skipped (no /usr)" 1>&2
2237c478bd9Sstevel@tonic-gate				# continue - not fatal
2247c478bd9Sstevel@tonic-gate			}
2257c478bd9Sstevel@tonic-gate		fi
2267c478bd9Sstevel@tonic-gate	fi
2277c478bd9Sstevel@tonic-gatefi
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate#
2307c478bd9Sstevel@tonic-gate# Shell function to avoid using /usr/bin/cut.  Given a dev from a
2317c478bd9Sstevel@tonic-gate# fstype=nfs line in mnttab (eg, "host:/export) extract the host
2327c478bd9Sstevel@tonic-gate# component.
2337c478bd9Sstevel@tonic-gateprint_host () {
2347c478bd9Sstevel@tonic-gate	OIFS=$IFS
2357c478bd9Sstevel@tonic-gate	IFS=":"
2367c478bd9Sstevel@tonic-gate	set -- $*
2377c478bd9Sstevel@tonic-gate	echo $1
2387c478bd9Sstevel@tonic-gate	IFS=$OIFS
2397c478bd9Sstevel@tonic-gate}
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate#
2427c478bd9Sstevel@tonic-gate# doumounts echos its return code to stdout, so commands used within
2437c478bd9Sstevel@tonic-gate# this function should take care to produce no other output to stdout.
2447c478bd9Sstevel@tonic-gatedoumounts () {
2457c478bd9Sstevel@tonic-gate	(
2467c478bd9Sstevel@tonic-gate	rc=0
2477c478bd9Sstevel@tonic-gate	fslist=""
2487c478bd9Sstevel@tonic-gate	while read dev mountp fstype mode dummy
2497c478bd9Sstevel@tonic-gate	do
2507c478bd9Sstevel@tonic-gate		case "${mountp}" in
2517c478bd9Sstevel@tonic-gate		/			| \
2527c478bd9Sstevel@tonic-gate		/dev			| \
2537c478bd9Sstevel@tonic-gate		/dev/fd			| \
2547c478bd9Sstevel@tonic-gate		/devices		| \
2557c478bd9Sstevel@tonic-gate		/etc/mnttab		| \
2567c478bd9Sstevel@tonic-gate		/etc/svc/volatile	| \
2577c478bd9Sstevel@tonic-gate		/lib			| \
2587c478bd9Sstevel@tonic-gate		/proc			| \
2597c478bd9Sstevel@tonic-gate		/sbin			| \
2607c478bd9Sstevel@tonic-gate		/system/contract	| \
2617c478bd9Sstevel@tonic-gate		/system/object		| \
2627c478bd9Sstevel@tonic-gate		/tmp			| \
2637c478bd9Sstevel@tonic-gate		/usr			| \
2647c478bd9Sstevel@tonic-gate		/var			| \
2657c478bd9Sstevel@tonic-gate		/var/adm		| \
2667c478bd9Sstevel@tonic-gate		/var/run		| \
2677c478bd9Sstevel@tonic-gate		'' )
2687c478bd9Sstevel@tonic-gate			#
2697c478bd9Sstevel@tonic-gate			# file systems possibly mounted in the kernel or
2707c478bd9Sstevel@tonic-gate			# in the methods of some of the file system
2717c478bd9Sstevel@tonic-gate			# services
2727c478bd9Sstevel@tonic-gate			#
2737c478bd9Sstevel@tonic-gate			continue
2747c478bd9Sstevel@tonic-gate			;;
2757c478bd9Sstevel@tonic-gate		* )
2767c478bd9Sstevel@tonic-gate			if [ -n "$HFLAG" ]; then
2777c478bd9Sstevel@tonic-gate				if [ "$fstype" = "nfs" ]; then
2787c478bd9Sstevel@tonic-gate					thishost=`print_host $dev`
2797c478bd9Sstevel@tonic-gate					if [ "$HOST" != "$thishost" ]; then
2807c478bd9Sstevel@tonic-gate						continue
2817c478bd9Sstevel@tonic-gate					fi
2827c478bd9Sstevel@tonic-gate				else
2837c478bd9Sstevel@tonic-gate					continue
2847c478bd9Sstevel@tonic-gate				fi
2857c478bd9Sstevel@tonic-gate			fi
2867c478bd9Sstevel@tonic-gate			if [ -n "$FFLAG" -a "$FSType" != "$fstype" ]; then
2877c478bd9Sstevel@tonic-gate				continue
2887c478bd9Sstevel@tonic-gate			fi
2897c478bd9Sstevel@tonic-gate			if [ -n "$LFLAG" -a "$fstype" = "nfs" ]; then
2907c478bd9Sstevel@tonic-gate				continue
2917c478bd9Sstevel@tonic-gate			fi
2927c478bd9Sstevel@tonic-gate			if [ -n "$RFLAG" -a "$fstype" != "nfs" ]; then
2937c478bd9Sstevel@tonic-gate				continue
2947c478bd9Sstevel@tonic-gate			fi
2957c478bd9Sstevel@tonic-gate			if [ "$ZONENAME" != "global" ]; then
2967c478bd9Sstevel@tonic-gate				for option in `echo $mode | tr , '\012'`; do
2977c478bd9Sstevel@tonic-gate					#
2987c478bd9Sstevel@tonic-gate					# should not see any zone options
2997c478bd9Sstevel@tonic-gate					# but our own
3007c478bd9Sstevel@tonic-gate					#
3017c478bd9Sstevel@tonic-gate					if [ "$option" = "zone=$ZONENAME" ]; then
3027c478bd9Sstevel@tonic-gate						break
3037c478bd9Sstevel@tonic-gate					fi
3047c478bd9Sstevel@tonic-gate				done
3057c478bd9Sstevel@tonic-gate				if [ "$option" != "zone=$ZONENAME" ]; then
3067c478bd9Sstevel@tonic-gate					continue
3077c478bd9Sstevel@tonic-gate				fi
308*5fad3adeSPavel Filipensky			# we are called from the global zone
309*5fad3adeSPavel Filipensky			else
310*5fad3adeSPavel Filipensky				for option in `echo $mode | tr , '\012'`; do
311*5fad3adeSPavel Filipensky					case "$option" in
312*5fad3adeSPavel Filipensky					zone=*)
313*5fad3adeSPavel Filipensky						option="zone="
314*5fad3adeSPavel Filipensky						break
315*5fad3adeSPavel Filipensky					;;
316*5fad3adeSPavel Filipensky					esac
317*5fad3adeSPavel Filipensky				done
318*5fad3adeSPavel Filipensky				# skip mounts from non-global zones if ZFLAG is not set
319*5fad3adeSPavel Filipensky				if [ "$option" = "zone=" -a -z "$ZFLAG" ]; then
320*5fad3adeSPavel Filipensky					continue
321*5fad3adeSPavel Filipensky				fi
322*5fad3adeSPavel Filipensky				# skip mounts from the global zone if ZFLAG is set
323*5fad3adeSPavel Filipensky				if [ "$option" != "zone=" -a -n "$ZFLAG" ]; then
324*5fad3adeSPavel Filipensky					continue
325*5fad3adeSPavel Filipensky				fi
3267c478bd9Sstevel@tonic-gate			fi
3277c478bd9Sstevel@tonic-gate			if [ -n "${KFLAG}" ]; then
3287c478bd9Sstevel@tonic-gate				fuser -c -k $mountp 1>&2
3297c478bd9Sstevel@tonic-gate				sleep 2
3307c478bd9Sstevel@tonic-gate			fi
3317c478bd9Sstevel@tonic-gate			if [ -n "$SFLAG" ]; then
3327c478bd9Sstevel@tonic-gate				umount ${UMOUNTFLAG} ${mountp} 1>&2
3337c478bd9Sstevel@tonic-gate				trc=$?
3347c478bd9Sstevel@tonic-gate				if [ $trc -ne 0 ]; then
3357c478bd9Sstevel@tonic-gate					rc=$trc
3367c478bd9Sstevel@tonic-gate				fi
3377c478bd9Sstevel@tonic-gate			else
3387c478bd9Sstevel@tonic-gate				# We want to umount in parallel
3397c478bd9Sstevel@tonic-gate				fslist="$fslist $mountp"
3407c478bd9Sstevel@tonic-gate			fi
3417c478bd9Sstevel@tonic-gate		esac
3427c478bd9Sstevel@tonic-gate	done
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate	if [ -n "$fslist" ]; then
3457c478bd9Sstevel@tonic-gate		umount -a ${UMOUNTFLAG} $fslist 1>&2
3467c478bd9Sstevel@tonic-gate		trc=$?
3477c478bd9Sstevel@tonic-gate		if [ $trc -ne 0 ]; then
3487c478bd9Sstevel@tonic-gate			rc=$trc
3497c478bd9Sstevel@tonic-gate		fi
3507c478bd9Sstevel@tonic-gate	fi
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate	echo $rc
3537c478bd9Sstevel@tonic-gate	)
3547c478bd9Sstevel@tonic-gate}
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate#
3577c478bd9Sstevel@tonic-gate# /etc/mnttab has the most recent mounts last.  Reverse it so that we
3587c478bd9Sstevel@tonic-gate# may umount in opposite order to the original mounts.
3597c478bd9Sstevel@tonic-gate#
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gateif [ ! -x /usr/bin/tail ]; then
3627c478bd9Sstevel@tonic-gate	exec < $MNTTAB
3637c478bd9Sstevel@tonic-gate	REVERSED=
3647c478bd9Sstevel@tonic-gate	while read line; do
3657c478bd9Sstevel@tonic-gate		if [ -n "$REVERSED" ]; then
3667c478bd9Sstevel@tonic-gate        		REVERSED="$line\n$REVERSED"
3677c478bd9Sstevel@tonic-gate		else
3687c478bd9Sstevel@tonic-gate			REVERSED="$line"
3697c478bd9Sstevel@tonic-gate		fi
3707c478bd9Sstevel@tonic-gate	done
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate	error=`echo $REVERSED | doumounts`
3737c478bd9Sstevel@tonic-gateelse
3747c478bd9Sstevel@tonic-gate	error=`tail -r $MNTTAB | doumounts`
3757c478bd9Sstevel@tonic-gatefi
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gateexit $error
378