- there was a minor problem - no ticket ## in the commit message, so I
choosed #74, but try to not forget about it next time
On 04/15/2013 01:42 PM, Denys Vlasenko wrote:
Instead of "(exited with N)" show
"('EVENT_NAME' exited with N)".
Factor out the code which generates tese messages.
v2: mark all messages for translation.
Signed-off-by: Denys Vlasenko <dvlasenk(a)redhat.com>
---
src/cli/cli-report.c | 9 ++++-----
src/gui-wizard-gtk/wizard.c | 13 +++----------
src/include/run_event.h | 6 ++++++
src/lib/run_event.c | 12 ++++++++++++
4 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
index 3923d60..f9df778 100644
--- a/src/cli/cli-report.c
+++ b/src/cli/cli-report.c
@@ -782,17 +782,16 @@ int run_event_chain(const char *dump_dir_name, GList *chain, int
interactive)
break;
if (retval == 0 && run_state->children_count == 0)
{
- printf("Error: no processing is specified for event '%s'",
event_name);
+ printf("Error: no processing is specified for event
'%s'\n", event_name);
retval = 1;
}
else
/* If program failed, or if it finished successfully without saying anything...
*/
if (retval != 0 || !l_state.output_was_produced)
{
- if (WIFSIGNALED(run_state->process_status))
- printf("(killed by signal %u)\n",
WTERMSIG(run_state->process_status));
- else
- printf("(exited with %u)\n", retval);
+ char *msg = exit_status_as_string(event_name,
run_state->process_status);
+ fputs(msg, stdout);
+ free(msg);
}
if (retval != 0)
break;
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index b55b975..f5d832a 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -1741,18 +1741,11 @@ static gboolean consume_cmd_output(GIOChannel *source,
GIOCondition condition, g
/* If program failed, or if it finished successfully without saying anything... */
if (retval != 0 || evd->event_log_state == LOGSTATE_FIRSTLINE)
{
- char *msg;
- if (WIFSIGNALED(run_state->process_status))
- msg = xasprintf("(killed by signal %u)\n",
WTERMSIG(run_state->process_status));
- else if (retval == 0)
- {
- msg = xasprintf(_("Completed successfuly\n"));
- }
- else
+ char *msg = exit_status_as_string(evd->event_name,
run_state->process_status);
+ if (retval != 0)
{
- /* If program failed, emit error line */
+ /* If program failed, emit *error* line */
evd->event_log_state = LOGSTATE_ERRLINE;
- msg = xasprintf("(exited with %u)\n", retval);
}
append_to_textview(evd->tv_log, msg);
save_to_event_log(evd, msg);
diff --git a/src/include/run_event.h b/src/include/run_event.h
index 40d0ba8..7579e8f 100644
--- a/src/include/run_event.h
+++ b/src/include/run_event.h
@@ -246,6 +246,12 @@ int run_event_stdio_ask_yes_no_yesforever(const char *msg, const
char *key, void
*/
char *run_event_stdio_ask_password(const char *msg, void *param);
+
+/* A simple helper */
+#define exit_status_as_string libreport_exit_status_as_string
+char *exit_status_as_string(const char *progname, int status);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
index 6fe12f8..aa79e16 100644
--- a/src/lib/run_event.c
+++ b/src/lib/run_event.c
@@ -753,3 +753,15 @@ static void run_event_stdio_error_and_die(const char *error_line,
void *param)
{
error_msg_and_die("Can't write bytes to child's stdin");
}
+
+char *exit_status_as_string(const char *progname, int status)
+{
+ char *msg;
+ if (WIFSIGNALED(status))
+ msg = xasprintf(_("('%s' was killed by signal %u)\n"),
progname, WTERMSIG(status));
+ else if (status == 0)
+ msg = xasprintf(_("('%s' completed successfully)\n"),
progname);
+ else
+ msg = xasprintf(_("('%s' exited with %u)\n"), progname,
WEXITSTATUS(status));
+ return msg;
+}