Re: [PATCH 1/3] Preserve errno across calls to error reporting functions

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

 



On 12/23/2010 11:39 AM, Laine Stump wrote:
> There are cases when we want log an error message while still
> preserving errno for a caller, but the functions that log errors make
> system calls that will clear errno. This patch preserves errno during
> those most basic error logging functions (corresponding to
> virReportSystemError(), virReportOOMError(), networkReportError(),
> etc, as well as virStrError()). It does *not preserve errno across
> calls to higher level items such as virDispatchError(), as it's
> assumed the caller is all finished with any need for errno by the time
> it dispatches the error.

>  const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen)
>  {
> +    int save_errno = errno;
> +    const char *ret;
> +
>  #ifdef HAVE_STRERROR_R
>  # ifdef __USE_GNU
>      /* Annoying linux specific API contract */
> -    return strerror_r(theerrno, errBuf, errBufLen);
> +    ret = strerror_r(theerrno, errBuf, errBufLen);
>  # else
>      strerror_r(theerrno, errBuf, errBufLen);
> -    return errBuf;
> +    ret = errBuf;
>  # endif
>  #else
>      /* Mingw lacks strerror_r and its strerror is definitely not

Ah, but gnulib now provides the LGPLv2+ strerror_r-posix module, which
not only provides strerror_r on mingw, but also sanitizes the Linux
interface into the POSIX compatible interface, so that we could use it
to simplify the code.  But that's a patch for another day.

ACK as-is.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]