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 f0c9ff6..e162867 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1116,7 +1116,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); @@ -1147,7 +1150,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 e68321d..3680cb8 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -168,7 +168,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 2974bb8..dc3f55e 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -268,13 +268,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 7e6e9b0..09c01dc 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -158,13 +158,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 f0fd024..c0a6a2b 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -175,13 +175,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 847c236..36f9a00 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -173,13 +173,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 59fe84b..bf514b1 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.c +++ b/libvirt-gobject/libvirt-gobject-node-device.c @@ -159,13 +159,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 13a7f59..f0b801e 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -204,13 +204,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 778844b..754af73 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.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list