#!/bin/sh
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)S40_setup_preload.sh	1.1	08/05/06 SMI"
#

#
# Tell ld.so.1(1) to LD_PRELOAD the s9_preload library.
#
# The crle must be done within the running zone due to differences in the
# format of ld.config between S9 and S10 and beyond.
#
# As part of the p2v module interface there are environment variables set for
# this script (e.g. FILEDIR - path to brand-specific file repository).
# See the p2v script for a full list of variables.
#

S9_PRELOAD=/.SUNWnative/usr/lib/brand/solaris9/s9_preload.so.1
S964_PRELOAD=/.SUNWnative/usr/lib/brand/solaris9/64/s9_preload.so.1

#
# We have to add the s9_preload library to the secure path or commands
# that run with setuid privileges (e.g. a shell via "su" from a normal user)
# will not be allowed to access the library.
#
SECURE_DEST=/usr/lib/secure/s9_preload.so.1
SECURE64_DEST=/usr/lib/secure/64/s9_preload.so.1

tag="pre_p2v"

if [ -f $S9_PRELOAD ]; then
	if [ ! -h $SECURE_DEST ]; then
		if [ -f /var/ld/ld.config -a ! -f /var/ld/ld.config.$tag ]; then
			cp -p /var/ld/ld.config /var/ld/ld.config.$tag
		fi
		ln -s $S9_PRELOAD $SECURE_DEST || exit 1
	fi

	crle -c /var/ld/ld.config -u -E LD_PRELOAD=$SECURE_DEST || exit 1
fi

if [ -f $S964_PRELOAD ]; then
	if [ ! -h $SECURE64_DEST ]; then
		if [ -f /var/ld/64/ld.config -a \
		    ! -f /var/ld/64/ld.config.$tag ]; then
			cp -p /var/ld/64/ld.config /var/ld/64/ld.config.$tag
		fi
		ln -s $S964_PRELOAD $SECURE64_DEST || exit 1
	fi

	crle -64 -c /var/ld/64/ld.config -u -E LD_PRELOAD=$SECURE64_DEST || exit 1
fi
