diff options
| author | Nikola Pajkovsky <npajkovs@redhat.com> | 2011-03-15 17:39:26 +0100 |
|---|---|---|
| committer | Nikola Pajkovsky <npajkovs@redhat.com> | 2011-03-15 17:39:26 +0100 |
| commit | 5b7b9f0969b268cedf2d7e23cf7b7f09004ec0cf (patch) | |
| tree | 6c63379cac136d30f01dd9b2744541cdba0c3b8d /src/lib | |
| parent | 4df9a21293f121e8d46d52404b89614d9b2b3cec (diff) | |
| download | abrt-5b7b9f0969b268cedf2d7e23cf7b7f09004ec0cf.tar.gz abrt-5b7b9f0969b268cedf2d7e23cf7b7f09004ec0cf.tar.xz abrt-5b7b9f0969b268cedf2d7e23cf7b7f09004ec0cf.zip | |
merge config files
firstly load system wide config from /etc/abrt/events, then
load user defined config from ~/.abrt/events and override
system wide config by user defined config
Signed-off-by: Nikola Pajkovsky <npajkovs@redhat.com>
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/event_config.c | 106 |
1 files changed, 61 insertions, 45 deletions
diff --git a/src/lib/event_config.c b/src/lib/event_config.c index e38041b8..019a3ed4 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -70,52 +70,13 @@ event_option_t *get_event_option_from_list(const char *name, GList *options) return NULL; } -/* (Re)loads data from /etc/abrt/events/foo.{xml,conf} */ -void load_event_config_data(void) +static void load_config_file(const char *dir_path) { - free_event_config_data(); - - if (!g_event_config_list) - g_event_config_list = g_hash_table_new_full( - /*hash_func*/ g_str_hash, - /*key_equal_func:*/ g_str_equal, - /*key_destroy_func:*/ free, - /*value_destroy_func:*/ (GDestroyNotify) free_event_config - ); - DIR *dir; struct dirent *dent; - /* Load .xml files */ - dir = opendir(EVENTS_DIR); - if (!dir) - return; - while ((dent = readdir(dir)) != NULL) - { - char *ext = strrchr(dent->d_name, '.'); - if (!ext) - continue; - if (strcmp(ext + 1, "xml") != 0) - continue; - - char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); - - *ext = '\0'; - event_config_t *event_config = get_event_config(dent->d_name); - bool new_config = (!event_config); - if (new_config) - event_config = new_event_config(); - - load_event_description_from_file(event_config, fullname); - free(fullname); - - if (new_config) - g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); - } - closedir(dir); - /* Load .conf files */ - dir = opendir(EVENTS_DIR); + dir = opendir(dir_path); if (!dir) return; while ((dent = readdir(dir)) != NULL) @@ -126,7 +87,7 @@ void load_event_config_data(void) if (strcmp(ext + 1, "conf") != 0) continue; - char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); + char *fullname = concat_path_file(dir_path, dent->d_name); *ext = '\0'; event_config_t *event_config = get_event_config(dent->d_name); @@ -147,16 +108,17 @@ void load_event_config_data(void) while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { event_option_t *opt; - GList *elem = g_list_find_custom(event_config->options, name, &cmp_event_option_name_with_string); + GList *elem = g_list_find_custom(event_config->options, name, + &cmp_event_option_name_with_string); if (elem) { opt = elem->data; - //log("conf: replacing '%s' value:'%s'->'%s'", name, opt->value, value); +// log("conf: replacing '%s' value:'%s'->'%s'", name, opt->value, value); free(opt->value); } else { - //log("conf: new value %s='%s'", name, value); +// log("conf: new value %s='%s'", name, value); opt = new_event_option(); opt->name = xstrdup(name); } @@ -173,6 +135,60 @@ void load_event_config_data(void) closedir(dir); } +/* (Re)loads data from /etc/abrt/events/foo.{xml,conf} and ~/.abrt/events/foo.conf */ +void load_event_config_data(void) +{ + free_event_config_data(); + + if (!g_event_config_list) + g_event_config_list = g_hash_table_new_full( + /*hash_func*/ g_str_hash, + /*key_equal_func:*/ g_str_equal, + /*key_destroy_func:*/ free, + /*value_destroy_func:*/ (GDestroyNotify) free_event_config + ); + + DIR *dir; + struct dirent *dent; + + /* Load .xml files */ + dir = opendir(EVENTS_DIR); + if (!dir) + return; + while ((dent = readdir(dir)) != NULL) + { + char *ext = strrchr(dent->d_name, '.'); + if (!ext) + continue; + if (strcmp(ext + 1, "xml") != 0) + continue; + + char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); + + *ext = '\0'; + event_config_t *event_config = get_event_config(dent->d_name); + bool new_config = (!event_config); + if (new_config) + event_config = new_event_config(); + + load_event_description_from_file(event_config, fullname); + free(fullname); + + if (new_config) + g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); + } + closedir(dir); + + load_config_file(EVENTS_DIR); + + char *HOME = getenv("HOME"); + if (!HOME || !HOME[0]) + return; + HOME = concat_path_file(HOME, ".abrt/events"); + load_config_file(HOME); + free(HOME); +} + /* Frees all loaded data */ void free_event_config_data(void) { |
