[Libguestfs] [nbdkit PATCH v3 1/4] plugins: Don't use bogus errno from non-C plugins

Eric Blake eblake at redhat.com
Fri Jan 27 14:01:17 UTC 2017


On 01/27/2017 04:11 AM, Richard W.M. Jones wrote:
> 
> Actually OCaml is a real compiled language, and the call from C to
> OCaml code (via caml_callback_exn) is a short piece of asm which
> preserves errno.

Which shows my lack of familiarity with OCaml; but I'm guessing that
also means that OCaml comes with easy ways to directly set errno so that
it will be visible from C.

> 
> However you'll need to save errno around caml_enter_blocking_section
> since that unblocks and processes signals.
> 
> IOW:
> 
>   static int
>   pread_wrapper (void *h, void *buf, uint32_t count, uint64_t offset)
>   {
>     CAMLparam0 ();
>     CAMLlocal3 (rv, strv, offsetv);
> +   int saved_errno;
> ...
>     rv = caml_callback3_exn (pread_fn, *(value *) h, strv, offsetv);
> +   saved_errno = errno;
>     if (Is_exception_result (rv)) {
>       nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
>       caml_enter_blocking_section ();
> +     errno = saved_errno;
>       CAMLreturnT (int, -1);

Okay, I'll respin the patch along these lines.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170127/8eaad162/attachment.sig>


More information about the Libguestfs mailing list