[Libguestfs] [PATCH v3 8/8] lib/canonical-name.c: Hide EINVAL error from underlying API call.
Richard W.M. Jones
rjones at redhat.com
Fri Oct 9 10:37:41 UTC 2020
On Fri, Oct 09, 2020 at 11:33:43AM +0100, Richard W.M. Jones wrote:
>
> This is the patch I tested which works (on top of the
> patch posted):
>
> diff --git a/lib/canonical-name.c b/lib/canonical-name.c
> index e0c7918b4..ae4def692 100644
> --- a/lib/canonical-name.c
> +++ b/lib/canonical-name.c
> @@ -53,8 +53,16 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device)
> * BitLocker-encrypted volume, so simply return the original
> * name in that case.
> */
> - if (ret == NULL && guestfs_last_errno (g) == EINVAL)
> - ret = safe_strdup (g, device);
> + if (ret == NULL) {
> + if (guestfs_last_errno (g) == EINVAL)
> + ret = safe_strdup (g, device);
> + else
> + /* Make sure the original error gets pushed through the
> + * error handlers.
> + */
> + guestfs_int_error_errno (g, guestfs_last_errno (g),
> + "%s", guestfs_last_error (g));
> + }
> }
> else
> ret = safe_strdup (g, device);
>
> ---
>
> Current upstream:
>
> $ guestfish scratch 1M : run : canonical-device-name "/dev/dm-999"
> libguestfs: error: lvm_canonical_lv_name: stat: /dev/dm-999: No such file or directory
> /dev/dm-999 <-----
>
> Patch posted without the above patch added:
>
> $ ./run guestfish scratch 1M : run : canonical-device-name "/dev/dm-999"
>
> (no output, but the command fails with exit code 1)
>
> Patch posted + above patch:
>
> $ ./run guestfish scratch 1M : run : canonical-device-name "/dev/dm-999"
> libguestfs: error: lvm_canonical_lv_name: stat: /dev/dm-999: No such file or directory
Actually I didn't notice this, but it improves on the current upstream
behaviour.
Current upstream calls the error handlers and returns a non-error
original string (see <----- line above) and exit code 0. With the
patch we return an error.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the Libguestfs
mailing list