Here is an alternative way to start Icon binaries on Linux (tested on
RedHat 7.3), slightly more efficient than the usual one.

If you compile Icon after removing the defines for Header and
ShellHeader in src/h/config.h, icont will produce a file containing
only a 108 byte header followed by icode (gzipped when using my
patch). The 300+ byte shell script is gone. Bash and sed will not be
invoked.

If you now try to execute unicon you get "cannot execute binary file".
So how do you associate a file (unicon) with an interpreter (iconx)?
The way Linux does it is by examining the first 128 bytes of the file
to be executed for some magic cookie that identifies the format and by
invoking its associated handler. It knows for instance about the ELF
format (the format of machine code executables like ls).  One could
change icont to generate an ELF image because it can be associated
with a special handler as well, but I digress. The easy way to do it
is by using the binfmt_misc kernel hook. This makes it possible to add
associations dynamically and determine a known format recursively (in
our case ELF for iconx). On RedHat binfmt_misc is not compiled into
the kernel but available as a kernel module, complicating the setup
slightly.  The Icon header happens to contain a magic cookie starting
at offset 44 (I9.U.00/32).

Assuming iconx is installed in /usr/bin, here is one way to
do the setup:

#!/bin/sh
cat >>/etc/rc.d/rc.local <<'EOT'
modprobe binfmt_misc
echo ':icon:M:44:I9.U.00/32::/usr/bin/iconx:' >/proc/sys/fs/binfmt_misc/register
EOT
cat >>/etc/modules.conf <<'EOT'
post-install binfmt_misc mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
pre-remove binfmt_misc umount /proc/sys/fs/binfmt_misc
EOT

and now either reboot or do the modprobe and echo manually.

It's nice to also let the `file' command know about the new binary format:

#!/bin/sh
cat >>/usr/share/magic <<'EOT'
# icode created by icont
44      string  I9.U.00/32      Icon 9 32-bit binary
EOT
file -C /usr/share/magic

-- 
Cheers,

Jan Bernard van Doorn


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to