[RFC PATCH 01/41] virErrorPreserveLast: Return the saved error object in addition to storing it

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

 



In some cases it's easier to use the returned value rather than passing
the variable pointer in via argument.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virerror.c | 18 ++++++++++++------
 src/util/virerror.h |  2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/util/virerror.c b/src/util/virerror.c
index 774c36bca3..1277a0bdfc 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -417,22 +417,28 @@ virSaveLastError(void)
  * virErrorPreserveLast:
  * @saveerr: pointer to virErrorPtr for storing last error object
  *
- * Preserves the currently set last error (for the thread) into @saveerr so that
- * it can be restored via virErrorRestore(). @saveerr must be passed to
+ * Preserves the currently set last error (for the thread) into @saveerr (if
+ * non-NULL) and in the return value so that it can be restored via
+ * virErrorRestore(). @saveerr or the return value must be passed to
  * virErrorRestore()
+ *
+ * Returns the last error object or NULL if there is no error.
  */
-void
+virErrorPtr
 virErrorPreserveLast(virErrorPtr *saveerr)
 {
     int saved_errno = errno;
     virErrorPtr lasterr = virGetLastError();
-
-    *saveerr = NULL;
+    virErrorPtr copy = NULL;

     if (lasterr)
-        *saveerr = virErrorCopyNew(lasterr);
+        copy = virErrorCopyNew(lasterr);
+
+    if (saveerr)
+        *saveerr = copy;

     errno = saved_errno;
+    return copy;
 }


diff --git a/src/util/virerror.h b/src/util/virerror.h
index 9d3e40d65a..42f2835a85 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -200,7 +200,7 @@ void virErrorSetErrnoFromLastError(void);

 bool virLastErrorIsSystemErrno(int errnum);

-void virErrorPreserveLast(virErrorPtr *saveerr);
+virErrorPtr virErrorPreserveLast(virErrorPtr *saveerr);
 void virErrorRestore(virErrorPtr *savederr);

 void virLastErrorPrefixMessage(const char *fmt, ...)
-- 
2.26.2




[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]

  Powered by Linux