diff options
| author | Nikola Pajkovsky <npajkovs@redhat.com> | 2011-03-16 11:55:37 +0100 |
|---|---|---|
| committer | Nikola Pajkovsky <npajkovs@redhat.com> | 2011-03-16 11:55:37 +0100 |
| commit | 20dc3f727b87c2ae99686adc745bfdc3eba55d43 (patch) | |
| tree | 263f9ea9ce230620dad71f790d26fd5ffca10827 /src | |
| parent | 4186340206b9ba112ec67751edf5ca63d97ced18 (diff) | |
| parent | 5b7b9f0969b268cedf2d7e23cf7b7f09004ec0cf (diff) | |
| download | abrt-20dc3f727b87c2ae99686adc745bfdc3eba55d43.tar.gz abrt-20dc3f727b87c2ae99686adc745bfdc3eba55d43.tar.xz abrt-20dc3f727b87c2ae99686adc745bfdc3eba55d43.zip | |
Merge branch 'cli'
* cli:
merge config files
Conflicts:
src/lib/event_config.c
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/event_config.c | 133 |
1 files changed, 75 insertions, 58 deletions
diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 6207f721..b7de754a 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -71,7 +71,72 @@ 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} */ +static void load_config_file(const char *dir_path) +{ + DIR *dir; + struct dirent *dent; + + /* Load .conf files */ + dir = opendir(dir_path); + if (!dir) + return; + while ((dent = readdir(dir)) != NULL) + { + char *ext = strrchr(dent->d_name, '.'); + if (!ext) + continue; + if (strcmp(ext + 1, "conf") != 0) + continue; + + char *fullname = concat_path_file(dir_path, 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(); + + map_string_h *keys_and_values = new_map_string(); + + load_conf_file(fullname, keys_and_values, /*skipKeysWithoutValue:*/ false); + free(fullname); + + /* Insert or replace every key/value from keys_and_values to event_config->option */ + GHashTableIter iter; + char *name; + char *value; + g_hash_table_iter_init(&iter, keys_and_values); + 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); + if (elem) + { + opt = elem->data; + // log("conf: replacing '%s' value:'%s'->'%s'", name, opt->value, value); + free(opt->value); + } + else + { + // log("conf: new value %s='%s'", name, value); + opt = new_event_option(); + opt->name = xstrdup(name); + } + opt->value = xstrdup(value); + if (!elem) + event_config->options = g_list_append(event_config->options, opt); + } + + free_map_string(keys_and_values); + + if (new_config) + g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); + } + 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(); @@ -122,7 +187,8 @@ void load_event_config_data(void) gchar *target = g_path_get_basename(link); char *ext = strrchr(target, '.'); if (!ext || 0 != strcmp(ext + 1, "xml")) - error_msg_and_die("Invalid event symlink '%s': expected it to point to another xml file", fullname); + error_msg_and_die("Invalid event symlink '%s': expected it to" + " point to another xml file", fullname); *ext = '\0'; g_hash_table_replace(g_event_config_symlinks, xstrdup(dent->d_name), target); g_free(link); @@ -143,63 +209,14 @@ void load_event_config_data(void) } closedir(dir); - /* Load .conf 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, "conf") != 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(); - - map_string_h *keys_and_values = new_map_string(); - - load_conf_file(fullname, keys_and_values, /*skipKeysWithoutValue:*/ false); - free(fullname); - - /* Insert or replace every key/value from keys_and_values to event_config->option */ - GHashTableIter iter; - char *name; - char *value; - g_hash_table_iter_init(&iter, keys_and_values); - 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); - if (elem) - { - opt = elem->data; - //log("conf: replacing '%s' value:'%s'->'%s'", name, opt->value, value); - free(opt->value); - } - else - { - //log("conf: new value %s='%s'", name, value); - opt = new_event_option(); - opt->name = xstrdup(name); - } - opt->value = xstrdup(value); - if (!elem) - event_config->options = g_list_append(event_config->options, opt); - } - - free_map_string(keys_and_values); + load_config_file(EVENTS_DIR); - if (new_config) - g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); - } - closedir(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 */ |
