[[libvirt-glib PATCHv2] 2/4] Don't use g_error in xxx_get_name

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

 



g_error will trigger an abort of the running process so it's not
desirable to call it in a library. This commit adds a GError **
parameter to all _get_name methods which were calling g_error.
---
 libvirt-gobject/libvirt-gobject-connection.c      |   10 ++++++++--
 libvirt-gobject/libvirt-gobject-domain-snapshot.c |    5 ++++-
 libvirt-gobject/libvirt-gobject-domain.c          |    7 +++++--
 libvirt-gobject/libvirt-gobject-domain.h          |    2 +-
 libvirt-gobject/libvirt-gobject-interface.c       |    7 +++++--
 libvirt-gobject/libvirt-gobject-interface.h       |    2 +-
 libvirt-gobject/libvirt-gobject-network-filter.c  |    8 ++++++--
 libvirt-gobject/libvirt-gobject-network-filter.h  |    2 +-
 libvirt-gobject/libvirt-gobject-network.c         |    7 +++++--
 libvirt-gobject/libvirt-gobject-network.h         |    2 +-
 libvirt-gobject/libvirt-gobject-node-device.c     |    7 +++++--
 libvirt-gobject/libvirt-gobject-node-device.h     |    2 +-
 libvirt-gobject/libvirt-gobject-storage-pool.c    |    7 +++++--
 libvirt-gobject/libvirt-gobject-storage-pool.h    |    2 +-
 14 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index a90581a..c19e411 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1112,7 +1112,10 @@ GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
 
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         GVirDomain *dom = value;
-        const gchar *thisname = gvir_domain_get_name(dom);
+        const gchar *thisname = gvir_domain_get_name(dom, NULL);
+
+        if (thisname == NULL)
+            continue;
 
         if (strcmp(thisname, name) == 0) {
             g_object_ref(dom);
@@ -1143,7 +1146,10 @@ GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn,
 
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         GVirStoragePool *pool = value;
-        const gchar *thisname = gvir_storage_pool_get_name(pool);
+        const gchar *thisname = gvir_storage_pool_get_name(pool, NULL);
+
+        if (thisname == NULL)
+            continue;
 
         if (strcmp(thisname, name) == 0) {
             g_object_ref(pool);
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
index 950555a..0560595 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
@@ -166,7 +166,10 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot)
     const char *name;
 
     if (!(name = virDomainSnapshotGetName(priv->handle))) {
-        g_error("Failed to get domain_snapshot name on %p", priv->handle);
+        gvir_set_error(err, GVIR_DOMAIN_SNAPSHOT_ERROR, 0,
+                       "Failed to get domain_snapshot name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index c1a67a5..bfbb80f 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -264,13 +264,16 @@ G_DEFINE_BOXED_TYPE(GVirDomainInfo, gvir_domain_info,
                     gvir_domain_info_copy, gvir_domain_info_free)
 
 
-const gchar *gvir_domain_get_name(GVirDomain *dom)
+const gchar *gvir_domain_get_name(GVirDomain *dom, GError **err)
 {
     GVirDomainPrivate *priv = dom->priv;
     const char *name;
 
     if (!(name = virDomainGetName(priv->handle))) {
-        g_error("Failed to get domain name on %p", priv->handle);
+        gvir_set_error(err, GVIR_DOMAIN_ERROR, 0,
+                       "Failed to get domain name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 20388f2..d912b21 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -102,7 +102,7 @@ GType gvir_domain_get_type(void);
 GType gvir_domain_info_get_type(void);
 GType gvir_domain_handle_get_type(void);
 
-const gchar *gvir_domain_get_name(GVirDomain *dom);
+const gchar *gvir_domain_get_name(GVirDomain *dom, GError **error);
 const gchar *gvir_domain_get_uuid(GVirDomain *dom);
 gint gvir_domain_get_id(GVirDomain *dom,
                         GError **err);
diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c
index f7bdde8..095e22a 100644
--- a/libvirt-gobject/libvirt-gobject-interface.c
+++ b/libvirt-gobject/libvirt-gobject-interface.c
@@ -157,13 +157,16 @@ gvir_interface_handle_free(GVirInterfaceHandle *src)
 G_DEFINE_BOXED_TYPE(GVirInterfaceHandle, gvir_interface_handle,
                     gvir_interface_handle_copy, gvir_interface_handle_free)
 
-const gchar *gvir_interface_get_name(GVirInterface *iface)
+const gchar *gvir_interface_get_name(GVirInterface *iface, GError **err)
 {
     GVirInterfacePrivate *priv = iface->priv;
     const char *name;
 
     if (!(name = virInterfaceGetName(priv->handle))) {
-        g_error("Failed to get interface name on %p", priv->handle);
+        gvir_set_error(err, GVIR_INTERFACE_ERROR, 0,
+                       "Failed to get interface name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-interface.h b/libvirt-gobject/libvirt-gobject-interface.h
index e4b302b..5831cfa 100644
--- a/libvirt-gobject/libvirt-gobject-interface.h
+++ b/libvirt-gobject/libvirt-gobject-interface.h
@@ -62,7 +62,7 @@ struct _GVirInterfaceClass
 GType gvir_interface_get_type(void);
 GType gvir_interface_handle_get_type(void);
 
-const gchar *gvir_interface_get_name(GVirInterface *iface);
+const gchar *gvir_interface_get_name(GVirInterface *iface, GError **err);
 
 GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface,
                                                guint flags,
diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c
index fe1a042..473ef5d 100644
--- a/libvirt-gobject/libvirt-gobject-network-filter.c
+++ b/libvirt-gobject/libvirt-gobject-network-filter.c
@@ -173,13 +173,17 @@ gvir_network_filter_handle_free(GVirNetworkFilterHandle *src)
 G_DEFINE_BOXED_TYPE(GVirNetworkFilterHandle, gvir_network_filter_handle,
                     gvir_network_filter_handle_copy, gvir_network_filter_handle_free)
 
-const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter)
+const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter,
+                                          GError **err)
 {
     GVirNetworkFilterPrivate *priv = filter->priv;
     const char *name;
 
     if (!(name = virNWFilterGetName(priv->handle))) {
-        g_error("Failed to get network_filter name on %p", priv->handle);
+        gvir_set_error(err, GVIR_NETWORK_FILTER_ERROR, 0,
+                       "Failed to get network_filter name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-network-filter.h b/libvirt-gobject/libvirt-gobject-network-filter.h
index 24defdc..5465b0e 100644
--- a/libvirt-gobject/libvirt-gobject-network-filter.h
+++ b/libvirt-gobject/libvirt-gobject-network-filter.h
@@ -61,7 +61,7 @@ struct _GVirNetworkFilterClass
 GType gvir_network_filter_get_type(void);
 GType gvir_network_filter_handle_get_type(void);
 
-const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter);
+const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter, GError **err);
 const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter);
 
 GVirConfigNetworkFilter *gvir_network_filter_get_config
diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c
index 75e010d..143e80b 100644
--- a/libvirt-gobject/libvirt-gobject-network.c
+++ b/libvirt-gobject/libvirt-gobject-network.c
@@ -171,13 +171,16 @@ gvir_network_handle_free(GVirNetworkHandle *src)
 G_DEFINE_BOXED_TYPE(GVirNetworkHandle, gvir_network_handle,
                     gvir_network_handle_copy, gvir_network_handle_free)
 
-const gchar *gvir_network_get_name(GVirNetwork *network)
+const gchar *gvir_network_get_name(GVirNetwork *network, GError **err)
 {
     GVirNetworkPrivate *priv = network->priv;
     const char *name;
 
     if (!(name = virNetworkGetName(priv->handle))) {
-        g_error("Failed to get network name on %p", priv->handle);
+        gvir_set_error(err, GVIR_NETWORK_ERROR, 0,
+                       "Failed to get network name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h
index f85aed6..a6ffba9 100644
--- a/libvirt-gobject/libvirt-gobject-network.h
+++ b/libvirt-gobject/libvirt-gobject-network.h
@@ -65,7 +65,7 @@ struct _GVirNetworkClass
 GType gvir_network_get_type(void);
 GType gvir_network_handle_get_type(void);
 
-const gchar *gvir_network_get_name(GVirNetwork *network);
+const gchar *gvir_network_get_name(GVirNetwork *network, GError **err);
 const gchar *gvir_network_get_uuid(GVirNetwork *network);
 
 GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network,
diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c
index f8d536e..55f7098 100644
--- a/libvirt-gobject/libvirt-gobject-node-device.c
+++ b/libvirt-gobject/libvirt-gobject-node-device.c
@@ -157,13 +157,16 @@ gvir_node_device_handle_free(GVirNodeDeviceHandle *src)
 G_DEFINE_BOXED_TYPE(GVirNodeDeviceHandle, gvir_node_device_handle,
                     gvir_node_device_handle_copy, gvir_node_device_handle_free)
 
-const gchar *gvir_node_device_get_name(GVirNodeDevice *device)
+const gchar *gvir_node_device_get_name(GVirNodeDevice *device, GError **err)
 {
     GVirNodeDevicePrivate *priv = device->priv;
     const char *name;
 
     if (!(name = virNodeDeviceGetName(priv->handle))) {
-        g_error("Failed to get node_device name on %p", priv->handle);
+        gvir_set_error(err, GVIR_NODE_DEVICE_ERROR, 0,
+                       "Failed to get node_device name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-node-device.h b/libvirt-gobject/libvirt-gobject-node-device.h
index 84a4234..3b57f99 100644
--- a/libvirt-gobject/libvirt-gobject-node-device.h
+++ b/libvirt-gobject/libvirt-gobject-node-device.h
@@ -61,7 +61,7 @@ struct _GVirNodeDeviceClass
 GType gvir_node_device_get_type(void);
 GType gvir_node_device_handle_get_type(void);
 
-const gchar *gvir_node_device_get_name(GVirNodeDevice *device);
+const gchar *gvir_node_device_get_name(GVirNodeDevice *device, GError **err);
 
 GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device,
                                                   guint flags,
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index a88699e..d2ee6d6 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -203,13 +203,16 @@ gvir_storage_pool_info_free(GVirStoragePoolInfo *info)
 G_DEFINE_BOXED_TYPE(GVirStoragePoolInfo, gvir_storage_pool_info,
                     gvir_storage_pool_info_copy, gvir_storage_pool_info_free)
 
-const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool)
+const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool, GError **err)
 {
     GVirStoragePoolPrivate *priv = pool->priv;
     const char *name;
 
     if (!(name = virStoragePoolGetName(priv->handle))) {
-        g_error("Failed to get storage_pool name on %p", priv->handle);
+        gvir_set_error(err, GVIR_STORAGE_POOL_ERROR, 0,
+                       "Failed to get storage_pool name on %p",
+                       priv->handle);
+        return NULL;
     }
 
     return name;
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h
index 4589844..78dd987 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.h
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.h
@@ -80,7 +80,7 @@ GType gvir_storage_pool_get_type(void);
 GType gvir_storage_pool_info_get_type(void);
 GType gvir_storage_pool_handle_get_type(void);
 
-const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool);
+const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool, GError **err);
 const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool);
 
 GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
-- 
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]