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

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

On 12/23/2010 02:30 PM, Eric Blake wrote:
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 __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
      /* 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.

I squashed in a bit of code to preserve errno during VIR_FREE (virFree) as you suggested in the review of patch 3/3 and pushed the result.


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