qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] error: error_setg_errno(): errno gets preserved


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] error: error_setg_errno(): errno gets preserved
Date: Wed, 27 Jul 2016 14:42:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 07/27/2016 03:24 AM, Sascha Silbe wrote:
> C11 allows errno to be clobbered by pretty much any library function
> call, so in general callers need to take care to save errno before
> calling other functions.
> 
> However, for error reporting functions this is rather awkward and can
> make the code on the caller side more complicated than
> necessary. error_setg_errno() already takes care of preserving errno
> and some functions rely on that, so just promise that we continue to
> do so in the future.
> 
> Signed-off-by: Sascha Silbe <address@hidden>
> ---
> 
> Alternative approach to "error: error_setg_errno(): errno may be
> clobbered" [1].

I like this alternative better.


> +++ b/include/qapi/error.h
> @@ -170,6 +170,9 @@ void error_setg_internal(Error **errp,
>   * Just like error_setg(), with @os_error info added to the message.
>   * If @os_error is non-zero, ": " + strerror(os_error) is appended to
>   * the human-readable error message.
> + *
> + * The value of errno (which usually can get clobbered by almost any
> + * function call) will be preserved.
>   */
>  #define error_setg_errno(errp, os_error, fmt, ...)                      \
>      error_setg_errno_internal((errp), __FILE__, __LINE__, __func__,     \

Do we need/want to make the guarantee of preserving errno across any of
the other functions and macros declared in error.h?

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]