[LIBREPORT PATCH] refactoring the xml and conf loader code related to trac#822
by Jiri Moskovcak
---
libreport.spec.in | 1 +
src/include/Makefile.am | 1 +
src/include/event_config.h | 1 +
src/include/file_obj.h | 24 +++++++++++
src/include/internal_libreport.h | 7 ++++
src/lib/Makefile.am | 4 +-
src/lib/event_config.c | 84 ++++++++++----------------------------
src/lib/file_list.c | 87 ++++++++++++++++++++++++++++++++++++++++
src/lib/file_obj.c | 31 ++++++++++++++
9 files changed, 176 insertions(+), 64 deletions(-)
create mode 100644 src/include/file_obj.h
create mode 100644 src/lib/file_list.c
create mode 100644 src/lib/file_obj.c
diff --git a/libreport.spec.in b/libreport.spec.in
index 9b70e30..124860a 100644
--- a/libreport.spec.in
+++ b/libreport.spec.in
@@ -289,6 +289,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%{_includedir}/libreport/problem_data.h
%{_includedir}/libreport/report.h
%{_includedir}/libreport/run_event.h
+%{_includedir}/libreport/file_obj.h
# Private api headers:
%{_includedir}/libreport/internal_abrt_dbus.h
%{_includedir}/libreport/internal_libreport.h
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 61b49a3..948662e 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -8,5 +8,6 @@ libreport_include_HEADERS = \
run_event.h \
libreport_curl.h \
\
+ file_obj.h \
internal_libreport.h \
internal_abrt_dbus.h
diff --git a/src/include/event_config.h b/src/include/event_config.h
index 0ca3bda..438c723 100644
--- a/src/include/event_config.h
+++ b/src/include/event_config.h
@@ -68,6 +68,7 @@ void free_event_option(event_option_t *p);
//structure to hold the option data
typedef struct
{
+ char *name; //the event name (from it's filename)
char *screen_name; //ui friendly name of the event: "Bugzilla" "RedHat Support Upload"
char *description; // "Report to..."/"Save to file". Should be one sentence, not long
char *long_descr; // Long(er) explanation, if needed
diff --git a/src/include/file_obj.h b/src/include/file_obj.h
new file mode 100644
index 0000000..0a35b85
--- /dev/null
+++ b/src/include/file_obj.h
@@ -0,0 +1,24 @@
+/*
+ Copyright (C) 2010 ABRT team
+ Copyright (C) 2010 RedHat Inc
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+typedef struct file_obj
+{
+ char *filename; //without ext
+ char *fullname; //the full path with extension
+} file_obj_t;
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
index f3396f1..b67e714 100644
--- a/src/include/internal_libreport.h
+++ b/src/include/internal_libreport.h
@@ -93,6 +93,7 @@ int vdprintf(int d, const char *format, va_list ap);
#include "problem_data.h"
#include "report.h"
#include "run_event.h"
+#include "file_obj.h"
#ifdef __cplusplus
extern "C" {
@@ -635,6 +636,12 @@ void set_user_setting(const char *name, const char *value);
const char *get_user_setting(const char *name);
#define load_forbidden_words libreport_load_forbidden_words
GList *load_forbidden_words();
+#define get_file_list libreport_get_file_list
+GList *get_file_list(const char *path, const char *ext);
+#define free_file_list libreport_free_file_list
+void free_file_list(GList *filelist);
+#define new_file_obj libreport_new_file_obj
+file_obj_t *new_file_obj(void);
/* Connect to abrtd over unix domain socket, issue DELETE command */
int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 5345950..2865624 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -47,7 +47,9 @@ libreport_la_SOURCES = \
report.c \
user_settings.c \
client.c \
- utf8.c
+ utf8.c \
+ file_list.c \
+ file_obj.c
libreport_la_CPPFLAGS = \
-I$(srcdir)/../include \
-DLOCALSTATEDIR='"$(localstatedir)"' \
diff --git a/src/lib/event_config.c b/src/lib/event_config.c
index e766470..106da73 100644
--- a/src/lib/event_config.c
+++ b/src/lib/event_config.c
@@ -83,25 +83,14 @@ event_option_t *get_event_option_from_list(const char *name, GList *options)
static void load_config_files(const char *dir_path)
{
- DIR *dir;
- struct dirent *dent;
- /* Load .conf files */
- dir = opendir(dir_path);
- if (!dir)
- return;
- while ((dent = readdir(dir)) != NULL)
+ GList *conf_files = get_file_list(dir_path, "conf");
+ while(conf_files != 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);
+ char *fullname = ((file_obj_t *)conf_files->data)->fullname;
+ char *filename = ((file_obj_t *)conf_files->data)->filename;
- *ext = '\0';
- event_config_t *event_config = get_event_config(dent->d_name);
+ event_config_t *event_config = get_event_config(filename);
bool new_config = (!event_config);
if (new_config)
event_config = new_event_config();
@@ -109,7 +98,8 @@ static void load_config_files(const char *dir_path)
map_string_h *keys_and_values = new_map_string();
load_conf_file(fullname, keys_and_values, /*skipKeysWithoutValue:*/ false);
- free(fullname);
+ //free later with the whole list
+ //free(fullname);
/* Insert or replace every key/value from keys_and_values to event_config->option */
GHashTableIter iter;
@@ -141,9 +131,11 @@ static void load_config_files(const char *dir_path)
free_map_string(keys_and_values);
if (new_config)
- g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config);
+ g_hash_table_replace(g_event_config_list, xstrdup(filename), event_config);
+
+ conf_files = g_list_next(conf_files);
}
- closedir(dir);
+ free_file_list(conf_files);
}
/* (Re)loads data from /etc/abrt/events/foo.{xml,conf} and $XDG_CACHE_HOME/abrt/events/foo.conf */
@@ -166,58 +158,24 @@ void load_event_config_data(void)
/*value_destroy_func:*/ free
);
- DIR *dir;
- struct dirent *dent;
-
- /* Load .xml files */
- dir = opendir(EVENTS_DIR);
- if (!dir)
- return;
- while ((dent = readdir(dir)) != NULL)
+ GList *file_objs = get_file_list(EVENTS_DIR, "xml");
+ while (file_objs)
{
- 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';
-
- 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), target);
- g_free(link);
- /* don't free target, it is owned by the hash table now */
- continue;
- }
+ file_obj_t *file = ((file_obj_t *)file_objs->data);
- event_config_t *event_config = get_event_config(dent->d_name);
+ event_config_t *event_config = get_event_config(file->filename);
bool new_config = (!event_config);
if (new_config)
- event_config = new_event_config();
+ event_config = new_event_config();
- load_event_description_from_file(event_config, fullname);
- free(fullname);
+ load_event_description_from_file(event_config, file->fullname);
if (new_config)
- g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config);
+ g_hash_table_replace(g_event_config_list, xstrdup(file->filename), event_config);
+
+ file_objs = g_list_next(file_objs);
}
- closedir(dir);
+ free_file_list(file_objs);
load_config_files(EVENTS_DIR);
diff --git a/src/lib/file_list.c b/src/lib/file_list.c
new file mode 100644
index 0000000..c9e2a33
--- /dev/null
+++ b/src/lib/file_list.c
@@ -0,0 +1,87 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "internal_libreport.h"
+
+GList *get_file_list(const char *path, const char *ext_filter)
+{
+ GList * files = NULL;
+ DIR *dir;
+ struct dirent *dent;
+
+ /* Load .$ext files */
+ dir = opendir(path);
+ if (!dir)
+ return NULL;
+ while ((dent = readdir(dir)) != NULL)
+ {
+ char *ext = strrchr(dent->d_name, '.');
+ if (!ext)
+ continue;
+ if (ext_filter && strcmp(ext + 1, ext_filter) != 0)
+ continue;
+
+ char *fullname = concat_path_file(path, 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';
+ //@@TODO symlink handling is broken!!
+ //g_hash_table_replace(g_event_config_symlinks, xstrdup(dent->d_name), target);
+ g_free(link);
+ /* don't free target, it is owned by the hash table now */
+ continue;
+ }
+
+ file_obj_t *file = new_file_obj();
+ file->filename = xstrdup(dent->d_name);
+ file->fullname = fullname;
+ files = g_list_prepend(files, file);
+
+ }
+ closedir(dir);
+ return files;
+}
+
+void free_file_list(GList *filelist)
+{
+ GList *li;
+ for (li = filelist; li; li = g_list_next(li))
+ {
+ free(((file_obj_t *)li->data)->filename);
+ free(((file_obj_t *)li->data)->fullname);
+ free(li->data);
+ }
+
+ g_list_free(filelist);
+}
diff --git a/src/lib/file_obj.c b/src/lib/file_obj.c
new file mode 100644
index 0000000..0af1723
--- /dev/null
+++ b/src/lib/file_obj.c
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "internal_libreport.h"
+
+file_obj_t *new_file_obj(void)
+{
+ return xmalloc(sizeof(file_obj_t));
+}
+
+void free_file_obj(file_obj_t *f)
+{
+ free(f->fullname);
+ free(f->filename);
+}
--
1.8.0
11 years, 6 months
[Automatic Bug Reporting Tool - ABRT] #856: chown foreign problems before reporting
by fedora-badges
#856: chown foreign problems before reporting
------------------------+---------------------
Reporter: jfilak | Owner: jfilak
Type: defect | Status: new
Priority: major | Milestone:
Component: gnome-abrt | Version:
Keywords: | Blocked By:
Blocking: |
------------------------+---------------------
The foreign problems shown in problems list when the "All problems" is
checked must be chowned before reporting because problem's directory is
not accessible for stealing which is required by for successful reporting.
--
Ticket URL: <https://fedorahosted.org/abrt/ticket/856>
Automatic Bug Reporting Tool - ABRT <http://fedorahoted.org/abrt/>
Automatic bug reporting tool
11 years, 6 months
[Automatic Bug Reporting Tool - ABRT] #813: enhance koops tainted flag parser to be able to parse different number of flags than 12
by fedora-badges
#813: enhance koops tainted flag parser to be able to parse different number of
flags than 12
--------------------+---------------------
Reporter: jfilak | Owner: jfilak
Type: defect | Status: new
Priority: major | Milestone:
Component: abrt | Version: 2.0
Keywords: | Blocked By:
Blocking: |
--------------------+---------------------
The current number of the tainted flags is 13
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain...
{{{
static const struct tnt tnts[] = {
{ TAINT_PROPRIETARY_MODULE, 'P', 'G' },
{ TAINT_FORCED_MODULE, 'F', ' ' },
{ TAINT_UNSAFE_SMP, 'S', ' ' },
{ TAINT_FORCED_RMMOD, 'R', ' ' },
{ TAINT_MACHINE_CHECK, 'M', ' ' },
{ TAINT_BAD_PAGE, 'B', ' ' },
{ TAINT_USER, 'U', ' ' },
{ TAINT_DIE, 'D', ' ' },
{ TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' },
{ TAINT_WARN, 'W', ' ' },
{ TAINT_CRAP, 'C', ' ' },
{ TAINT_FIRMWARE_WORKAROUND, 'I', ' ' },
{ TAINT_OOT_MODULE, 'O', ' ' },
};
}}}
--
Ticket URL: <https://fedorahosted.org/abrt/ticket/813>
Automatic Bug Reporting Tool - ABRT <http://fedorahoted.org/abrt/>
Automatic bug reporting tool
11 years, 7 months