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

[libvirt] [PATCH] Introduce virSaveLastError(), virFreeError()



# HG changeset patch
# User john levon sun com
# Date 1233870901 28800
# Node ID 2c12bdf95e5e5f7d00b606df679364463555d76e
# Parent  059167552cb467c107870c3b739438ca107116a8
Introduce virSaveLastError(), virFreeError()

Allow applications to store a copy of the last error reported.

Signed-off-by: John Levon <john levon sun com>

diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -172,8 +172,10 @@ typedef void (*virErrorFunc) (void *user
  */
 
 virErrorPtr		virGetLastError		(void);
+virErrorPtr		virSaveLastError	(void);
 void			virResetLastError	(void);
 void			virResetError		(virErrorPtr err);
+void			virFreeError		(virErrorPtr err);
 
 virErrorPtr		virConnGetLastError	(virConnectPtr conn);
 void			virConnResetLastError	(virConnectPtr conn);
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -247,4 +247,10 @@ LIBVIRT_0.6.0 {
 
 } LIBVIRT_0.5.0;
 
+LIBVIRT_0.6.1 {
+    global:
+	virFreeError;
+	virSaveLastError;
+} LIBVIRT_0.6.0;
+
 # .... define new API here using predicted next version number ....
diff --git a/src/virterror.c b/src/virterror.c
--- a/src/virterror.c
+++ b/src/virterror.c
@@ -286,6 +286,27 @@ virCopyLastError(virErrorPtr to)
 }
 
 /**
+ * virSaveLastError:
+ *
+ * Save the last error into a new error object.
+ *
+ * Returns a pointer to the copied error or NULL if allocation failed.
+ * It is the caller's responsibility to free the error with
+ * virFreeError().
+ */
+virErrorPtr
+virSaveLastError(void)
+{
+    virErrorPtr to;
+
+    if (VIR_ALLOC(to) < 0)
+        return NULL;
+
+    virCopyLastError(to);
+    return to;
+}
+
+/**
  * virResetError:
  * @err: pointer to the virError to clean up
  *
@@ -303,6 +324,18 @@ virResetError(virErrorPtr err)
     memset(err, 0, sizeof(virError));
 }
 
+/**
+ * virFreeError:
+ * @err: error to free
+ *
+ * Resets and frees the given error.
+ */
+void
+virFreeError(virErrorPtr err)
+{
+    virResetError(err);
+    VIR_FREE(err);
+}
 
 /**
  * virResetLastError:


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