From 30eaa5a344f0a568010c8a9cb551ed114268a182 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mar 24 2011 14:36:53 +0000 Subject: - when we're returning an error we generated, the hint is the error - don't try to print a NULL hint --- diff --git a/src/getcert.c b/src/getcert.c index 9b67f78..afc6996 100644 --- a/src/getcert.c +++ b/src/getcert.c @@ -186,8 +186,9 @@ prep_req(enum cm_tdbus_type which, /* Try to offer some advice based on the error. */ static const char * -print_hint(const char *error) +print_hint(const char *error, const char *message) { + char *buf = NULL; const char *text = NULL; if (strcmp(error, DBUS_ERROR_ACCESS_DENIED) == 0) { text = _("Insufficient access. Please retry operation as root.\n"); @@ -201,8 +202,20 @@ print_hint(const char *error) } else if (strcmp(error, DBUS_ERROR_NO_SERVER) == 0) { text = _("Please verify that the message bus (D-Bus) service is running.\n"); + } else + if (strncmp(error, CM_DBUS_ERROR_BASE, + strlen(CM_DBUS_ERROR_BASE)) == 0) { + text = _(message); + buf = malloc(strlen(text) + 2); + if (buf != NULL) { + sprintf(buf, "%s\n", text); + text = buf; + } + } + if (text != NULL) { + printf("%s", text); } - printf("%s", text); + free(buf); return text; } @@ -218,12 +231,16 @@ send_req(DBusMessage *req, int verbose) if (rep == NULL) { if (dbus_error_is_set(&err)) { if (err.name != NULL) { - if ((print_hint(err.name) == NULL) || verbose) { + if ((print_hint(err.name, + err.message) == NULL) || + verbose) { if ((err.message != NULL) && verbose) { - printf(_("Error %s: %s\n"), err.name, + printf(_("Error %s: %s\n"), + err.name, err.message); } else { - printf(_("Error %s\n"), err.name); + printf(_("Error %s\n"), + err.name); } } } else {