[[libvirt-glib PATCHv3] 1/3] Add proper error reporting to gvir_storage_vol_get_path

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

 



gvir_storage_vol_get_name currently call g_error when an error occurs.
Since g_error trigger a coredump, calling it in a library is harmful.
Replace this with proper GError error reporting.
---
 libvirt-gobject/libvirt-gobject-storage-vol.c |    7 +++++--
 libvirt-gobject/libvirt-gobject-storage-vol.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 5b18877..5e83e1b 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -184,13 +184,16 @@ const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol)
     return name;
 }
 
-const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol)
+const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol, GError **error)
 {
     GVirStorageVolPrivate *priv = vol->priv;
     const char *path;
 
     if (!(path = virStorageVolGetPath(priv->handle))) {
-        g_error("Failed to get storage_vol path on %p", priv->handle);
+        gvir_set_error(error, GVIR_STORAGE_VOL_ERROR, 0,
+                       "Failed to get storage_vol path on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return path;
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h
index db63865..25f683a 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.h
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
@@ -78,7 +78,7 @@ GType gvir_storage_vol_info_get_type(void);
 GType gvir_storage_vol_handle_get_type(void);
 
 const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol);
-const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
+const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol, GError **error);
 
 gboolean gvir_storage_vol_delete(GVirStorageVol *vol,
                                  guint flags,
-- 
1.7.7.6

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