You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.3 KiB

From 90884eeb92527a8f0dbc2d90b3665b40ada3d426 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Fri, 21 Feb 2014 22:41:05 +0100
Subject: [LIBREPORT PATCH 31/33] introduce import-event-options in xml event
definitions
Related to rhbz#1069111
Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
src/include/event_config.h | 1 +
src/lib/event_config.c | 49 +++++++++++++++++++++++++++++++++++++---------
src/lib/event_xml_parser.c | 15 ++++++++++++++
3 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/src/include/event_config.h b/src/include/event_config.h
index 24e1eac..e2fcc23 100644
--- a/src/include/event_config.h
+++ b/src/include/event_config.h
@@ -81,6 +81,7 @@ typedef struct
bool ec_skip_review;
bool ec_sending_sensitive_data;
+ GList *ec_imported_event_names;
GList *options;
} event_config_t;
diff --git a/src/lib/event_config.c b/src/lib/event_config.c
index 6d12695..b25517d 100644
--- a/src/lib/event_config.c
+++ b/src/lib/event_config.c
@@ -112,10 +112,8 @@ void free_event_config(event_config_t *p)
free(p->ec_exclude_items_by_default);
free(p->ec_include_items_by_default);
free(p->ec_exclude_items_always);
- GList *opt;
- for (opt = p->options; opt; opt = opt->next)
- free_event_option(opt->data);
- g_list_free(p->options);
+ g_list_free_full(p->ec_imported_event_names, free);
+ g_list_free_full(p->options, (GDestroyNotify)free_event_option);
free(p);
}
@@ -282,22 +280,54 @@ GList *export_event_config(const char *event_name)
event_config_t *config = get_event_config(event_name);
if (config)
{
+ GList *imported = config->ec_imported_event_names;
+ while (imported)
+ {
+ GList *exported = export_event_config(/*Event name*/imported->data);
+ while (exported)
+ {
+ if (!g_list_find_custom(env_list, exported->data, (GCompareFunc)strcmp))
+ /* It is not necessary to make a copy of opt->eo_name */
+ /* since its memory is owned by event_option_t and it */
+ /* has global scope */
+ env_list = g_list_prepend(env_list, exported->data);
+
+ exported = g_list_remove_link(exported, exported);
+ }
+
+ imported = g_list_next(imported);
+ }
+
GList *lopt;
for (lopt = config->options; lopt; lopt = lopt->next)
{
event_option_t *opt = lopt->data;
if (!opt->eo_value)
continue;
- char *var_val = xasprintf("%s=%s", opt->eo_name, opt->eo_value);
- log_debug("Exporting '%s'", var_val);
- env_list = g_list_prepend(env_list, var_val);
- putenv(var_val);
+
+ log_debug("Exporting '%s=%s'", opt->eo_name, opt->eo_value);
+
+ /* Add the exported key only if it is not in the list */
+ if (!g_list_find_custom(env_list, opt->eo_name, (GCompareFunc)strcmp))
+ /* It is not necessary to make a copy of opt->eo_name */
+ /* since its memory is owned by opt and it has global scope */
+ env_list = g_list_prepend(env_list, opt->eo_name);
+
+ /* setenv() makes copies of strings */
+ xsetenv(opt->eo_name, opt->eo_value);
}
}
return env_list;
}
+/*
+ * Goes through given list and calls unsetnev() for each list item.
+ *
+ * Accepts a list of 'const char *' type items which contains names of exported
+ * environment variables and which was returned from export_event_config()
+ * function.
+ */
void unexport_event_config(GList *env_list)
{
while (env_list)
@@ -305,8 +335,9 @@ void unexport_event_config(GList *env_list)
char *var_val = env_list->data;
log_debug("Unexporting '%s'", var_val);
safe_unsetenv(var_val);
+
+ /* The list doesn't own memory of values: see export_event_config() */
env_list = g_list_remove(env_list, var_val);
- free(var_val);
}
}
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
index 1f98158..a15f1e1 100644
--- a/src/lib/event_xml_parser.c
+++ b/src/lib/event_xml_parser.c
@@ -40,6 +40,7 @@
#define EXCL_ALWAYS_ELEMENT "exclude-items-always"
#define EXCL_BINARY_ELEMENT "exclude-binary-items"
#define ADV_OPTIONS_ELEMENT "advanced-options"
+#define IMPORT_OPTIONS_ELEMENT "import-event-options"
typedef struct
{
@@ -210,6 +211,20 @@ static void start_element(GMarkupParseContext *context,
}
}
else
+ if (strcmp(element_name, IMPORT_OPTIONS_ELEMENT) == 0)
+ {
+ if (attribute_names[0] == NULL
+ || attribute_names[1] != NULL
+ || strcmp(attribute_names[0], "event") != 0)
+ {
+ error_msg("XML event configuration error: import-event-options element misses attribute 'event'");
+ return;
+ }
+
+ GList *head = parse_data->event_config.values->ec_imported_event_names;
+ parse_data->event_config.values->ec_imported_event_names = g_list_append(head, xstrdup(attribute_values[0]));
+ }
+ else
if (strcmp(element_name, LABEL_ELEMENT) == 0
|| strcmp(element_name, DESCRIPTION_ELEMENT) == 0
|| strcmp(element_name, LONG_DESCR_ELEMENT) == 0
--
1.8.3.1