|
|
057568 |
From fc028b3417349fd60a2ddd1aff1127a417df512b Mon Sep 17 00:00:00 2001
|
|
|
057568 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
057568 |
Date: Thu, 2 Jul 2015 15:04:06 +0200
|
|
|
057568 |
Subject: [PATCH] lib: get possible events for problem_data_t
|
|
|
057568 |
|
|
|
057568 |
Certainly useful when we have no file system access to dump directories
|
|
|
057568 |
and we only get a problem data via a D-Bus service.
|
|
|
057568 |
|
|
|
057568 |
Related: #1224984
|
|
|
057568 |
|
|
|
057568 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
057568 |
---
|
|
|
057568 |
src/include/run_event.h | 8 +++++++
|
|
|
057568 |
src/lib/glib_support.c | 2 +-
|
|
|
057568 |
src/lib/run_event.c | 56 +++++++++++++++++++++++++++++++++++--------------
|
|
|
057568 |
3 files changed, 49 insertions(+), 17 deletions(-)
|
|
|
057568 |
|
|
|
057568 |
diff --git a/src/include/run_event.h b/src/include/run_event.h
|
|
|
057568 |
index 7579e8f..bc43d4f 100644
|
|
|
057568 |
--- a/src/include/run_event.h
|
|
|
057568 |
+++ b/src/include/run_event.h
|
|
|
057568 |
@@ -186,6 +186,9 @@ int run_event_on_problem_data(struct run_event_state *state, problem_data_t *dat
|
|
|
057568 |
*/
|
|
|
057568 |
char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const char *pfx);
|
|
|
057568 |
|
|
|
057568 |
+/* Like list_possible_events but accepts problem_data_t */
|
|
|
057568 |
+char *list_possible_events_problem_data(problem_data_t *pd, const char *dump_dir_name, const char *pfx);
|
|
|
057568 |
+
|
|
|
057568 |
/*
|
|
|
057568 |
* Returns a list of possible events for given problem directory
|
|
|
057568 |
*
|
|
|
057568 |
@@ -195,6 +198,11 @@ char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const
|
|
|
057568 |
GList *list_possible_events_glist(const char *problem_dir_name,
|
|
|
057568 |
const char *pfx);
|
|
|
057568 |
|
|
|
057568 |
+/* Like list_possible_events_glist but accepts problem_data_t */
|
|
|
057568 |
+GList *list_possible_events_problem_data_glist(problem_data_t *pd,
|
|
|
057568 |
+ const char *problem_dir_name,
|
|
|
057568 |
+ const char *pfx);
|
|
|
057568 |
+
|
|
|
057568 |
/* Command line run event callback implemenetation */
|
|
|
057568 |
|
|
|
057568 |
/*
|
|
|
057568 |
diff --git a/src/lib/glib_support.c b/src/lib/glib_support.c
|
|
|
057568 |
index 02c2dfd..2751b0c 100644
|
|
|
057568 |
--- a/src/lib/glib_support.c
|
|
|
057568 |
+++ b/src/lib/glib_support.c
|
|
|
057568 |
@@ -92,7 +92,7 @@ GList *parse_list(const char* list)
|
|
|
057568 |
|
|
|
057568 |
char *tmp_list = xstrdup(list);
|
|
|
057568 |
|
|
|
057568 |
- GList *l = parse_delimited_list(list, LIST_DELIMITER);
|
|
|
057568 |
+ GList *l = parse_delimited_list(tmp_list, LIST_DELIMITER);
|
|
|
057568 |
|
|
|
057568 |
free(tmp_list);
|
|
|
057568 |
|
|
|
057568 |
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
|
|
|
057568 |
index a56cf88..252c6bc 100644
|
|
|
057568 |
--- a/src/lib/run_event.c
|
|
|
057568 |
+++ b/src/lib/run_event.c
|
|
|
057568 |
@@ -298,11 +298,17 @@ static int regcmp_lines(char *val, const char *regex)
|
|
|
057568 |
static char* pop_next_command(GList **pp_rule_list,
|
|
|
057568 |
char **pp_event_name, /* reports EVENT value thru this, if not NULL on entry */
|
|
|
057568 |
struct dump_dir **pp_dd, /* use *pp_dd for access to dump dir, if non-NULL */
|
|
|
057568 |
+ problem_data_t *pd, /* use *pp for access to problem data, if non-NULL */
|
|
|
057568 |
const char *dump_dir_name,
|
|
|
057568 |
const char *pfx,
|
|
|
057568 |
unsigned pfx_len
|
|
|
057568 |
)
|
|
|
057568 |
{
|
|
|
057568 |
+ /* It is an error to pass both, but we can recover from it and use only
|
|
|
057568 |
+ * problem_data_t in that case */
|
|
|
057568 |
+ if (pp_dd != NULL && pd != NULL)
|
|
|
057568 |
+ error_msg("BUG: both dump dir and problem data passed to %s()", __func__);
|
|
|
057568 |
+
|
|
|
057568 |
char *command = NULL;
|
|
|
057568 |
struct dump_dir *dd = pp_dd ? *pp_dd : NULL;
|
|
|
057568 |
|
|
|
057568 |
@@ -331,7 +337,7 @@ static char* pop_next_command(GList **pp_rule_list,
|
|
|
057568 |
else
|
|
|
057568 |
{
|
|
|
057568 |
/* Read from dump dir and compare */
|
|
|
057568 |
- if (!dd)
|
|
|
057568 |
+ if (!dd && pd == NULL)
|
|
|
057568 |
{
|
|
|
057568 |
/* Without dir to match, we assume match for all conditions */
|
|
|
057568 |
if (!dump_dir_name)
|
|
|
057568 |
@@ -349,10 +355,15 @@ static char* pop_next_command(GList **pp_rule_list,
|
|
|
057568 |
/* Is it "VAR!=VAL"? */
|
|
|
057568 |
int inverted = (eq_sign > cond_str && eq_sign[-1] == '!');
|
|
|
057568 |
char *var_name = xstrndup(cond_str, eq_sign - cond_str - (regex|inverted));
|
|
|
057568 |
- char *real_val = dd_load_text_ext(dd, var_name, DD_FAIL_QUIETLY_ENOENT);
|
|
|
057568 |
+ char *real_val = NULL;
|
|
|
057568 |
+ char *free_me = NULL;
|
|
|
057568 |
+ if (pd == NULL)
|
|
|
057568 |
+ free_me = real_val = dd_load_text_ext(dd, var_name, DD_FAIL_QUIETLY_ENOENT);
|
|
|
057568 |
+ else
|
|
|
057568 |
+ real_val = problem_data_get_content_or_NULL(pd, var_name);
|
|
|
057568 |
free(var_name);
|
|
|
057568 |
int vals_differ = regex ? regcmp_lines(real_val, eq_sign + 1) : strcmp(real_val, eq_sign + 1);
|
|
|
057568 |
- free(real_val);
|
|
|
057568 |
+ free(free_me);
|
|
|
057568 |
if (inverted)
|
|
|
057568 |
vals_differ = !vals_differ;
|
|
|
057568 |
|
|
|
057568 |
@@ -422,6 +433,7 @@ int spawn_next_command(struct run_event_state *state,
|
|
|
057568 |
char *cmd = pop_next_command(&state->rule_list,
|
|
|
057568 |
NULL, /* don't return event_name */
|
|
|
057568 |
NULL, /* NULL dd: we match by... */
|
|
|
057568 |
+ NULL, /* no problem data */
|
|
|
057568 |
dump_dir_name, /* ...dirname */
|
|
|
057568 |
event, strlen(event)+1 /* for this event name exactly (not prefix) */
|
|
|
057568 |
);
|
|
|
057568 |
@@ -648,7 +660,8 @@ int run_event_on_problem_data(struct run_event_state *state, problem_data_t *dat
|
|
|
057568 |
return r;
|
|
|
057568 |
}
|
|
|
057568 |
|
|
|
057568 |
-char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const char *pfx)
|
|
|
057568 |
+
|
|
|
057568 |
+static char *_list_possible_events(struct dump_dir **dd, problem_data_t *pd, const char *dump_dir_name, const char *pfx)
|
|
|
057568 |
{
|
|
|
057568 |
struct strbuf *result = strbuf_new();
|
|
|
057568 |
|
|
|
057568 |
@@ -661,7 +674,8 @@ char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const
|
|
|
057568 |
char *event_name = NULL;
|
|
|
057568 |
char *cmd = pop_next_command(&rule_list,
|
|
|
057568 |
&event_name, /* return event_name */
|
|
|
057568 |
- (dd ? &dd : NULL), /* match this dd... */
|
|
|
057568 |
+ dd, /* match this dd... */
|
|
|
057568 |
+ pd, /* no problem data */
|
|
|
057568 |
dump_dir_name, /* ...or if NULL, this dirname */
|
|
|
057568 |
pfx, pfx_len /* for events with this prefix */
|
|
|
057568 |
);
|
|
|
057568 |
@@ -695,24 +709,34 @@ char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const
|
|
|
057568 |
return strbuf_free_nobuf(result);
|
|
|
057568 |
}
|
|
|
057568 |
|
|
|
057568 |
+char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const char *pfx)
|
|
|
057568 |
+{
|
|
|
057568 |
+ return _list_possible_events((dd ? &dd : NULL), NULL, dump_dir_name, pfx);
|
|
|
057568 |
+}
|
|
|
057568 |
+
|
|
|
057568 |
+char *list_possible_events_problem_data(problem_data_t *pd, const char *dump_dir_name, const char *pfx)
|
|
|
057568 |
+{
|
|
|
057568 |
+ return _list_possible_events(NULL, pd, dump_dir_name, pfx);
|
|
|
057568 |
+}
|
|
|
057568 |
+
|
|
|
057568 |
GList *list_possible_events_glist(const char *problem_dir_name,
|
|
|
057568 |
const char *pfx)
|
|
|
057568 |
{
|
|
|
057568 |
struct dump_dir *dd = dd_opendir(problem_dir_name, DD_OPEN_READONLY);
|
|
|
057568 |
- GList *l = NULL;
|
|
|
057568 |
char *events = list_possible_events(dd, problem_dir_name, pfx);
|
|
|
057568 |
- char *start = events;
|
|
|
057568 |
- char *end = strchr(events, '\n');
|
|
|
057568 |
+ GList *l = parse_delimited_list(events, "\n");
|
|
|
057568 |
+ dd_close(dd);
|
|
|
057568 |
+ free(events);
|
|
|
057568 |
|
|
|
057568 |
- while(end)
|
|
|
057568 |
- {
|
|
|
057568 |
- *end = '\0';
|
|
|
057568 |
- l = g_list_append(l, xstrdup(start));
|
|
|
057568 |
- start = end + 1;
|
|
|
057568 |
- end = strchr(start, '\n');
|
|
|
057568 |
- }
|
|
|
057568 |
+ return l;
|
|
|
057568 |
+}
|
|
|
057568 |
|
|
|
057568 |
- dd_close(dd);
|
|
|
057568 |
+GList *list_possible_events_problem_data_glist(problem_data_t *pd,
|
|
|
057568 |
+ const char *problem_dir_name,
|
|
|
057568 |
+ const char *pfx)
|
|
|
057568 |
+{
|
|
|
057568 |
+ char *events = list_possible_events_problem_data(pd, problem_dir_name, pfx);
|
|
|
057568 |
+ GList *l = parse_delimited_list(events, "\n");
|
|
|
057568 |
free(events);
|
|
|
057568 |
|
|
|
057568 |
return l;
|
|
|
057568 |
--
|
|
|
057568 |
2.4.3
|
|
|
057568 |
|