summaryrefslogtreecommitdiffstats
path: root/src/software-dbus
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2014-03-28 15:00:54 +0100
committerPeter Schiffer <pschiffe@redhat.com>2014-03-28 16:55:08 +0100
commit56bc3cca9f608b9243b413cf8b52a7c416aac63f (patch)
tree03b2123d3f80799183a70e1a382c9c910c2afa95 /src/software-dbus
parent3ae5f8606e63e820359e16186b96938d5a23bcea (diff)
downloadopenlmi-providers-56bc3cca9f608b9243b413cf8b52a7c416aac63f.tar.gz
openlmi-providers-56bc3cca9f608b9243b413cf8b52a7c416aac63f.tar.xz
openlmi-providers-56bc3cca9f608b9243b413cf8b52a7c416aac63f.zip
Software-dbus: enhanced error reporting
Diffstat (limited to 'src/software-dbus')
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityProvider.c48
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityResourceProvider.c14
-rw-r--r--src/software-dbus/sw-utils.c35
-rw-r--r--src/software-dbus/sw-utils.h4
4 files changed, 66 insertions, 35 deletions
diff --git a/src/software-dbus/LMI_SoftwareIdentityProvider.c b/src/software-dbus/LMI_SoftwareIdentityProvider.c
index 73a8ae5..09fbd93 100644
--- a/src/software-dbus/LMI_SoftwareIdentityProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityProvider.c
@@ -45,6 +45,7 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames(
{
PkTask *task = NULL;
PkResults *results = NULL;
+ GError *gerror = NULL;
GPtrArray *array = NULL;
SwPackage sw_pkg;
unsigned i;
@@ -55,9 +56,9 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames(
task = pk_task_new();
- results = pk_task_get_packages_sync(task, 0, NULL, NULL, NULL, NULL);
- if (check_and_create_error_msg(results, "Getting list of packages failed",
- error_msg, ERROR_MSG_LEN)) {
+ results = pk_task_get_packages_sync(task, 0, NULL, NULL, NULL, &gerror);
+ if (check_and_create_error_msg(results, gerror,
+ "Getting list of packages failed", error_msg, ERROR_MSG_LEN)) {
goto done;
}
@@ -82,6 +83,8 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames(
}
done:
+ g_clear_error(&gerror);
+
if (task) {
g_object_unref(task);
}
@@ -120,6 +123,7 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance(
PkPackage *pk_pkg = NULL;
PkDetails *pk_det = NULL;
PkResults *results = NULL, *results2 = NULL;
+ GError *gerror = NULL;
GPtrArray *array = NULL;
gchar **values = NULL;
SwPackage sw_pkg;
@@ -147,8 +151,8 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance(
values[0] = g_strdup(sw_pkg.name);
values[1] = NULL;
- results = pk_task_resolve_sync(task, 0, values, NULL, NULL, NULL, NULL);
- if (check_and_create_error_msg(results, "Resolving package failed",
+ results = pk_task_resolve_sync(task, 0, values, NULL, NULL, NULL, &gerror);
+ if (check_and_create_error_msg(results, gerror, "Resolving package failed",
error_msg, ERROR_MSG_LEN)) {
goto done;
}
@@ -189,21 +193,24 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance(
g_free(values[0]);
values[0] = g_strdup(pk_package_get_id(pk_pkg));
- results2 = pk_task_get_details_sync(task, values, NULL, NULL, NULL, NULL);
- if (check_and_create_error_msg(results2, "Getting package details failed",
- error_msg, ERROR_MSG_LEN)) {
- goto done;
- }
-
- g_ptr_array_unref(array);
- array = pk_results_get_details_array(results2);
- for (j = 0; j < array->len; j++) {
- pk_det = g_ptr_array_index(array, j);
- if (strcmp(pk_details_get_package_id(pk_det),
- pk_package_get_id(pk_pkg)) == 0) {
- LMI_SoftwareIdentity_Set_Description(&w,
- pk_details_get_description(pk_det));
- break;
+ results2 = pk_task_get_details_sync(task, values, NULL, NULL, NULL,
+ &gerror);
+ if (check_and_create_error_msg(results2, gerror,
+ "Getting package details failed", error_msg, ERROR_MSG_LEN)) {
+ warn(error_msg);
+ /* This is non-fatal problem. */
+ error_msg[0] = '\0';
+ } else {
+ g_ptr_array_unref(array);
+ array = pk_results_get_details_array(results2);
+ for (j = 0; j < array->len; j++) {
+ pk_det = g_ptr_array_index(array, j);
+ if (strcmp(pk_details_get_package_id(pk_det),
+ pk_package_get_id(pk_pkg)) == 0) {
+ LMI_SoftwareIdentity_Set_Description(&w,
+ pk_details_get_description(pk_det));
+ break;
+ }
}
}
@@ -213,6 +220,7 @@ done:
free_sw_package(&sw_pkg);
g_strfreev(values);
+ g_clear_error(&gerror);
if (task) {
g_object_unref(task);
diff --git a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
index ecf1391..c92900e 100644
--- a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
@@ -58,6 +58,7 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances(
{
PkTask *task = NULL;
PkResults *results = NULL;
+ GError *gerror = NULL;
GPtrArray *array = NULL;
gboolean repo_enabled;
gchar *repo_id = NULL, *repo_desc = NULL;
@@ -67,8 +68,8 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances(
task = pk_task_new();
- results = pk_task_get_repo_list_sync(task, 0, NULL, NULL, NULL, NULL);
- if (check_and_create_error_msg(results,
+ results = pk_task_get_repo_list_sync(task, 0, NULL, NULL, NULL, &gerror);
+ if (check_and_create_error_msg(results, gerror,
"Getting list of repositories failed", error_msg, ERROR_MSG_LEN)) {
goto done;
}
@@ -133,6 +134,8 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances(
}
done:
+ g_clear_error(&gerror);
+
if (task) {
g_object_unref(task);
}
@@ -254,6 +257,7 @@ KUint32 LMI_SoftwareIdentityResource_RequestStateChange(
KUint32 result = KUINT32_INIT;
PkTask *task = NULL;
PkResults *results = NULL;
+ GError *gerror = NULL;
gboolean enable;
char error_msg[ERROR_MSG_LEN] = "";
unsigned ret = 1;
@@ -285,8 +289,8 @@ KUint32 LMI_SoftwareIdentityResource_RequestStateChange(
task = pk_task_new();
results = pk_task_repo_enable_sync(task, self->Name.chars, enable, NULL,
- NULL, NULL, NULL);
- if (check_and_create_error_msg(results,
+ NULL, NULL, &gerror);
+ if (check_and_create_error_msg(results, gerror,
"Failed to set repository state", error_msg, ERROR_MSG_LEN)) {
goto done;
}
@@ -294,6 +298,8 @@ KUint32 LMI_SoftwareIdentityResource_RequestStateChange(
ret = 0;
done:
+ g_clear_error(&gerror);
+
if (task) {
g_object_unref(task);
}
diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c
index ca9722a..3cfa175 100644
--- a/src/software-dbus/sw-utils.c
+++ b/src/software-dbus/sw-utils.c
@@ -201,22 +201,39 @@ void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
pkg->version, pkg->release, pkg->arch);
}
-short check_and_create_error_msg(PkResults *results, const char *custom_msg,
- char *error_msg, const unsigned error_msg_len)
+short check_and_create_error_msg(PkResults *results, GError *gerror,
+ const char *custom_msg, char *error_msg, const unsigned error_msg_len)
{
short ret = 0;
PkError *error_code = NULL;
- error_code = pk_results_get_error_code(results);
- if (error_code) {
- snprintf(error_msg, error_msg_len,
- "%s: %s, %s", custom_msg,
- pk_error_enum_to_string(pk_error_get_code(error_code)),
- pk_error_get_details(error_code));
- g_object_unref(error_code);
+ if (results) {
+ error_code = pk_results_get_error_code(results);
+ if (error_code) {
+ snprintf(error_msg, error_msg_len,
+ "%s: %s, %s", custom_msg,
+ pk_error_enum_to_string(pk_error_get_code(error_code)),
+ pk_error_get_details(error_code));
+ g_object_unref(error_code);
+ ret = 1;
+ goto done;
+ }
+ }
+
+ if (gerror) {
+ snprintf(error_msg, error_msg_len, "%s: %s", custom_msg,
+ gerror->message);
+ ret = 1;
+ goto done;
+ }
+
+ if (!results) {
+ snprintf(error_msg, error_msg_len, "%s: Nothing returned", custom_msg);
ret = 1;
+ goto done;
}
+done:
return ret;
}
diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h
index 5e61ccb..0735259 100644
--- a/src/software-dbus/sw-utils.h
+++ b/src/software-dbus/sw-utils.h
@@ -100,8 +100,8 @@ void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
* @return 0 if no error occurred, positive value if error occurred
* and error_msg was modified
*/
-short check_and_create_error_msg(PkResults *results, const char *custom_msg,
- char *error_msg, const unsigned error_msg_len);
+short check_and_create_error_msg(PkResults *results, GError *gerror,
+ const char *custom_msg, char *error_msg, const unsigned error_msg_len);
/*
* Create standard instance ID based on class name and ID.