Monday February 04, 2008 I wanted a single ~/bin in my home dir that could cope with 32 vs 64 and SPARC vs x86 and also allow me to have CPU capability variants as well, ie sparcv9+vis2 and a generic sparcv8 variant. So I rewrote isaexec as a simple shell script, I don't know how long ago I did this but it was probably some time during Solaris 7 development (which is when isaexec first appeared), anyway below is the shell script. I have subdirs in ~/bin for each cpu/architecture and all the binaries are links to ~/bin/isaexec.sh
#!/bin/ksh
fname=`basename $0`
pathname=`dirname $0`
if [ ! -x /usr/bin/isalist ]; then
arch=`arch`
if [ ! -x $pathname/$arch/$fname ]; then
echo "$0: cannot find the ISA list";
else
exec $pathname/$arch/$fname
echo "$0: cannon find/execute $fname in ISA subdirectories"
fi
fi
for isa in `/usr/bin/isalist` ; do
execpath="${pathname}/${isa}/${fname}"
if [ -x $execpath ]; then
exec $execpath "$@"
echo "$0 exec $execpath failed"
fi
done
echo "$0: cannon find/execute $fname in ISA subdirectories"
exit 1;
This far from perfect shell script from a performance view point and could probably use much more shell builtin functionality if ksh (or ksh93) was used instead.
( Feb 04 2008, 01:08:22 PM GMT ) Permalink Comments [1]
The ksh93 version of the script would look like this (per http://www.opensolaris.org/os/project/shell/shellstyle/ and some security issues fixed):
-- snip --
#!/usr/bin/ksh93
builtin basename
builtin dirname
IFS=''
typeset fname="$(basename "$0")"
typeset pathname="$(dirname $0)"
if [[ ! -x /usr/bin/isalist ]]; then
arch="$(/usr/bin/arch)"
if [[ ! -x "$pathname/$arch/$fname" ]]; then
print -n2 -f "%s: cannot find the ISA list" "$0";
else
exec "$pathname/$arch/$fname"
print -n2 -f "%s: cannon find/execute %s in ISA subdirectories" "$0" "$fname"
fi
fi
for isa in $(/usr/bin/isalist) ; do
execpath="${pathname}/${isa}/${fname}"
if [[ -x "$execpath" ]]; then
exec $execpath "$@"
print -n2 -f "%s: exec %s failed" "$0" "$execpath"
fi
done
print -n2 -f "%s: cannon find/execute %s in ISA subdirectories" "$0" "$fname"
exit 1;
-- snip --
Posted by Roland Mainz on February 04, 2008 at 11:11 PM GMT #