dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / i386 / etc / caplib.ksh
blob4cab453bbe8e3150796b66ece4ef9e939e6689d0
1 #!/bin/ksh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
23 # ident "%Z%%M% %I% %E% SMI"
25 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26 # Use is subject to license terms.
30 # This script is called by flarcreate.sh
32 # Unmount all hwcap libraries (like /usr/lib/libc/libc_hwcap2.so.1)
33 # and store commands needed to remount them in preexit/remount_hwcap.xxxx
34 # scripts, which remounts them in the preexit phase.
37 if [ -z "$FLASH_PID" ]; then
38 echo "$0: ERROR: FLASH_PID not set in execution environment, exiting..."
39 exit 1
41 if [ -z "$FLASH_DIR" ]; then
42 echo "$0: ERROR: FLASH_DIR not set in execution environment, exiting..."
43 exit 1
46 CHMOD=/usr/bin/chmod
47 ELFDUMP=/usr/ccs/bin/elfdump
48 MOUNT=/usr/sbin/mount
49 UMOUNT=/usr/sbin/umount
50 EGREP=/usr/bin/egrep
51 SED=/usr/bin/sed
52 CMD_LIST="$CHMOD $ELFDUMP $MOUNT $UMOUNT $EGREP $SED"
54 for cmd in $CMD_LIST
56 if [ ! -x $cmd ]; then
57 echo "$0: ERROR: $cmd not found or not executable, exiting..."
58 exit 1
60 done
63 # Fill "LIBS" with a list of mounted libraries in the form:
64 # MOUNTPOUNT:FILE
65 # e.g.:
66 # /lib/libc.so.1:/usr/lib/libc/libc_hwcap2.so.1
68 LIBS=`$MOUNT | $EGREP "^/lib|^/usr/lib" | \
69 $SED -e 's:^\(/[^ ]*\) on \([^ ]*\).*$:\1@\2:'`
71 if [ ! "$LIBS" ]; then
72 exit 0
75 REMOUNT_DIR=${FLASH_DIR}/preexit
76 REMOUNT=${REMOUNT_DIR}/remount_hwcap.${FLASH_PID}
79 # Create the flash preexit script directory for the remount scripts if it
80 # doesn't already exist.
82 if [ ! -d $REMOUNT_DIR ]; then
83 umask 077
84 /usr/bin/mkdir $REMOUNT_DIR
85 if [ $? -ne 0 ]; then
86 echo "$0: ERROR: could not mkdir $REMOUNT_DIR, exiting..."
87 exit 1
92 # If an old remount script by this name exists, delete it
94 if [ -f $REMOUNT ]; then
95 /bin/rm -f $REMOUNT
98 umask 477
100 cat > $REMOUNT << EOF
101 #!/bin/sh
102 if [ \"\$FLASH_PID\" != \"$FLASH_PID\" ]; then
103 /bin/rm -f $REMOUNT
104 exit 0
108 if [ $? -ne 0 ]; then
109 echo "$0: ERROR: could not create $REMOUNT, exiting..."
110 exit 1
114 # Now process each of the libraries that are mounted. For each, find out if
115 # it's a hwcap library; if it is, unmount it and write instructions to the
116 # preexit script as to how to remount it.
118 for entry in $LIBS
120 echo $entry | IFS=@ read MOUNTPOINT MOUNTLIB
121 CAPLIB=`$ELFDUMP -H $MOUNTLIB`
122 if [ \( $? -eq 0 \) -a \( -n "$CAPLIB" \) ]; then
123 $UMOUNT $MOUNTPOINT || $UMOUNT -f $MOUNTPOINT || \
124 { echo "$0: ERROR: Could not unmount" \
125 "$MOUNTPOINT, exiting..."; \
126 /bin/sh $REMOUNT; /bin/rm -f $REMOUNT; exit 1; }
128 echo $MOUNTLIB | $EGREP -s :
129 if [ $? -eq 0 ]; then
130 MOUNTOPTS="-O"
131 else
132 MOUNTOPTS="-O -F lofs"
134 echo "$MOUNT $MOUNTOPTS $MOUNTLIB $MOUNTPOINT" >> $REMOUNT
136 done
139 # Write final cleanup instructions to the flash preexit remount script and make
140 # it executable.
142 echo "/bin/rm -f $REMOUNT" >> $REMOUNT
143 echo "exit 0" >> $REMOUNT
144 $CHMOD 0500 $REMOUNT
145 exit 0