darren_moffat@blog$ cat /dev/mem | grep /dev/urandom

« Previous day (Feb 3, 2008) | Main | Next day (Feb 4, 2008) »

20080204 Monday February 04, 2008

isaexec(1) as a shell script

/usr/lib/isaexecis often used to provide automatic selection of a 32 vs 64 bit binary, however it can actually do much more than that it can pick between sparcv8+vis and sparcv8 for example. What it can't do in its distributed form is pick between SPARC and x86 variants because it is a 32 bit binary.

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]


Valid HTML! Valid CSS!


follow darrenmoffat at http://twitter.com
Get OpenSolaris  Use OpenOffice.org

This is a personal weblog, I do not speak for my employer.