From 775659551adc37a079e099a1770abe8e933676d5 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Tue, 15 Mar 2011 10:04:22 +0100 Subject: Config file symlinks --- src/lib/event_config.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 0f5c0f62..8b18f332 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -1,6 +1,7 @@ #include "abrtlib.h" GHashTable *g_event_config_list; +static GHashTable *g_event_config_symlinks; event_option_t *new_event_option(void) { @@ -56,6 +57,13 @@ void load_event_config_data(void) /*key_destroy_func:*/ free, /*value_destroy_func:*/ (GDestroyNotify) free_event_config ); + if (!g_event_config_symlinks) + g_event_config_symlinks = g_hash_table_new_full( + /*hash_func*/ g_str_hash, + /*key_equal_func:*/ g_str_equal, + /*key_destroy_func:*/ free, + /*value_destroy_func:*/ free + ); DIR *dir; struct dirent *dent; @@ -73,8 +81,29 @@ void load_event_config_data(void) continue; char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); - *ext = '\0'; + + struct stat buf; + if (0 != lstat(fullname, &buf)) + continue; + if (S_ISLNK(buf.st_mode)) + { + GError *error = NULL; + gchar *link = g_file_read_link(fullname, &error); + if (error != NULL) + error_msg_and_die("Error reading symlink '%s': %s", fullname, error->message); + + 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); + *ext = '\0'; + g_hash_table_replace(g_event_config_symlinks, xstrdup(dent->d_name), basename); + g_free(link); + /* don't free basename, it is owned by the hash table now */ + continue; + } + event_config_t *event_config = get_event_config(dent->d_name); bool new_config = (!event_config); if (new_config) @@ -155,11 +184,22 @@ void free_event_config_data(void) g_hash_table_destroy(g_event_config_list); g_event_config_list = NULL; } + if (g_event_config_symlinks) + { + g_hash_table_destroy(g_event_config_symlinks); + g_event_config_symlinks = NULL; + } } event_config_t *get_event_config(const char *name) { if (!g_event_config_list) return NULL; + if (g_event_config_symlinks) + { + char *link = g_hash_table_lookup(g_event_config_symlinks, name); + if (link) + name = link; + } return g_hash_table_lookup(g_event_config_list, name); } -- cgit From e1bb00559e0b4a77aa7c1c5ae96fd06a79ab3d27 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Tue, 15 Mar 2011 13:46:58 +0100 Subject: config symlinks: fix storage of symlink values --- src/lib/event_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/event_config.c b/src/lib/event_config.c index d733e449..5532710a 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -106,9 +106,9 @@ void load_event_config_data(void) if (!ext || 0 != strcmp(ext + 1, "xml")) 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), basename); + g_hash_table_replace(g_event_config_symlinks, xstrdup(dent->d_name), target); g_free(link); - /* don't free basename, it is owned by the hash table now */ + /* don't free target, it is owned by the hash table now */ continue; } -- cgit From 694c033eaaf1fef39667ca4503bb15a4b9e4ec6d Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Tue, 15 Mar 2011 20:19:54 +0100 Subject: use get_event_config in wizard to make symlinks work --- src/gui-wizard-gtk/wizard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c index 9a642f59..458fba29 100644 --- a/src/gui-wizard-gtk/wizard.c +++ b/src/gui-wizard-gtk/wizard.c @@ -423,7 +423,7 @@ VERB2 log("removing all buttons from box %p", box); else event_screen_name = event_name; const char *event_description = NULL; - event_config_t *cfg = g_hash_table_lookup(g_event_config_list, event_name); + event_config_t *cfg = get_event_config(event_name); if (cfg) { /* .xml has (presumably) prettier description, use it: */ -- cgit