Next: , Previous: binfmt registry, Up: binfmt


G.4 Using the mechanism

We may want to add the binary formats in one of the shell scripts that are executed at system boot time. For example, on a Slackware Linux system we can use /etc/rc.d/rc.local.

To do it we can add to the shell script a chunk of code like the following, which activates the mechanism for Scheme programs compiled with Vicare:

     if test -f /proc/sys/fs/binfmt_misc/register
     then
       if test -f /proc/sys/fs/binfmt_misc/VICARE
       then echo -1 >/proc/sys/fs/binfmt_misc/VICARE
       fi
       echo \
        ':VICARE:M:0:;;;!vicare::/usr/local/bin/vicare:' \
        >/proc/sys/fs/binfmt_misc/register
     fi

which does the following:

  1. Verify if the binfmt_misc kernel module has been loaded by testing the existence of the register file; if the module is not there, nothing happens.
  2. Remove the configuration from the registry if it is already there; this is done by testing the existence of the special file:
              /proc/sys/fs/binfmt_misc/VICARE
    

    echoing -1 in it removes the Vicare record.

  3. echo the Vicare record into the registry with the following fields:
    VICARE
    It is the name of the special file representing the record in the registry.
    M
    Activates first bytes recognition.
    0
    The offset of the magic string into the file.
    ;;;!vicare
    The magic string itself.
    /usr/local/bin/vicare
    The full pathname to the Vicare runtime system executable.

We see that the mask field is set to the empty string, that is: no mask is applied and #!vicare is matched literally.

We have to care about the order of added entries: entries added later are matched first.