[Libguestfs] [nbdkit PATCH v2 4/6] plugins: Add new nbdkit_set_error() utility function

Richard W.M. Jones rjones at redhat.com
Thu Jan 26 10:13:28 UTC 2017


On Wed, Jan 25, 2017 at 08:42:34PM -0600, Eric Blake wrote:
> +eg. NULL or -1.  If the call to C<nbdkit_set_error> is omitted, then
> +the value of C<errno> will be used instead.
[...]
> +/* Grab the appropriate error value.
> + */
> +static int
> +_get_error (void)
> +{
> +  int err = errno;
> +  int ret = tls_get_error ();
> +
> +  if (!ret)
> +    ret = err ? err : EIO;
> +  return ret;
> +}

I don't think we should use the implicit errno.

The reason is that we cannot be sure that errno is meaningful in
language bindings.  A lot of code could run between (eg) a Perl plugin
seeing a system call fail, and that plugin callback returning to
nbdkit code, and any of that code might touch errno.  Since some of
that code would be in the language interpreter, we cannot even be
careful about preserving errno along those paths.

So I think if the caller didn't call nbdkit_set_errno, we should
assume no errno value is available for us to use.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list