On 11/23/19 9:46 AM, Richard W.M. Jones wrote:

I think an aim of nbdkit is to make it as widely usable as possible.
That's for example why we have apparent esoterica like plugins written
in shell script.

We want to in the future ship the (or "an") imageio plugin separately
from virt-v2v.  A possibility is it might be shipped as a single
Python file which starts with ‘#!/usr/bin/env nbdkit python’ which

That is not portable; not all kernels permit more than one argument in #!. You can work around it with modern env (both BSD and Coreutils have recently added -S), as:

#!/usr/bin/env -S nbdkit python

which will then invoke the desired 'nbdkit' 'python' 'file' regardless of whether the OS invoked 'env' '-S nbdkit python' (Linux) or 'env' '-S' 'nbdkit' 'python' (others). But that in turn assumes env -S is portable (it's fairly new, so not yet). Otherwise, interpreted plugin shebangs really do have to hard-code the expected path of nbdkit rather than relying on env, unless we find a way to make:

nbdkit file

determine that when 'nbdkit-plugin-file.so' does not exist but 'file' does, then inspect file to determine if 'nbdkit-plugin-interpreter.so' exists based on the first line of file.

Except that would mean the first line changes to:

#!/usr/bin/env nbdkit

which lacks the desired interpreter, so we'd still have to add something like documenting that if the first line of the #! contains 'nbdkit', then the second line is some form of magic comment that includes the substring 'PLUGIN=...' (we have to allow arbitrary slop as prefix or suffix after a plugin name, to allow the second line to be a comment or otherwise innocuous interpreted line in whatever desired target language), so we end up with:

#!/usr/bin/env nbdkit
# PLUGIN=python

where the initial invocation of '/usr/bin/env' 'nbdkit' 'file'
then passes on to '/path/to/nbdkit' 'file'
which sees that 'file' is not a plugin, but does have magic, so it then retries as if invoked as '/path/to/nbdkit' 'python' 'file'

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to