xref: /titanic_50/usr/src/lib/libc/i386/etc/caplib.ksh (revision 3471bc8c6d7a07a376b0e7eba2297717b94415d5)
1a7123019Skucharsk#!/bin/ksh
2a7123019Skucharsk#
3a7123019Skucharsk# CDDL HEADER START
4a7123019Skucharsk#
5a7123019Skucharsk# The contents of this file are subject to the terms of the
6*3471bc8cSsc157166# Common Development and Distribution License (the "License").
7*3471bc8cSsc157166# You may not use this file except in compliance with the License.
8a7123019Skucharsk#
9a7123019Skucharsk# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10a7123019Skucharsk# or http://www.opensolaris.org/os/licensing.
11a7123019Skucharsk# See the License for the specific language governing permissions
12a7123019Skucharsk# and limitations under the License.
13a7123019Skucharsk#
14a7123019Skucharsk# When distributing Covered Code, include this CDDL HEADER in each
15a7123019Skucharsk# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16a7123019Skucharsk# If applicable, add the following below this CDDL HEADER, with the
17a7123019Skucharsk# fields enclosed by brackets "[]" replaced with your own identifying
18a7123019Skucharsk# information: Portions Copyright [yyyy] [name of copyright owner]
19a7123019Skucharsk#
20a7123019Skucharsk# CDDL HEADER END
21a7123019Skucharsk#
22a7123019Skucharsk#
23a7123019Skucharsk# ident	"%Z%%M%	%I%	%E% SMI"
24a7123019Skucharsk#
25aa3884f6Sck142721# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26a7123019Skucharsk# Use is subject to license terms.
27a7123019Skucharsk#
28a7123019Skucharsk
29a7123019Skucharsk#
30a7123019Skucharsk# This script is called by flarcreate.sh
31a7123019Skucharsk#
32a7123019Skucharsk# Unmount all hwcap libraries (like /usr/lib/libc/libc_hwcap2.so.1)
33a7123019Skucharsk# and store commands needed to remount them in preexit/remount_hwcap.xxxx
34a7123019Skucharsk# scripts, which remounts them in the preexit phase.
35a7123019Skucharsk#
36a7123019Skucharsk
37aa3884f6Sck142721if [ -z "$FLASH_PID" ]; then
38a7123019Skucharsk	echo "$0: ERROR: FLASH_PID not set in execution environment, exiting..."
39a7123019Skucharsk	exit 1
40a7123019Skucharskfi
41*3471bc8cSsc157166if [ -z "$FLASH_DIR" ]; then
42*3471bc8cSsc157166	echo "$0: ERROR: FLASH_DIR not set in execution environment, exiting..."
43*3471bc8cSsc157166	exit 1
44*3471bc8cSsc157166fi
45a7123019Skucharsk
46a7123019SkucharskCHMOD=/usr/bin/chmod
47a7123019SkucharskELFDUMP=/usr/ccs/bin/elfdump
48a7123019SkucharskMOUNT=/usr/sbin/mount
49a7123019SkucharskUMOUNT=/usr/sbin/umount
50a7123019SkucharskEGREP=/usr/bin/egrep
51a7123019SkucharskSED=/usr/bin/sed
52a7123019SkucharskCMD_LIST="$CHMOD $ELFDUMP $MOUNT $UMOUNT $EGREP $SED"
53a7123019Skucharsk
54a7123019Skucharskfor cmd in $CMD_LIST
55a7123019Skucharskdo
56a7123019Skucharsk    if [ ! -x $cmd ]; then
57a7123019Skucharsk	echo "$0: ERROR: $cmd not found or not executable, exiting..."
58a7123019Skucharsk	exit 1
59a7123019Skucharsk    fi
60a7123019Skucharskdone
61a7123019Skucharsk
62a7123019Skucharsk#
63a7123019Skucharsk# Fill "LIBS" with a list of mounted libraries in the form:
64a7123019Skucharsk# 	MOUNTPOUNT:FILE
65a7123019Skucharsk# e.g.:
66a7123019Skucharsk#	/lib/libc.so.1:/usr/lib/libc/libc_hwcap2.so.1
67a7123019Skucharsk#
68a7123019SkucharskLIBS=`$MOUNT | $EGREP "^/lib|^/usr/lib" | \
69a7123019Skucharsk    $SED -e 's:^\(/[^ ]*\) on \([^ ]*\).*$:\1@\2:'`
70a7123019Skucharsk
71aa3884f6Sck142721if [ ! "$LIBS" ]; then
72a7123019Skucharsk	exit 0
73a7123019Skucharskfi
74a7123019Skucharsk
75*3471bc8cSsc157166REMOUNT_DIR=${FLASH_DIR}/preexit
76a7123019SkucharskREMOUNT=${REMOUNT_DIR}/remount_hwcap.${FLASH_PID}
77a7123019Skucharsk
78a7123019Skucharsk#
79a7123019Skucharsk# Create the flash preexit script directory for the remount scripts if it
80a7123019Skucharsk# doesn't already exist.
81a7123019Skucharsk#
82a7123019Skucharskif [ ! -d $REMOUNT_DIR ]; then
83a7123019Skucharsk	umask 077
84a7123019Skucharsk	/usr/bin/mkdir $REMOUNT_DIR
85a7123019Skucharsk	if [ $? -ne 0 ]; then
86a7123019Skucharsk		echo "$0: ERROR: could not mkdir $REMOUNT_DIR, exiting..."
87a7123019Skucharsk		exit 1
88a7123019Skucharsk	fi
89a7123019Skucharskfi
90a7123019Skucharsk
91a7123019Skucharsk#
92a7123019Skucharsk# If an old remount script by this name exists, delete it
93a7123019Skucharsk#
94a7123019Skucharskif [ -f $REMOUNT ]; then
95a7123019Skucharsk	/bin/rm -f $REMOUNT
96a7123019Skucharskfi
97a7123019Skucharsk
98a7123019Skucharskumask 477
99a7123019Skucharsk
100a7123019Skucharskcat > $REMOUNT << EOF
101a7123019Skucharsk#!/bin/sh
102a7123019Skucharskif [ \"\$FLASH_PID\" != \"$FLASH_PID\" ]; then
103a7123019Skucharsk	/bin/rm -f $REMOUNT
104a7123019Skucharsk	exit 0
105a7123019Skucharskfi
106a7123019SkucharskEOF
107a7123019Skucharsk
108a7123019Skucharskif [ $? -ne 0 ]; then
109a7123019Skucharsk	echo "$0: ERROR: could not create $REMOUNT, exiting..."
110a7123019Skucharsk	exit 1
111a7123019Skucharskfi
112a7123019Skucharsk
113a7123019Skucharsk#
114a7123019Skucharsk# Now process each of the libraries that are mounted.  For each, find out if
115a7123019Skucharsk# it's a hwcap library; if it is, unmount it and write instructions to the
116a7123019Skucharsk# preexit script as to how to remount it.
117a7123019Skucharsk#
118a7123019Skucharskfor entry in $LIBS
119a7123019Skucharskdo
120a7123019Skucharsk	echo $entry | IFS=@ read MOUNTPOINT MOUNTLIB
121a7123019Skucharsk	CAPLIB=`$ELFDUMP -H $MOUNTLIB`
122a7123019Skucharsk	if [ \( $? -eq 0 \) -a \( -n "$CAPLIB" \) ]; then
123a7123019Skucharsk		$UMOUNT $MOUNTPOINT || $UMOUNT -f $MOUNTPOINT || \
124a7123019Skucharsk		    { echo "$0: ERROR: Could not unmount" \
125a7123019Skucharsk			  "$MOUNTPOINT, exiting..."; \
126a7123019Skucharsk		      /bin/sh $REMOUNT; /bin/rm -f $REMOUNT; exit 1; }
127a7123019Skucharsk
128a7123019Skucharsk		echo $MOUNTLIB | $EGREP -s :
129a7123019Skucharsk		if [ $? -eq 0 ]; then
130a7123019Skucharsk			MOUNTOPTS="-O"
131a7123019Skucharsk		else
132a7123019Skucharsk			MOUNTOPTS="-O -F lofs"
133a7123019Skucharsk		fi
134a7123019Skucharsk		echo "$MOUNT $MOUNTOPTS $MOUNTLIB $MOUNTPOINT" >> $REMOUNT
135a7123019Skucharsk	fi
136a7123019Skucharskdone
137a7123019Skucharsk
138a7123019Skucharsk#
139a7123019Skucharsk# Write final cleanup instructions to the flash preexit remount script and make
140a7123019Skucharsk# it executable.
141a7123019Skucharsk#
142a7123019Skucharskecho "/bin/rm -f $REMOUNT" >> $REMOUNT
143a7123019Skucharskecho "exit 0" >> $REMOUNT
144a7123019Skucharsk$CHMOD 0500 $REMOUNT
145a7123019Skucharskexit 0
146