Collect events are run both in report mode (-r) and in standalone
collect mode (-c).
---
src/cli/cli-report.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/cli/cli-report.h | 1 +
src/cli/cli.c | 9 ++++++
3 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
index 689fc4e..9fdf05d 100644
--- a/src/cli/cli-report.c
+++ b/src/cli/cli-report.c
@@ -664,6 +664,75 @@ GList *str_to_glist(char *str, int delim)
return list;
}
+/* When this function returns the dump dir passed as dd is closed */
+int collect(const char *dump_dir_name, struct dump_dir *dd, int batch)
+{
+ int errors = 0;
+ char wanted_collectors[255];
+ GList *selected_events = NULL;
+
+ char *collect_events_as_lines = list_possible_events(dd, NULL, "collect");
+ dd_close(dd);
+
+ /* return if there are no collect events */
+ if (!collect_events_as_lines)
+ return 0;
+
+ if (!*collect_events_as_lines)
+ {
+ free(collect_events_as_lines);
+ return 0;
+ }
+
+ GList *list_collect_events = str_to_glist(collect_events_as_lines, '\n');
+ free(collect_events_as_lines);
+
+ if (!batch)
+ {
+ GList *li;
+ unsigned i;
+
+ puts(_("What additional information would you like to collect?"));
+ /* Print list of collectors and ask the user which should be used. */
+ for (li = list_collect_events, i = 1; li; li = li->next, i++)
+ {
+ char *collector_name = (char *) li->data;
+ event_config_t *config = get_event_config(collector_name);
+
+ if (!config)
+ VERB1 log("No configuration file found for collector
'%s'", collector_name);
+
+ printf(" %d) %s\n", i, (config && config->screen_name) ?
config->screen_name : collector_name);
+ }
+
+ read_from_stdin(_("Select collector(s): "), wanted_collectors,
sizeof(wanted_collectors));
+
+ for (li = list_collect_events, i = 1; li; li = li->next, i++)
+ {
+ char *collector_name = (char *) li->data;
+
+ /* Was this collector requested? */
+ if (!is_number_in_string(i, wanted_collectors))
+ continue;
+
+ selected_events = g_list_append(selected_events, collector_name);
+ }
+ }
+ else
+ {
+ /* run all collectors in noninteractive mode */
+ selected_events = list_collect_events;
+ }
+
+ errors = run_events(dump_dir_name, selected_events, "Collection");
+
+ list_free_with_free(list_collect_events);
+ if (!batch)
+ g_list_free(selected_events);
+
+ return errors;
+}
+
/* Report the crash */
int report(const char *dump_dir_name, int flags)
{
@@ -696,6 +765,15 @@ int report(const char *dump_dir_name, int flags)
dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
if (!dd)
return -1;
+
+ int collect_errors = collect(dump_dir_name, dd, flags & CLI_REPORT_BATCH);
+ if (collect_errors > 0)
+ printf(_("There were %d errors while collecting additional
data\n"), collect_errors);
+
+ /* Load dd from (possibly updated by collect) dump dir */
+ dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
+ return -1;
}
char *report_events_as_lines = list_possible_events(dd, NULL, "report");
diff --git a/src/cli/cli-report.h b/src/cli/cli-report.h
index d3d8d70..a2138ce 100644
--- a/src/cli/cli-report.h
+++ b/src/cli/cli-report.h
@@ -32,6 +32,7 @@ enum {
CLI_REPORT_ONLY = 1 << 1,
};
int report(const char *dump_dir_name, int flags);
+int collect(const char *dump_dir_name, struct dump_dir *dd, int batch);
#ifdef __cplusplus
}
diff --git a/src/cli/cli.c b/src/cli/cli.c
index d209dc6..ac71ab9 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -176,6 +176,15 @@ int main(int argc, char** argv)
free(analyze_events_as_lines);
break;
}
+ case OPT_collect:
+ {
+ struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
+ if (!dd)
+ return 1;
+
+ exitcode = collect(dump_dir_name, dd, always);
+ break;
+ }
case OPT_report:
{
struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
--
1.7.6