From 042d62126a0ca8b6b9d2fb4d417f07691be90536 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 23 Apr 2011 17:21:17 +0200 Subject: mass replace of crash_data with problem_data Signed-off-by: Denys Vlasenko --- src/applet/test_report.c | 10 +- src/cli/abrt-cli.1 | 4 +- src/cli/cli.c | 58 ++--- src/cli/report.c | 56 ++--- src/daemon/MiddleWare.c | 27 +-- src/daemon/MiddleWare.h | 4 +- src/daemon/abrt.conf.5 | 2 +- src/daemon/abrtd.8 | 2 +- src/daemon/abrtd.c | 14 +- src/gui-wizard-gtk/main.c | 14 +- src/gui-wizard-gtk/wizard.c | 34 +-- src/gui-wizard-gtk/wizard.glade | 2 +- src/gui-wizard-gtk/wizard.h | 6 +- src/include/Makefile.am | 4 +- src/include/abrt_crash_data.h | 100 -------- src/include/abrt_problem_data.h | 100 ++++++++ src/include/abrtlib.h | 10 +- src/include/report/crash_data.h | 106 --------- src/include/report/dump_dir.h | 2 +- src/include/report/problem_data.h | 106 +++++++++ src/include/report/run_event.h | 4 +- src/lib/Makefile.am | 2 +- src/lib/crash_data.c | 309 ------------------------- src/lib/create_dump_dir.c | 8 +- src/lib/dump_dir.c | 2 +- src/lib/make_descr.c | 24 +- src/lib/problem_data.c | 309 +++++++++++++++++++++++++ src/lib/run_event.c | 6 +- src/plugins/Upload.conf | 2 +- src/plugins/abrt-Bugzilla.7 | 4 +- src/plugins/abrt-KerneloopsReporter.7 | 2 +- src/plugins/abrt-Logger.7 | 2 +- src/plugins/abrt-Mailx.7 | 2 +- src/plugins/abrt-Upload.7 | 2 +- src/plugins/abrt-action-bugzilla.cpp | 64 ++--- src/plugins/abrt-action-kerneloops.c | 6 +- src/plugins/abrt-action-mailx.c | 10 +- src/plugins/abrt-action-print.c | 6 +- src/plugins/abrt-action-rhtsupport.c | 18 +- src/plugins/abrt-plugins.7 | 2 +- src/report-python/Makefile.am | 2 +- src/report-python/__init__.py | 4 +- src/report-python/common.h | 8 +- src/report-python/crash_data.c | 137 ----------- src/report-python/dump_dir.c | 2 +- src/report-python/problem_data.c | 137 +++++++++++ src/report-python/reportmodule.c | 8 +- src/report-python/run_event.c | 14 +- src/report-python/test_crash_data | 21 -- src/report-python/test_crash_data2 | 10 - src/report-python/test_full | 6 +- src/report-python/test_full2 | 4 +- src/report-python/test_problem_data | 21 ++ src/report-python/test_problem_data2 | 10 + src/report-python/test_setroubleshoot_example2 | 2 +- 55 files changed, 912 insertions(+), 919 deletions(-) delete mode 100644 src/include/abrt_crash_data.h create mode 100644 src/include/abrt_problem_data.h delete mode 100644 src/include/report/crash_data.h create mode 100644 src/include/report/problem_data.h delete mode 100644 src/lib/crash_data.c create mode 100644 src/lib/problem_data.c delete mode 100644 src/report-python/crash_data.c create mode 100644 src/report-python/problem_data.c delete mode 100755 src/report-python/test_crash_data delete mode 100755 src/report-python/test_crash_data2 create mode 100644 src/report-python/test_problem_data create mode 100644 src/report-python/test_problem_data2 diff --git a/src/applet/test_report.c b/src/applet/test_report.c index f5e79d92..5d98cfe2 100644 --- a/src/applet/test_report.c +++ b/src/applet/test_report.c @@ -22,7 +22,7 @@ #include #include #include -#include "crash_data.h" +#include "problem_data.h" #include "dump_dir.h" #include "run_event.h" @@ -34,13 +34,13 @@ static char *do_log(char *log_line, void *param) int main(int argc, char** argv) { - crash_data_t *crash_data = new_crash_data(); + problem_data_t *problem_data = new_problem_data(); - add_to_crash_data(crash_data, "analyzer", "wow"); + add_to_problem_data(problem_data, "analyzer", "wow"); const char *event = "report"; - struct dump_dir *dd = create_dump_dir_from_crash_data(crash_data, "/tmp"); - free_crash_data(crash_data); + struct dump_dir *dd = create_dump_dir_from_problem_data(problem_data, "/tmp"); + free_problem_data(problem_data); if (!dd) return 1; char *dir_name = strdup(dd->dd_dirname); diff --git a/src/cli/abrt-cli.1 b/src/cli/abrt-cli.1 index 1622fb14..9e0a630e 100644 --- a/src/cli/abrt-cli.1 +++ b/src/cli/abrt-cli.1 @@ -8,8 +8,8 @@ abrt\-cli \- a command line interface to abrt .I abrt\-cli is a command line tool that manages application crashes catched by .I abrtd -daemon. It enables access to crash data, and allows to report -crashes depending on active abrt plugins. +daemon. It enables access to problem data, and allows to report +problems depending on active abrt plugins. .SH OPTIONS .B Basic startup options .IP "\-V, \-\-version" diff --git a/src/cli/cli.c b/src/cli/cli.c index 50baed7b..85c6f5f6 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -23,7 +23,7 @@ #include "abrt_dbus.h" #include "report.h" -static crash_data_t *FillCrashInfo(const char *dump_dir_name) +static problem_data_t *FillCrashInfo(const char *dump_dir_name) { int sv_logmode = logmode; logmode = 0; /* suppress EPERM/EACCES errors in opendir */ @@ -33,14 +33,14 @@ static crash_data_t *FillCrashInfo(const char *dump_dir_name) if (!dd) return NULL; - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); - add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); + add_to_problem_data_ext(problem_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); - return crash_data; + return problem_data; } -static void GetCrashInfos(vector_of_crash_data_t *retval, const char *dir_name) +static void GetCrashInfos(vector_of_problem_data_t *retval, const char *dir_name) { VERB1 log("Loading dumps from '%s'", dir_name); @@ -59,9 +59,9 @@ static void GetCrashInfos(vector_of_crash_data_t *retval, const char *dir_name) if (stat(dump_dir_name, &statbuf) == 0 && S_ISDIR(statbuf.st_mode) ) { - crash_data_t *crash_data = FillCrashInfo(dump_dir_name); - if (crash_data) - g_ptr_array_add(retval, crash_data); + problem_data_t *problem_data = FillCrashInfo(dump_dir_name); + if (problem_data) + g_ptr_array_add(retval, problem_data); } free(dump_dir_name); } @@ -70,20 +70,20 @@ static void GetCrashInfos(vector_of_crash_data_t *retval, const char *dir_name) } /** Prints basic information about a crash to stdout. */ -static void print_crash(crash_data_t *crash_data) +static void print_crash(problem_data_t *problem_data) { - struct crash_item *item = g_hash_table_lookup(crash_data, CD_DUMPDIR); + struct problem_item *item = g_hash_table_lookup(problem_data, CD_DUMPDIR); if (item) printf("\tDirectory : %s\n", item->content); - GList *list = g_hash_table_get_keys(crash_data); + GList *list = g_hash_table_get_keys(problem_data); GList *l = list = g_list_sort(list, (GCompareFunc)strcmp); while (l) { const char *key = l->data; - item = g_hash_table_lookup(crash_data, key); + item = g_hash_table_lookup(problem_data, key); if (item && (item->flags & CD_FLAG_LIST) && !strchr(item->content, '\n')) { - char *formatted = format_crash_item(item); + char *formatted = format_problem_item(item); printf("\t%-12s: %s\n", key, formatted ? formatted : item->content); free(formatted); } @@ -97,15 +97,15 @@ static void print_crash(crash_data_t *crash_data) * @param include_reported * Do not skip entries marked as already reported. */ -static void print_crash_list(vector_of_crash_data_t *crash_list, bool include_reported) +static void print_crash_list(vector_of_problem_data_t *crash_list, bool include_reported) { unsigned i; for (i = 0; i < crash_list->len; ++i) { - crash_data_t *crash = get_crash_data(crash_list, i); + problem_data_t *crash = get_problem_data(crash_list, i); if (!include_reported) { - const char *msg = get_crash_item_content_or_NULL(crash, FILENAME_REPORTED_TO); + const char *msg = get_problem_item_content_or_NULL(crash, FILENAME_REPORTED_TO); if (msg) continue; } @@ -118,13 +118,13 @@ static void print_crash_list(vector_of_crash_data_t *crash_list, bool include_re /** * Prints full information about a crash */ -static void print_crash_info(crash_data_t *crash_data, bool show_multiline) +static void print_crash_info(problem_data_t *problem_data, bool show_multiline) { - struct crash_item *item = g_hash_table_lookup(crash_data, CD_DUMPDIR); + struct problem_item *item = g_hash_table_lookup(problem_data, CD_DUMPDIR); if (item) printf("%-16s: %s\n", "Directory", item->content); - GList *list = g_hash_table_get_keys(crash_data); + GList *list = g_hash_table_get_keys(problem_data); GList *l = list = g_list_sort(list, (GCompareFunc)strcmp); bool multi_line = 0; while (l) @@ -132,10 +132,10 @@ static void print_crash_info(crash_data_t *crash_data, bool show_multiline) const char *key = l->data; if (strcmp(key, CD_DUMPDIR) != 0) { - item = g_hash_table_lookup(crash_data, key); + item = g_hash_table_lookup(problem_data, key); if (item) { - char *formatted = format_crash_item(item); + char *formatted = format_problem_item(item); char *output = formatted ? formatted : item->content; char *last_eol = strrchr(output, '\n'); if (show_multiline || !last_eol) @@ -327,7 +327,7 @@ int main(int argc, char** argv) { case OPT_GET_LIST: { - vector_of_crash_data_t *ci = new_vector_of_crash_data(); + vector_of_problem_data_t *ci = new_vector_of_problem_data(); while (D_list) { char *dir = (char *)D_list->data; @@ -335,7 +335,7 @@ int main(int argc, char** argv) D_list = g_list_remove(D_list, dir); } print_crash_list(ci, full); - free_vector_of_crash_data(ci); + free_vector_of_problem_data(ci); break; } case OPT_REPORT: @@ -370,7 +370,7 @@ int main(int argc, char** argv) } case OPT_INFO: { - /* Load crash_data from dump dir */ + /* Load problem_data from dump dir */ struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); if (!dd) return -1; @@ -393,21 +393,21 @@ int main(int argc, char** argv) if (analyzer_result != 0) return 1; - /* Reload crash_data from (possibly updated by analyze) dump dir */ + /* Reload problem_data from (possibly updated by analyze) dump dir */ dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); if (!dd) return -1; } else free(analyze_events_as_lines); - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); - add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, + add_to_problem_data_ext(problem_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); - print_crash_info(crash_data, full); - free_crash_data(crash_data); + print_crash_info(problem_data, full); + free_problem_data(problem_data); break; } diff --git a/src/cli/report.c b/src/cli/report.c index 2e2bd002..96bf0062 100644 --- a/src/cli/report.c +++ b/src/cli/report.c @@ -113,10 +113,10 @@ static void remove_comments_and_unescape(char *str) * Writes a field of crash report to a file. * Field must be writable. */ -static void write_crash_report_field(FILE *fp, crash_data_t *crash_data, +static void write_crash_report_field(FILE *fp, problem_data_t *problem_data, const char *field, const char *description) { - const struct crash_item *value = get_crash_data_item_or_NULL(crash_data, field); + const struct problem_item *value = get_problem_data_item_or_NULL(problem_data, field); if (!value) { // exit silently, all fields are optional for now @@ -142,7 +142,7 @@ static void write_crash_report_field(FILE *fp, crash_data_t *crash_data, * If the report is successfully stored to the file, a zero value is returned. * On failure, nonzero value is returned. */ -static void write_crash_report(crash_data_t *report, FILE *fp) +static void write_crash_report(problem_data_t *report, FILE *fp) { fprintf(fp, "# Please check this report. Lines starting with '#' will be ignored.\n" "# Lines starting with '%%----' separate fields, please do not delete them.\n\n"); @@ -171,7 +171,7 @@ static void write_crash_report(crash_data_t *report, FILE *fp) * 1 if the field was changed. * Changes to read-only fields are ignored. */ -static int read_crash_report_field(const char *text, crash_data_t *report, +static int read_crash_report_field(const char *text, problem_data_t *report, const char *field) { char separator[sizeof("\n" FIELD_SEP)-1 + strlen(field) + 2]; // 2 = '\n\0' @@ -188,7 +188,7 @@ static int read_crash_report_field(const char *text, crash_data_t *report, else length = end - textfield; - struct crash_item *value = get_crash_data_item_or_NULL(report, field); + struct problem_item *value = get_problem_data_item_or_NULL(report, field); if (!value) { error_msg("Field %s not found", field); @@ -226,7 +226,7 @@ static int read_crash_report_field(const char *text, crash_data_t *report, * 1 if any field was changed. * Changes to read-only fields are ignored. */ -static int read_crash_report(crash_data_t *report, const char *text) +static int read_crash_report(problem_data_t *report, const char *text) { int result = 0; result |= read_crash_report_field(text, report, FILENAME_COMMENT); @@ -245,13 +245,13 @@ static int read_crash_report(crash_data_t *report, const char *text) } /** - * Ensures that the fields needed for editor are present in the crash data. + * Ensures that the fields needed for editor are present in the problem data. * Fields: comments. */ -static void create_fields_for_editor(crash_data_t *crash_data) +static void create_fields_for_editor(problem_data_t *problem_data) { - if (!get_crash_data_item_or_NULL(crash_data, FILENAME_COMMENT)) - add_to_crash_data_ext(crash_data, FILENAME_COMMENT, "", CD_FLAG_TXT + CD_FLAG_ISEDITABLE); + if (!get_problem_data_item_or_NULL(problem_data, FILENAME_COMMENT)) + add_to_problem_data_ext(problem_data, FILENAME_COMMENT, "", CD_FLAG_TXT + CD_FLAG_ISEDITABLE); } /** @@ -291,11 +291,11 @@ static int launch_editor(const char *path) /** * Returns: - * 0 on success, crash data has been updated + * 0 on success, problem data has been updated * 2 on failure, unable to create, open, or close temporary file * 3 on failure, cannot launch text editor */ -static int run_report_editor(crash_data_t *crash_data) +static int run_report_editor(problem_data_t *problem_data) { /* Open a temporary file and write the crash report to it. */ char filename[] = "/tmp/abrt-report.XXXXXX"; @@ -312,7 +312,7 @@ static int run_report_editor(crash_data_t *crash_data) die_out_of_memory(); } - write_crash_report(crash_data, fp); + write_crash_report(problem_data, fp); if (fclose(fp)) /* errno is set */ { @@ -354,7 +354,7 @@ static int run_report_editor(crash_data_t *crash_data) remove_comments_and_unescape(text); // Updates the crash report from the file text. - int report_changed = read_crash_report(crash_data, text); + int report_changed = read_crash_report(problem_data, text); free(text); if (report_changed) puts(_("\nThe report has been updated")); @@ -658,7 +658,7 @@ GList *str_to_glist(char *str, int delim) /* Report the crash */ int report(const char *dump_dir_name, int flags) { - /* Load crash_data from (possibly updated by analyze) dump dir */ + /* Load problem_data from (possibly updated by analyze) dump dir */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return -1; @@ -681,23 +681,23 @@ int report(const char *dump_dir_name, int flags) return 1; } - /* Load crash_data from (possibly updated by analyze) dump dir */ + /* Load problem_data from (possibly updated by analyze) dump dir */ dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return -1; char *report_events_as_lines = list_possible_events(dd, NULL, "report"); - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); if (!(flags & CLI_REPORT_BATCH)) { /* Open text editor and give a chance to review the backtrace etc */ - create_fields_for_editor(crash_data); - int result = run_report_editor(crash_data); + create_fields_for_editor(problem_data); + int result = run_report_editor(problem_data); if (result != 0) { - free_crash_data(crash_data); + free_problem_data(problem_data); free(report_events_as_lines); return 1; } @@ -705,9 +705,9 @@ int report(const char *dump_dir_name, int flags) dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) { -//TODO: we should iterate through crash_data and modify all modifiable fields - const char *comment = get_crash_item_content_or_NULL(crash_data, FILENAME_COMMENT); - const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); +//TODO: we should iterate through problem_data and modify all modifiable fields + const char *comment = get_problem_item_content_or_NULL(problem_data, FILENAME_COMMENT); + const char *backtrace = get_problem_item_content_or_NULL(problem_data, FILENAME_BACKTRACE); if (comment) dd_save_text(dd, FILENAME_COMMENT, comment); if (backtrace) @@ -725,7 +725,7 @@ int report(const char *dump_dir_name, int flags) if (!report_events) { - free_crash_data(crash_data); + free_problem_data(problem_data); error_msg_and_die("The dump directory '%s' has no defined reporters", dump_dir_name); } @@ -743,7 +743,7 @@ int report(const char *dump_dir_name, int flags) } else { - const char *rating_str = get_crash_item_content_or_NULL(crash_data, FILENAME_RATING); + const char *rating_str = get_problem_item_content_or_NULL(problem_data, FILENAME_RATING); unsigned rating = rating_str ? xatou(rating_str) : 4; /* For every reporter, ask if user really wants to report using it. */ @@ -777,7 +777,7 @@ int report(const char *dump_dir_name, int flags) { puts(_("Reporting disabled because the backtrace is unusable")); - const char *package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); + const char *package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE); if (package && package[0]) printf(_("Please try to install debuginfo manually using the command: \"debuginfo-install %s\" and try again\n"), package); @@ -801,8 +801,8 @@ int report(const char *dump_dir_name, int flags) } } - printf(_("Crash reported via %d report events (%d errors)\n"), plugins, errors); - free_crash_data(crash_data); + printf(_("Problem reported via %d report events (%d errors)\n"), plugins, errors); + free_problem_data(problem_data); list_free_with_free(report_events); return errors; } diff --git a/src/daemon/MiddleWare.c b/src/daemon/MiddleWare.c index fb943b1c..d6c8aa10 100644 --- a/src/daemon/MiddleWare.c +++ b/src/daemon/MiddleWare.c @@ -23,14 +23,7 @@ #include "CommLayerServerDBus.h" #include "MiddleWare.h" -/** - * Get one crash info. If getting is successful, - * then crash info is filled. - * @param dump_dir_name A dump dir containing all necessary data. - * @param pCrashData A crash info. - * @return It return results of operation. See mw_result_t. - */ -static crash_data_t *FillCrashInfo(const char *dump_dir_name); +static problem_data_t *FillCrashInfo(const char *dump_dir_name); struct logging_state { @@ -126,7 +119,7 @@ static char *do_log(char *log_line, void *param) return log_line; } -mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data) +mw_result_t LoadDebugDump(const char *dump_dir_name, problem_data_t **problem_data) { mw_result_t res; @@ -182,7 +175,7 @@ mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data) dump_dir_name = state.crash_dump_dup_name; } - /* Loads crash_data (from the *first debugdump dir* if this one is a dup) + /* Loads problem_data (from the *first debugdump dir* if this one is a dup) * Returns: * MW_OCCURRED: "crash count is != 1" (iow: it is > 1 - dup) * MW_OK: "crash count is 1" (iow: this is a new crash, not a dup) @@ -208,8 +201,8 @@ mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data) dd_save_text(dd, FILENAME_COUNT, new_count_str); dd_close(dd); - *crash_data = FillCrashInfo(dump_dir_name); - if (*crash_data != NULL) + *problem_data = FillCrashInfo(dump_dir_name); + if (*problem_data != NULL) { res = MW_OK; if (count > 1) @@ -229,24 +222,24 @@ mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data) return res; } -static crash_data_t *FillCrashInfo(const char *dump_dir_name) +static problem_data_t *FillCrashInfo(const char *dump_dir_name) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return NULL; - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); char *events = list_possible_events(dd, NULL, ""); dd_close(dd); - add_to_crash_data_ext(crash_data, CD_EVENTS, events, + add_to_problem_data_ext(problem_data, CD_EVENTS, events, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); free(events); - add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, + add_to_problem_data_ext(problem_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); - return crash_data; + return problem_data; } /* Remove dump dir */ diff --git a/src/daemon/MiddleWare.h b/src/daemon/MiddleWare.h index ef246aaf..1c7645fe 100644 --- a/src/daemon/MiddleWare.h +++ b/src/daemon/MiddleWare.h @@ -47,10 +47,10 @@ typedef enum { * Fills crash info. * Note that if it's a dup, loads _first crash_ info, not this one's. * @param dump_dir_name A debugdump directory. - * @param pCrashData A crash info. + * @param problem_data A problem data. * @return It return results of operation. See mw_result_t. */ -mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data); +mw_result_t LoadDebugDump(const char *dump_dir_name, problem_data_t **problem_data); int DeleteDebugDump(const char *dump_dir_name, long caller_uid); diff --git a/src/daemon/abrt.conf.5 b/src/daemon/abrt.conf.5 index 87bbdb79..4d718a9b 100644 --- a/src/daemon/abrt.conf.5 +++ b/src/daemon/abrt.conf.5 @@ -5,7 +5,7 @@ abrt.conf \- configuration file for abrt .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the problem data and takes action according to its configuration. This manual page describes \fIabrt\fP's configuration file. .P diff --git a/src/daemon/abrtd.8 b/src/daemon/abrtd.8 index 150f0c3d..4a9449aa 100644 --- a/src/daemon/abrtd.8 +++ b/src/daemon/abrtd.8 @@ -6,7 +6,7 @@ abrtd \- automated bug reporting tool's daemon .SH DESCRIPTION .I abrtd is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data (core file, application's command line etc.) +it collects the problem data (core file, application's command line etc.) and takes action according to the type of application that crashed and according to the configuration in the .I abrt.conf diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c index d18265f4..ca0e0d2e 100644 --- a/src/daemon/abrtd.c +++ b/src/daemon/abrtd.c @@ -345,10 +345,10 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin } char *fullname = NULL; - crash_data_t *crash_data = NULL; + problem_data_t *problem_data = NULL; fullname = concat_path_file(DEBUG_DUMPS_DIR, name); - mw_result_t res = LoadDebugDump(fullname, &crash_data); - const char *first = crash_data ? get_crash_item_content_or_NULL(crash_data, CD_DUMPDIR) : NULL; + mw_result_t res = LoadDebugDump(fullname, &problem_data); + const char *first = problem_data ? get_problem_item_content_or_NULL(problem_data, CD_DUMPDIR) : NULL; switch (res) { case MW_OK: @@ -365,11 +365,11 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin delete_dump_dir(fullname); } - const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); + const char *uid_str = get_problem_item_content_or_NULL(problem_data, FILENAME_UID); /* When dup occurs we need to return first occurence, * not the one which is deleted */ - send_dbus_sig_Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), + send_dbus_sig_Crash(get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE), (first) ? first : fullname, uid_str ); @@ -383,7 +383,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin break; } free(fullname); - free_crash_data(crash_data); + free_problem_data(problem_data); } /* while */ free(buf); @@ -650,7 +650,7 @@ int main(int argc, char** argv) goto init_error; pidfile_created = true; - /* Open socket to receive new crashes. */ + /* Open socket to receive new problem data (from python etc). */ dumpsocket_init(); /* Note: this already may process a few dbus messages, diff --git a/src/gui-wizard-gtk/main.c b/src/gui-wizard-gtk/main.c index 87159aec..2d036085 100644 --- a/src/gui-wizard-gtk/main.c +++ b/src/gui-wizard-gtk/main.c @@ -32,12 +32,12 @@ char *g_dump_dir_name = NULL; char *g_analyze_events = NULL; char *g_reanalyze_events = NULL; char *g_report_events = NULL; -crash_data_t *g_cd; +problem_data_t *g_cd; -void reload_crash_data_from_dump_dir(void) +void reload_problem_data_from_dump_dir(void) { - free_crash_data(g_cd); + free_problem_data(g_cd); free(g_analyze_events); free(g_reanalyze_events); free(g_report_events); @@ -46,8 +46,8 @@ void reload_crash_data_from_dump_dir(void) if (!dd) xfunc_die(); /* dd_opendir already logged error msg */ - g_cd = create_crash_data_from_dump_dir(dd); - add_to_crash_data_ext(g_cd, CD_DUMPDIR, g_dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); + g_cd = create_problem_data_from_dump_dir(dd); + add_to_problem_data_ext(g_cd, CD_DUMPDIR, g_dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); g_analyze_events = list_possible_events(dd, NULL, "analyze"); g_reanalyze_events = list_possible_events(dd, NULL, "reanalyze"); @@ -119,9 +119,9 @@ int main(int argc, char **argv) g_custom_logger = &show_error_as_msgbox; - reload_crash_data_from_dump_dir(); + reload_problem_data_from_dump_dir(); - update_gui_state_from_crash_data(); + update_gui_state_from_problem_data(); /* Enter main loop */ gtk_main(); diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c index 0a57f04d..2639cd30 100644 --- a/src/gui-wizard-gtk/wizard.c +++ b/src/gui-wizard-gtk/wizard.c @@ -247,7 +247,7 @@ void show_error_as_msgbox(const char *msg) static void load_text_to_text_view(GtkTextView *tv, const char *name) { - const char *str = g_cd ? get_crash_item_content_or_NULL(g_cd, name) : NULL; + const char *str = g_cd ? get_problem_item_content_or_NULL(g_cd, name) : NULL; gtk_text_buffer_set_text(gtk_text_view_get_buffer(tv), (str ? str : ""), -1); } @@ -263,7 +263,7 @@ static gchar *get_malloced_string_from_text_view(GtkTextView *tv) static void save_text_if_changed(const char *name, const char *new_value) { - const char *old_value = g_cd ? get_crash_item_content_or_NULL(g_cd, name) : ""; + const char *old_value = g_cd ? get_problem_item_content_or_NULL(g_cd, name) : ""; if (!old_value) old_value = ""; if (strcmp(new_value, old_value) != 0) @@ -276,8 +276,8 @@ static void save_text_if_changed(const char *name, const char *new_value) } //FIXME: else: what to do with still-unsaved data in the widget?? dd_close(dd); - reload_crash_data_from_dump_dir(); - update_gui_state_from_crash_data(); + reload_problem_data_from_dump_dir(); + update_gui_state_from_problem_data(); } } @@ -339,7 +339,7 @@ static void tv_details_row_activated( gchar *column_name; gtk_tree_model_get(model, &iter, DETAIL_COLUMN_NAME, &column_name, -1); - struct crash_item *item = get_crash_data_item_or_NULL(g_cd, column_name); + struct problem_item *item = get_problem_data_item_or_NULL(g_cd, column_name); if (!item || !(item->flags & CD_FLAG_TXT)) return; if (!strchr(item->content, '\n')) /* one line? */ @@ -375,7 +375,7 @@ static void tv_details_cursor_changed( gchar *column_name; gtk_tree_model_get(model, &iter, DETAIL_COLUMN_NAME, &column_name, -1); - struct crash_item *item = get_crash_data_item_or_NULL(g_cd, column_name); + struct problem_item *item = get_problem_data_item_or_NULL(g_cd, column_name); gboolean editable = (item && (item->flags & CD_FLAG_TXT) && !strchr(item->content, '\n')); @@ -391,7 +391,7 @@ static void tv_details_cursor_changed( } -/* update_gui_state_from_crash_data */ +/* update_gui_state_from_problem_data */ static gint find_by_button(gconstpointer a, gconstpointer button) { @@ -532,7 +532,7 @@ struct cd_stats { static void append_item_to_ls_details(gpointer name, gpointer value, gpointer data) { - crash_item *item = (crash_item*)value; + problem_item *item = (problem_item*)value; struct cd_stats *stats = data; GtkTreeIter iter; @@ -578,11 +578,11 @@ static void append_item_to_ls_details(gpointer name, gpointer value, gpointer da } } -void update_gui_state_from_crash_data(void) +void update_gui_state_from_problem_data(void) { gtk_window_set_title(GTK_WINDOW(g_assistant), g_dump_dir_name); - const char *reason = get_crash_item_content_or_NULL(g_cd, FILENAME_REASON); + const char *reason = get_problem_item_content_or_NULL(g_cd, FILENAME_REASON); gtk_label_set_text(g_lbl_cd_reason, reason ? reason : _("(no description)")); ///vda make_label_autowrap_on_resize(g_lbl_cd_reason); @@ -860,8 +860,8 @@ static gboolean consume_cmd_output(GIOChannel *source, GIOCondition condition, g strbuf_free(evd->event_log); free(evd); - reload_crash_data_from_dump_dir(); - update_gui_state_from_crash_data(); + reload_problem_data_from_dump_dir(); + update_gui_state_from_problem_data(); return FALSE; /* "please remove this event" */ } @@ -993,10 +993,10 @@ static void check_backtrace_and_allow_send(void) //TODO: rename, this checks rat * but so far only oopses doesn't have rating, so for now we * skip the "kernel" manually */ - const char *component = get_crash_item_content_or_NULL(g_cd, FILENAME_COMPONENT); + const char *component = get_problem_item_content_or_NULL(g_cd, FILENAME_COMPONENT); if (strcmp(component, "kernel") != 0) { - const char *rating = get_crash_item_content_or_NULL(g_cd, FILENAME_RATING); + const char *rating = get_problem_item_content_or_NULL(g_cd, FILENAME_RATING); if (rating) switch (*rating) { case '4': //bt is ok - no warning here @@ -1047,7 +1047,7 @@ static void on_btn_refresh_clicked(GtkButton *button) g_analyze_events = append_to_malloced_string(g_analyze_events, g_reanalyze_events); g_reanalyze_events[0] = '\0'; /* Refresh GUI so that we see new analyze+reanalyze buttons */ - update_gui_state_from_crash_data(); + update_gui_state_from_problem_data(); /* Change page to analyzer selector - let user play with them */ gtk_assistant_set_current_page(g_assistant, PAGENO_ANALYZE_SELECTOR); @@ -1144,13 +1144,13 @@ static gint next_page_no(gint current_page_no, gpointer data) { #if 0 case PAGENO_COMMENT: - if (get_crash_item_content_or_NULL(g_cd, FILENAME_COMMENT)) + if (get_problem_item_content_or_NULL(g_cd, FILENAME_COMMENT)) break; goto again; /* no comment, skip next page */ #endif case PAGENO_BACKTRACE_APPROVAL: - if (get_crash_item_content_or_NULL(g_cd, FILENAME_BACKTRACE)) + if (get_problem_item_content_or_NULL(g_cd, FILENAME_BACKTRACE)) break; goto again; /* no backtrace, skip next page */ diff --git a/src/gui-wizard-gtk/wizard.glade b/src/gui-wizard-gtk/wizard.glade index 672fb141..73070e8d 100644 --- a/src/gui-wizard-gtk/wizard.glade +++ b/src/gui-wizard-gtk/wizard.glade @@ -34,7 +34,7 @@ False 0 5 - Click 'Forward' to proceed with analyzing and reporting this problem. + Click 'Forward' to proceed with analyzing and reporting this problem to proceed with analyzing and reporting this problem to proceed with analyzing and reporting this problem to proceed with analyzing and reporting this problem. False diff --git a/src/gui-wizard-gtk/wizard.h b/src/gui-wizard-gtk/wizard.h index a27a27d9..5e341e34 100644 --- a/src/gui-wizard-gtk/wizard.h +++ b/src/gui-wizard-gtk/wizard.h @@ -17,7 +17,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ void create_assistant(void); -void update_gui_state_from_crash_data(void); +void update_gui_state_from_problem_data(void); void show_error_as_msgbox(const char *msg); @@ -26,5 +26,5 @@ extern char *g_dump_dir_name; extern char *g_analyze_events; extern char *g_reanalyze_events; extern char *g_report_events; -extern crash_data_t *g_cd; -void reload_crash_data_from_dump_dir(void); +extern problem_data_t *g_cd; +void reload_problem_data_from_dump_dir(void); diff --git a/src/include/Makefile.am b/src/include/Makefile.am index e6f0387b..eaebe3a1 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -1,6 +1,6 @@ libreport_includedir = $(includedir)/report libreport_include_HEADERS = \ - report/crash_data.h \ + report/problem_data.h \ report/dump_dir.h \ report/run_event.h \ report/event_config.h @@ -9,5 +9,5 @@ libabrt_includedir = $(includedir)/abrt libabrt_include_HEADERS = \ abrtlib.h \ abrt_types.h \ - abrt_crash_data.h \ + abrt_problem_data.h \ xfuncs.h diff --git a/src/include/abrt_crash_data.h b/src/include/abrt_crash_data.h deleted file mode 100644 index 237a3d01..00000000 --- a/src/include/abrt_crash_data.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - Copyright (C) 2009 Abrt team. - Copyright (C) 2009 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. -*/ -#ifndef ABRT_CRASH_DUMP_H_ -#define ABRT_CRASH_DUMP_H_ - -#include "crash_data.h" -#include "abrt_types.h" - -// Text bigger than this usually is attached, not added inline -#define CD_TEXT_ATT_SIZE (2*1024) - -// Filenames in dump directory: -// filled by a hook: -#define FILENAME_REASON "reason" /* mandatory */ -#define FILENAME_UID "uid" /* mandatory */ -#define FILENAME_TIME "time" /* mandatory */ -#define FILENAME_ANALYZER "analyzer" -#define FILENAME_EXECUTABLE "executable" -#define FILENAME_BINARY "binary" -#define FILENAME_CMDLINE "cmdline" -#define FILENAME_COREDUMP "coredump" -#define FILENAME_BACKTRACE "backtrace" -#define FILENAME_MAPS "maps" -#define FILENAME_SMAPS "smaps" -#define FILENAME_ENVIRON "environ" -#define FILENAME_DUPHASH "global_uuid" /* name is compat, to be renamed to "duphash" */ -// Name of the function where the application crashed. -// Optional. -#define FILENAME_CRASH_FUNCTION "crash_function" -// filled by CDebugDump::Create() (which also fills FILENAME_UID): -#define FILENAME_ARCHITECTURE "architecture" -#define FILENAME_KERNEL "kernel" -// From /etc/system-release or /etc/redhat-release -#define FILENAME_OS_RELEASE "os_release" -// Filled by -#define FILENAME_PACKAGE "package" -#define FILENAME_COMPONENT "component" -#define FILENAME_COMMENT "comment" -#define FILENAME_RATING "rating" -#define FILENAME_HOSTNAME "hostname" -// Optional. Set to "1" by abrt-handle-upload for every unpacked crashdump -#define FILENAME_REMOTE "remote" -#define FILENAME_TAINTED "kernel_tainted" -// TODO: TicketUploader also has open-coded "TICKET", "CUSTOMER" files - -#define FILENAME_UUID "uuid" -#define FILENAME_COUNT "count" -/* Multi-line list of places problem was reported. - * Recommended line format: - * "Reporter: VAR=VAL VAR=VAL" - * Use add_reported_to(dd, "line_without_newline"): it adds line - * only if it is not already there. - */ -#define FILENAME_REPORTED_TO "reported_to" -#define FILENAME_EVENT_LOG "event_log" -// Not stored as files, added "on the fly": -#define CD_DUMPDIR "DumpDir" -// "Which events are possible (make sense) on this crash dump?" -// (a string with "\n" terminated event names) -#define CD_EVENTS "Events" - -/* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK - * when it reaches HIGH_WATERMARK size - */ -enum { - EVENT_LOG_HIGH_WATERMARK = 30 * 1024, - EVENT_LOG_LOW_WATERMARK = 20 * 1024, -}; - -#ifdef __cplusplus -extern "C" { -#endif - -#define add_reported_to abrt_add_reported_to -void add_reported_to(struct dump_dir *dd, const char *line); - -#define log_crash_data abrt_log_crash_data -void log_crash_data(crash_data_t *crash_data, const char *pfx); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/abrt_problem_data.h b/src/include/abrt_problem_data.h new file mode 100644 index 00000000..3ab6679c --- /dev/null +++ b/src/include/abrt_problem_data.h @@ -0,0 +1,100 @@ +/* + Copyright (C) 2009 Abrt team. + Copyright (C) 2009 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. +*/ +#ifndef ABRT_PROBLEM_DATA_H_ +#define ABRT_PROBLEM_DATA_H_ + +#include "problem_data.h" +#include "abrt_types.h" + +// Text bigger than this usually is attached, not added inline +#define CD_TEXT_ATT_SIZE (2*1024) + +// Filenames in dump directory: +// filled by a hook: +#define FILENAME_REASON "reason" /* mandatory */ +#define FILENAME_UID "uid" /* mandatory */ +#define FILENAME_TIME "time" /* mandatory */ +#define FILENAME_ANALYZER "analyzer" +#define FILENAME_EXECUTABLE "executable" +#define FILENAME_BINARY "binary" +#define FILENAME_CMDLINE "cmdline" +#define FILENAME_COREDUMP "coredump" +#define FILENAME_BACKTRACE "backtrace" +#define FILENAME_MAPS "maps" +#define FILENAME_SMAPS "smaps" +#define FILENAME_ENVIRON "environ" +#define FILENAME_DUPHASH "global_uuid" /* name is compat, to be renamed to "duphash" */ +// Name of the function where the application crashed. +// Optional. +#define FILENAME_CRASH_FUNCTION "crash_function" +// filled by CDebugDump::Create() (which also fills FILENAME_UID): +#define FILENAME_ARCHITECTURE "architecture" +#define FILENAME_KERNEL "kernel" +// From /etc/system-release or /etc/redhat-release +#define FILENAME_OS_RELEASE "os_release" +// Filled by +#define FILENAME_PACKAGE "package" +#define FILENAME_COMPONENT "component" +#define FILENAME_COMMENT "comment" +#define FILENAME_RATING "rating" +#define FILENAME_HOSTNAME "hostname" +// Optional. Set to "1" by abrt-handle-upload for every unpacked dump +#define FILENAME_REMOTE "remote" +#define FILENAME_TAINTED "kernel_tainted" +// TODO: TicketUploader also has open-coded "TICKET", "CUSTOMER" files + +#define FILENAME_UUID "uuid" +#define FILENAME_COUNT "count" +/* Multi-line list of places problem was reported. + * Recommended line format: + * "Reporter: VAR=VAL VAR=VAL" + * Use add_reported_to(dd, "line_without_newline"): it adds line + * only if it is not already there. + */ +#define FILENAME_REPORTED_TO "reported_to" +#define FILENAME_EVENT_LOG "event_log" +// Not stored as files, added "on the fly": +#define CD_DUMPDIR "DumpDir" +// "Which events are possible (make sense) on this dump dir?" +// (a string with "\n" terminated event names) +#define CD_EVENTS "Events" + +/* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK + * when it reaches HIGH_WATERMARK size + */ +enum { + EVENT_LOG_HIGH_WATERMARK = 30 * 1024, + EVENT_LOG_LOW_WATERMARK = 20 * 1024, +}; + +#ifdef __cplusplus +extern "C" { +#endif + +#define add_reported_to abrt_add_reported_to +void add_reported_to(struct dump_dir *dd, const char *line); + +#define log_problem_data abrt_log_problem_data +void log_problem_data(problem_data_t *problem_data, const char *pfx); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 6d9337d5..19ce7ad9 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -77,7 +77,7 @@ int vdprintf(int d, const char *format, va_list ap); #include "strbuf.h" #include "hash_sha1.h" -#include "abrt_crash_data.h" +#include "abrt_problem_data.h" #include "abrt_types.h" #include "dump_dir.h" #include "hooklib.h" @@ -239,13 +239,13 @@ int daemon_is_ok(); char *iso_date_string(time_t *pt); #define make_description_bz abrt_make_description_bz -char* make_description_bz(crash_data_t *crash_data); +char* make_description_bz(problem_data_t *problem_data); #define make_description_comment abrt_make_description_comment -char* make_description_comment(crash_data_t *crash_data); +char* make_description_comment(problem_data_t *problem_data); #define make_description_logger abrt_make_description_logger -char* make_description_logger(crash_data_t *crash_data); +char* make_description_logger(problem_data_t *problem_data); #define make_description_mailx abrt_make_description_mailx -char* make_description_mailx(crash_data_t *crash_data); +char* make_description_mailx(problem_data_t *problem_data); #define parse_release_for_bz abrt_parse_release_for_bz void parse_release_for_bz(const char *pRelease, char **product, char **version); diff --git a/src/include/report/crash_data.h b/src/include/report/crash_data.h deleted file mode 100644 index e152c63f..00000000 --- a/src/include/report/crash_data.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright (C) 2009 Abrt team. - Copyright (C) 2009 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. -*/ -#ifndef CRASH_DATA_H_ -#define CRASH_DATA_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct dump_dir; - -enum { - CD_FLAG_BIN = (1 << 0), - CD_FLAG_TXT = (1 << 1), - CD_FLAG_ISEDITABLE = (1 << 2), - CD_FLAG_ISNOTEDITABLE = (1 << 3), - /* Show this element in "short" info (abrt-cli -l) */ - CD_FLAG_LIST = (1 << 4), - CD_FLAG_UNIXTIME = (1 << 5), -}; - -struct crash_item { - char *content; - unsigned flags; -}; -typedef struct crash_item crash_item; - -char *format_crash_item(struct crash_item *item); - -/* In-memory crash data structure and accessors */ - -typedef GHashTable crash_data_t; - -crash_data_t *new_crash_data(void); - -static inline void free_crash_data(crash_data_t *crash_data) -{ - if (crash_data) - g_hash_table_destroy(crash_data); -} - -void add_to_crash_data_ext(crash_data_t *crash_data, - const char *name, - const char *content, - unsigned flags); -/* Uses CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE flags */ -void add_to_crash_data(crash_data_t *crash_data, - const char *name, - const char *content); - -static inline struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key) -{ - return (struct crash_item *)g_hash_table_lookup(crash_data, key); -} -const char *get_crash_item_content_or_NULL(crash_data_t *crash_data, const char *key); -/* Aborts if key is not found: */ -const char *get_crash_item_content_or_die(crash_data_t *crash_data, const char *key); - - -/* Vector of these structures */ - -typedef GPtrArray vector_of_crash_data_t; - -static inline crash_data_t *get_crash_data(vector_of_crash_data_t *vector, unsigned i) -{ - return (crash_data_t *)g_ptr_array_index(vector, i); -} - -vector_of_crash_data_t *new_vector_of_crash_data(void); -static inline void free_vector_of_crash_data(vector_of_crash_data_t *vector) -{ - if (vector) - g_ptr_array_free(vector, TRUE); -} - - -/* Conversions between in-memory and on-disk formats */ - -void load_crash_data_from_dump_dir(crash_data_t *crash_data, struct dump_dir *dd); -crash_data_t *create_crash_data_from_dump_dir(struct dump_dir *dd); - -struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const char *base_dir_name); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/report/dump_dir.h b/src/include/report/dump_dir.h index 026571b7..c88ebe7f 100644 --- a/src/include/report/dump_dir.h +++ b/src/include/report/dump_dir.h @@ -1,5 +1,5 @@ /* - On-disk storage of crash dumps + On-disk storage of problem data Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) Copyright (C) 2009 RedHat inc. diff --git a/src/include/report/problem_data.h b/src/include/report/problem_data.h new file mode 100644 index 00000000..1481654f --- /dev/null +++ b/src/include/report/problem_data.h @@ -0,0 +1,106 @@ +/* + Copyright (C) 2009 Abrt team. + Copyright (C) 2009 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. +*/ +#ifndef PROBLEM_DATA_H_ +#define PROBLEM_DATA_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct dump_dir; + +enum { + CD_FLAG_BIN = (1 << 0), + CD_FLAG_TXT = (1 << 1), + CD_FLAG_ISEDITABLE = (1 << 2), + CD_FLAG_ISNOTEDITABLE = (1 << 3), + /* Show this element in "short" info (abrt-cli -l) */ + CD_FLAG_LIST = (1 << 4), + CD_FLAG_UNIXTIME = (1 << 5), +}; + +struct problem_item { + char *content; + unsigned flags; +}; +typedef struct problem_item problem_item; + +char *format_problem_item(struct problem_item *item); + +/* In-memory problem data structure and accessors */ + +typedef GHashTable problem_data_t; + +problem_data_t *new_problem_data(void); + +static inline void free_problem_data(problem_data_t *problem_data) +{ + if (problem_data) + g_hash_table_destroy(problem_data); +} + +void add_to_problem_data_ext(problem_data_t *problem_data, + const char *name, + const char *content, + unsigned flags); +/* Uses CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE flags */ +void add_to_problem_data(problem_data_t *problem_data, + const char *name, + const char *content); + +static inline struct problem_item *get_problem_data_item_or_NULL(problem_data_t *problem_data, const char *key) +{ + return (struct problem_item *)g_hash_table_lookup(problem_data, key); +} +const char *get_problem_item_content_or_NULL(problem_data_t *problem_data, const char *key); +/* Aborts if key is not found: */ +const char *get_problem_item_content_or_die(problem_data_t *problem_data, const char *key); + + +/* Vector of these structures */ + +typedef GPtrArray vector_of_problem_data_t; + +static inline problem_data_t *get_problem_data(vector_of_problem_data_t *vector, unsigned i) +{ + return (problem_data_t *)g_ptr_array_index(vector, i); +} + +vector_of_problem_data_t *new_vector_of_problem_data(void); +static inline void free_vector_of_problem_data(vector_of_problem_data_t *vector) +{ + if (vector) + g_ptr_array_free(vector, TRUE); +} + + +/* Conversions between in-memory and on-disk formats */ + +void load_problem_data_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd); +problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd); + +struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/report/run_event.h b/src/include/report/run_event.h index 7fd8edea..8bd86543 100644 --- a/src/include/report/run_event.h +++ b/src/include/report/run_event.h @@ -19,7 +19,7 @@ #ifndef RUN_EVENT_H_ #define RUN_EVENT_H_ -#include "crash_data.h" +#include "problem_data.h" #ifdef __cplusplus extern "C" { @@ -65,7 +65,7 @@ void free_commands(struct run_event_state *state); * of post_run_callback. If all actions are successful, returns 0. */ int run_event_on_dir_name(struct run_event_state *state, const char *dump_dir_name, const char *event); -int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, const char *event); +int run_event_on_problem_data(struct run_event_state *state, problem_data_t *data, const char *event); /* Querying for possible events */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index decfeffd..f2b97749 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -36,7 +36,7 @@ libreport_la_SOURCES = \ load_plugin_settings.c \ make_descr.c \ run_event.c \ - crash_data.c \ + problem_data.c \ create_dump_dir.c \ abrt_types.c \ hooklib.c hooklib.h \ diff --git a/src/lib/crash_data.c b/src/lib/crash_data.c deleted file mode 100644 index 81513388..00000000 --- a/src/lib/crash_data.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - Copyright (C) 2010 Denys Vlasenko (dvlasenk@redhat.com) - 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. -*/ -#include "abrtlib.h" - -static void free_crash_item(void *ptr) -{ - if (ptr) - { - struct crash_item *item = (struct crash_item *)ptr; - free(item->content); - free(item); - } -} - -char *format_crash_item(struct crash_item *item) -{ - if (!item) - return xstrdup("(nullitem)"); - - if (item->flags & CD_FLAG_UNIXTIME) - { - errno = 0; - char *end; - time_t time = strtol(item->content, &end, 10); - if (!errno && !*end && end != item->content) - { - char timeloc[256]; - int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time)); - if (success) - return xstrdup(timeloc); - } - } - return NULL; -} - -/* crash_data["name"] = { "content", CD_FLAG_foo_bits } */ - -crash_data_t *new_crash_data(void) -{ - return g_hash_table_new_full(g_str_hash, g_str_equal, - free, free_crash_item); -} - -void add_to_crash_data_ext(crash_data_t *crash_data, - const char *name, - const char *content, - unsigned flags) -{ - if (!(flags & CD_FLAG_BIN)) - flags |= CD_FLAG_TXT; - if (!(flags & CD_FLAG_ISEDITABLE)) - flags |= CD_FLAG_ISNOTEDITABLE; - - struct crash_item *item = (struct crash_item *)xzalloc(sizeof(*item)); - item->content = xstrdup(content); - item->flags = flags; - g_hash_table_replace(crash_data, xstrdup(name), item); -} - -void add_to_crash_data(crash_data_t *crash_data, - const char *name, - const char *content) -{ - add_to_crash_data_ext(crash_data, name, content, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); -} - -const char *get_crash_item_content_or_die(crash_data_t *crash_data, const char *key) -{ - struct crash_item *item = get_crash_data_item_or_NULL(crash_data, key); - if (!item) - error_msg_and_die("Error accessing crash data: no ['%s']", key); - return item->content; -} - -const char *get_crash_item_content_or_NULL(crash_data_t *crash_data, const char *key) -{ - struct crash_item *item = get_crash_data_item_or_NULL(crash_data, key); - if (!item) - return NULL; - return item->content; -} - - -/* crash_data_vector[i] = { "name" = { "content", CD_FLAG_foo_bits } } */ - -vector_of_crash_data_t *new_vector_of_crash_data(void) -{ - return g_ptr_array_new_with_free_func((void (*)(void*)) &free_crash_data); -} - - -/* Miscellaneous helpers */ - -static bool is_in_list(const char *name, const char *const *v) -{ - while (*v) - { - if (strcmp(*v, name) == 0) - return true; - v++; - } - return false; -} - -static const char *const editable_files[] = { - FILENAME_COMMENT , - FILENAME_BACKTRACE, - NULL -}; -static bool is_editable_file(const char *file_name) -{ - return is_in_list(file_name, editable_files); -} - -static const char *const always_text_files[] = { - FILENAME_CMDLINE , - FILENAME_BACKTRACE, - NULL -}; -static char* is_text_file(const char *name, ssize_t *sz) -{ - /* We were using magic.h API to check for file being text, but it thinks - * that file containing just "0" is not text (!!) - * So, we do it ourself. - */ - - int fd = open(name, O_RDONLY); - if (fd < 0) - return NULL; /* it's not text (because it does not exist! :) */ - - /* Maybe 64k limit is small. But _some_ limit is necessary: - * fields declared "text" may end up in editing fields and such. - * We don't want to accidentally end up with 100meg text in a textbox! - * So, don't remove this. If you really need to, raise the limit. - * - * Bumped up to 200k: saw 124740 byte /proc/PID/smaps file - */ - off_t size = lseek(fd, 0, SEEK_END); - if (size < 0 || size > 200*1024) - { - close(fd); - return NULL; /* it's not a SMALL text */ - } - lseek(fd, 0, SEEK_SET); - - char *buf = (char*)xmalloc(*sz); - ssize_t r = full_read(fd, buf, *sz); - close(fd); - if (r < 0) - { - free(buf); - return NULL; /* it's not text (because we can't read it) */ - } - if (r < *sz) - buf[r] = '\0'; - *sz = r; - - /* Some files in our dump directories are known to always be textual */ - const char *base = strrchr(name, '/'); - if (base) - { - base++; - if (is_in_list(base, always_text_files)) - return buf; - } - - /* Every once in a while, even a text file contains a few garbled - * or unexpected non-ASCII chars. We should not declare it "binary". - */ - const unsigned RATIO = 50; - unsigned total_chars = r + RATIO; - unsigned bad_chars = 1; /* 1 prevents division by 0 later */ - while (--r >= 0) - { - if (buf[r] >= 0x7f - /* among control chars, only '\t','\n' etc are allowed */ - || (buf[r] < ' ' && !isspace(buf[r])) - ) { - if (buf[r] == '\0') - { - /* We don't like NULs very much. Not text for sure! */ - free(buf); - return NULL; - } - bad_chars++; - } - } - - if ((total_chars / bad_chars) >= RATIO) - return buf; /* looks like text to me */ - - free(buf); - return NULL; /* it's binary */ -} - -void load_crash_data_from_dump_dir(crash_data_t *crash_data, struct dump_dir *dd) -{ - char *short_name; - char *full_name; - - dd_init_next_file(dd); - while (dd_get_next_file(dd, &short_name, &full_name)) - { - ssize_t sz = 4*1024; - char *text = NULL; - bool editable = is_editable_file(short_name); - - if (!editable) - { - text = is_text_file(full_name, &sz); - if (!text) - { - add_to_crash_data_ext(crash_data, - short_name, - full_name, - CD_FLAG_BIN + CD_FLAG_ISNOTEDITABLE - ); - free(short_name); - free(full_name); - continue; - } - } - - char *content; - if (sz < 4*1024) /* did is_text_file read entire file? */ - { - content = text; - /* Strip '\n' from one-line elements: */ - char *nl = strchr(content, '\n'); - if (nl && nl[1] == '\0') - *nl = '\0'; - } - else - { - /* no, need to read it all */ - free(text); - content = dd_load_text(dd, short_name); - } - - int flags = 0; - - if (editable) - flags |= CD_FLAG_TXT | CD_FLAG_ISEDITABLE; - else - flags |= CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE; - - static const char *const list_files[] = { - FILENAME_UID , - FILENAME_PACKAGE , - FILENAME_EXECUTABLE, - FILENAME_TIME , - FILENAME_COUNT , - NULL - }; - if (is_in_list(short_name, list_files)) - flags |= CD_FLAG_LIST; - - if (strcmp(short_name, FILENAME_TIME) == 0) - flags |= CD_FLAG_UNIXTIME; - - add_to_crash_data_ext(crash_data, - short_name, - content, - flags - ); - free(short_name); - free(full_name); - free(content); - } -} - -crash_data_t *create_crash_data_from_dump_dir(struct dump_dir *dd) -{ - crash_data_t *crash_data = new_crash_data(); - load_crash_data_from_dump_dir(crash_data, dd); - return crash_data; -} - -void log_crash_data(crash_data_t *crash_data, const char *pfx) -{ - GHashTableIter iter; - char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); - while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) - { - log("%s[%s]:'%s' 0x%x", - pfx, name, - value->content, - value->flags - ); - } -} diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c index 50893f05..9839a96c 100644 --- a/src/lib/create_dump_dir.c +++ b/src/lib/create_dump_dir.c @@ -29,7 +29,7 @@ static struct dump_dir *try_dd_create(const char *base_dir_name, const char *dir return dd; } -struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const char *base_dir_name) +struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name) { char dir_name[sizeof("abrt-tmp-YYYY-MM-DD-HH:MM:SS-%lu") + sizeof(long)*3]; sprintf(dir_name, "abrt-tmp-%s-%lu", iso_date_string(NULL), (long)getpid()); @@ -63,13 +63,13 @@ struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { if (name[0] == '.' || strchr(name, '/')) { - error_msg("Crash data field name contains disallowed chars: '%s'", name); + error_msg("Problem data field name contains disallowed chars: '%s'", name); goto next; } diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c index 464df5c9..0c6467f4 100644 --- a/src/lib/dump_dir.c +++ b/src/lib/dump_dir.c @@ -315,7 +315,7 @@ struct dump_dir *dd_opendir(const char *dir, int flags) * directory when run without arguments, because its option -d DIR * defaults to "."! */ - error_msg("'%s' is not a crash dump directory", dir); + error_msg("'%s' is not a dump directory", dir); } else if (errno == ENOENT || errno == ENOTDIR) { diff --git a/src/lib/make_descr.c b/src/lib/make_descr.c index c5b4bd6c..35f4e9dc 100644 --- a/src/lib/make_descr.c +++ b/src/lib/make_descr.c @@ -68,7 +68,7 @@ static const char *const blacklisted_items[] = { NULL }; -char* make_description_mailx(crash_data_t *crash_data) +char* make_description_mailx(problem_data_t *problem_data) { struct strbuf *buf_dsc = strbuf_new(); struct strbuf *buf_additional_files = strbuf_new(); @@ -77,8 +77,8 @@ char* make_description_mailx(crash_data_t *crash_data) GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { if (value->flags & CD_FLAG_TXT) @@ -112,7 +112,7 @@ char* make_description_mailx(crash_data_t *crash_data) return strbuf_free_nobuf(buf_dsc); } -char* make_description_bz(crash_data_t *crash_data) +char* make_description_bz(problem_data_t *problem_data) { struct strbuf *buf_dsc = strbuf_new(); struct strbuf *buf_big_dsc = strbuf_new(); @@ -120,8 +120,8 @@ char* make_description_bz(crash_data_t *crash_data) GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { struct stat statbuf; @@ -200,15 +200,15 @@ char* make_description_bz(crash_data_t *crash_data) return strbuf_free_nobuf(buf_dsc); } -char* make_description_logger(crash_data_t *crash_data) +char* make_description_logger(problem_data_t *problem_data) { struct strbuf *buf_dsc = strbuf_new(); struct strbuf *buf_long_dsc = strbuf_new(); GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { const char *content = value->content; @@ -251,12 +251,12 @@ char* make_description_logger(crash_data_t *crash_data) return strbuf_free_nobuf(buf_dsc); } -char* make_description_comment(crash_data_t *crash_data) +char* make_description_comment(problem_data_t *problem_data) { char *comment = NULL; - struct crash_item *value; + struct problem_item *value; - value = get_crash_data_item_or_NULL(crash_data, FILENAME_COMMENT); + value = get_problem_data_item_or_NULL(problem_data, FILENAME_COMMENT); if (value) { if (value->content[0]) diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c new file mode 100644 index 00000000..63db70db --- /dev/null +++ b/src/lib/problem_data.c @@ -0,0 +1,309 @@ +/* + Copyright (C) 2010 Denys Vlasenko (dvlasenk@redhat.com) + 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. +*/ +#include "abrtlib.h" + +static void free_problem_item(void *ptr) +{ + if (ptr) + { + struct problem_item *item = (struct problem_item *)ptr; + free(item->content); + free(item); + } +} + +char *format_problem_item(struct problem_item *item) +{ + if (!item) + return xstrdup("(nullitem)"); + + if (item->flags & CD_FLAG_UNIXTIME) + { + errno = 0; + char *end; + time_t time = strtol(item->content, &end, 10); + if (!errno && !*end && end != item->content) + { + char timeloc[256]; + int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time)); + if (success) + return xstrdup(timeloc); + } + } + return NULL; +} + +/* problem_data["name"] = { "content", CD_FLAG_foo_bits } */ + +problem_data_t *new_problem_data(void) +{ + return g_hash_table_new_full(g_str_hash, g_str_equal, + free, free_problem_item); +} + +void add_to_problem_data_ext(problem_data_t *problem_data, + const char *name, + const char *content, + unsigned flags) +{ + if (!(flags & CD_FLAG_BIN)) + flags |= CD_FLAG_TXT; + if (!(flags & CD_FLAG_ISEDITABLE)) + flags |= CD_FLAG_ISNOTEDITABLE; + + struct problem_item *item = (struct problem_item *)xzalloc(sizeof(*item)); + item->content = xstrdup(content); + item->flags = flags; + g_hash_table_replace(problem_data, xstrdup(name), item); +} + +void add_to_problem_data(problem_data_t *problem_data, + const char *name, + const char *content) +{ + add_to_problem_data_ext(problem_data, name, content, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); +} + +const char *get_problem_item_content_or_die(problem_data_t *problem_data, const char *key) +{ + struct problem_item *item = get_problem_data_item_or_NULL(problem_data, key); + if (!item) + error_msg_and_die("Error accessing problem data: no ['%s']", key); + return item->content; +} + +const char *get_problem_item_content_or_NULL(problem_data_t *problem_data, const char *key) +{ + struct problem_item *item = get_problem_data_item_or_NULL(problem_data, key); + if (!item) + return NULL; + return item->content; +} + + +/* problem_data_vector[i] = { "name" = { "content", CD_FLAG_foo_bits } } */ + +vector_of_problem_data_t *new_vector_of_problem_data(void) +{ + return g_ptr_array_new_with_free_func((void (*)(void*)) &free_problem_data); +} + + +/* Miscellaneous helpers */ + +static bool is_in_list(const char *name, const char *const *v) +{ + while (*v) + { + if (strcmp(*v, name) == 0) + return true; + v++; + } + return false; +} + +static const char *const editable_files[] = { + FILENAME_COMMENT , + FILENAME_BACKTRACE, + NULL +}; +static bool is_editable_file(const char *file_name) +{ + return is_in_list(file_name, editable_files); +} + +static const char *const always_text_files[] = { + FILENAME_CMDLINE , + FILENAME_BACKTRACE, + NULL +}; +static char* is_text_file(const char *name, ssize_t *sz) +{ + /* We were using magic.h API to check for file being text, but it thinks + * that file containing just "0" is not text (!!) + * So, we do it ourself. + */ + + int fd = open(name, O_RDONLY); + if (fd < 0) + return NULL; /* it's not text (because it does not exist! :) */ + + /* Maybe 64k limit is small. But _some_ limit is necessary: + * fields declared "text" may end up in editing fields and such. + * We don't want to accidentally end up with 100meg text in a textbox! + * So, don't remove this. If you really need to, raise the limit. + * + * Bumped up to 200k: saw 124740 byte /proc/PID/smaps file + */ + off_t size = lseek(fd, 0, SEEK_END); + if (size < 0 || size > 200*1024) + { + close(fd); + return NULL; /* it's not a SMALL text */ + } + lseek(fd, 0, SEEK_SET); + + char *buf = (char*)xmalloc(*sz); + ssize_t r = full_read(fd, buf, *sz); + close(fd); + if (r < 0) + { + free(buf); + return NULL; /* it's not text (because we can't read it) */ + } + if (r < *sz) + buf[r] = '\0'; + *sz = r; + + /* Some files in our dump directories are known to always be textual */ + const char *base = strrchr(name, '/'); + if (base) + { + base++; + if (is_in_list(base, always_text_files)) + return buf; + } + + /* Every once in a while, even a text file contains a few garbled + * or unexpected non-ASCII chars. We should not declare it "binary". + */ + const unsigned RATIO = 50; + unsigned total_chars = r + RATIO; + unsigned bad_chars = 1; /* 1 prevents division by 0 later */ + while (--r >= 0) + { + if (buf[r] >= 0x7f + /* among control chars, only '\t','\n' etc are allowed */ + || (buf[r] < ' ' && !isspace(buf[r])) + ) { + if (buf[r] == '\0') + { + /* We don't like NULs very much. Not text for sure! */ + free(buf); + return NULL; + } + bad_chars++; + } + } + + if ((total_chars / bad_chars) >= RATIO) + return buf; /* looks like text to me */ + + free(buf); + return NULL; /* it's binary */ +} + +void load_problem_data_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd) +{ + char *short_name; + char *full_name; + + dd_init_next_file(dd); + while (dd_get_next_file(dd, &short_name, &full_name)) + { + ssize_t sz = 4*1024; + char *text = NULL; + bool editable = is_editable_file(short_name); + + if (!editable) + { + text = is_text_file(full_name, &sz); + if (!text) + { + add_to_problem_data_ext(problem_data, + short_name, + full_name, + CD_FLAG_BIN + CD_FLAG_ISNOTEDITABLE + ); + free(short_name); + free(full_name); + continue; + } + } + + char *content; + if (sz < 4*1024) /* did is_text_file read entire file? */ + { + content = text; + /* Strip '\n' from one-line elements: */ + char *nl = strchr(content, '\n'); + if (nl && nl[1] == '\0') + *nl = '\0'; + } + else + { + /* no, need to read it all */ + free(text); + content = dd_load_text(dd, short_name); + } + + int flags = 0; + + if (editable) + flags |= CD_FLAG_TXT | CD_FLAG_ISEDITABLE; + else + flags |= CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE; + + static const char *const list_files[] = { + FILENAME_UID , + FILENAME_PACKAGE , + FILENAME_EXECUTABLE, + FILENAME_TIME , + FILENAME_COUNT , + NULL + }; + if (is_in_list(short_name, list_files)) + flags |= CD_FLAG_LIST; + + if (strcmp(short_name, FILENAME_TIME) == 0) + flags |= CD_FLAG_UNIXTIME; + + add_to_problem_data_ext(problem_data, + short_name, + content, + flags + ); + free(short_name); + free(full_name); + free(content); + } +} + +problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd) +{ + problem_data_t *problem_data = new_problem_data(); + load_problem_data_from_dump_dir(problem_data, dd); + return problem_data; +} + +void log_problem_data(problem_data_t *problem_data, const char *pfx) +{ + GHashTableIter iter; + char *name; + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) + { + log("%s[%s]:'%s' 0x%x", + pfx, name, + value->content, + value->flags + ); + } +} diff --git a/src/lib/run_event.c b/src/lib/run_event.c index 08711ea0..e577c383 100644 --- a/src/lib/run_event.c +++ b/src/lib/run_event.c @@ -339,11 +339,11 @@ int run_event_on_dir_name(struct run_event_state *state, return retval; } -int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, const char *event) +int run_event_on_problem_data(struct run_event_state *state, problem_data_t *data, const char *event) { state->children_count = 0; - struct dump_dir *dd = create_dump_dir_from_crash_data(data, NULL); + struct dump_dir *dd = create_dump_dir_from_problem_data(data, NULL); if (!dd) return -1; char *dir_name = xstrdup(dd->dd_dirname); @@ -356,7 +356,7 @@ int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, c free(dir_name); if (dd) { - load_crash_data_from_dump_dir(data, dd); + load_problem_data_from_dump_dir(data, dd); dd_delete(dd); } return r; diff --git a/src/plugins/Upload.conf b/src/plugins/Upload.conf index 696a7bd4..803b0ac8 100644 --- a/src/plugins/Upload.conf +++ b/src/plugins/Upload.conf @@ -1,4 +1,4 @@ -# Description: Packs crash data into .tar.gz file and uploads it via FTP/SCP/etc +# Description: Packs problem data into .tar.gz file and uploads it via FTP/SCP/etc # URL to upload the files to. # supported: ftp, ftps, http, https, scp, sftp, tftp, file diff --git a/src/plugins/abrt-Bugzilla.7 b/src/plugins/abrt-Bugzilla.7 index 99bb60d1..708695c7 100644 --- a/src/plugins/abrt-Bugzilla.7 +++ b/src/plugins/abrt-Bugzilla.7 @@ -5,13 +5,13 @@ Bugzilla plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the problem data and takes action according to its configuration. This manual page describes the \fIBugzilla\fP plugin for \fIabrt\fP. .P This plugin is used to report the crash to a Bugzilla instance. The plugin will determine the package name and distribution version. The -crash data is attached to the bug report. +problem data is attached to the bug report. .SH INVOCATION The plugin is invoked in the \fIabrt.conf\fP configuration file. No parameters are necessary. diff --git a/src/plugins/abrt-KerneloopsReporter.7 b/src/plugins/abrt-KerneloopsReporter.7 index 98bd3874..cec492f1 100644 --- a/src/plugins/abrt-KerneloopsReporter.7 +++ b/src/plugins/abrt-KerneloopsReporter.7 @@ -5,7 +5,7 @@ KerneloopsReporter plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the problem data and takes action according to its configuration. This manual page describes the \fIKerneloopsReporter\fP plugin for \fIabrt\fP. .P diff --git a/src/plugins/abrt-Logger.7 b/src/plugins/abrt-Logger.7 index 8ae679f8..a9fbae09 100644 --- a/src/plugins/abrt-Logger.7 +++ b/src/plugins/abrt-Logger.7 @@ -5,7 +5,7 @@ Logger plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the problem data and takes action according to its configuration. This manual page describes the \fILogger\fP plugin for \fIabrt\fP. .P diff --git a/src/plugins/abrt-Mailx.7 b/src/plugins/abrt-Mailx.7 index 90a8bbce..1f2f08fc 100644 --- a/src/plugins/abrt-Mailx.7 +++ b/src/plugins/abrt-Mailx.7 @@ -5,7 +5,7 @@ Mailx plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the problem data and takes action according to its configuration. This manual page describes the \fIMailx\fP plugin for \fIabrt\fP. .P diff --git a/src/plugins/abrt-Upload.7 b/src/plugins/abrt-Upload.7 index 7d4ee57f..4f39b361 100644 --- a/src/plugins/abrt-Upload.7 +++ b/src/plugins/abrt-Upload.7 @@ -5,7 +5,7 @@ Upload plugin for abrt(8) .P .I abrt is a daemon which watches for application crashes. When a crash occurs, -it collects the crash data and performs some actions according to +it collects the problem data and performs some actions according to the configuration. This manual page describes the \fIUpload\fP plugin for \fIabrt\fP. .P diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 95aad861..d0281ce7 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -18,7 +18,7 @@ */ #include "abrtlib.h" #include "abrt_xmlrpc.h" -#include "abrt_crash_data.h" +#include "abrt_problem_data.h" #include "parse_options.h" #define PROGNAME "abrt-action-bugzilla" @@ -96,8 +96,8 @@ struct ctx: public abrt_xmlrpc_conn { xmlrpc_int32 get_bug_dup_id(xmlrpc_value* result_xml); void get_bug_cc(xmlrpc_value* result_xml, struct bug_info* bz); int add_plus_one_cc(xmlrpc_int32 bug_id, const char* login); - xmlrpc_int32 new_bug(crash_data_t *crash_data, int depend_on_bugno); - int add_attachments(const char* bug_id_str, crash_data_t *crash_data); + xmlrpc_int32 new_bug(problem_data_t *problem_data, int depend_on_bugno); + int add_attachments(const char* bug_id_str, problem_data_t *problem_data); int get_bug_info(struct bug_info* bz, xmlrpc_int32 bug_id); int add_comment(xmlrpc_int32 bug_id, const char* comment, bool is_private); @@ -426,19 +426,19 @@ static const char *tainted_string(unsigned tainted) return taint_warnings[idx]; } -xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) +xmlrpc_int32 ctx::new_bug(problem_data_t *problem_data, int depend_on_bugno) { - const char *package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); - const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); - const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); + const char *package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE); + const char *component = get_problem_item_content_or_NULL(problem_data, FILENAME_COMPONENT); + const char *release = get_problem_item_content_or_NULL(problem_data, FILENAME_OS_RELEASE); if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */ - release = get_crash_item_content_or_NULL(crash_data, "release"); - const char *arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); - const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); - const char *reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); - const char *function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); - const char *analyzer = get_crash_item_content_or_NULL(crash_data, FILENAME_ANALYZER); - const char *tainted_str = get_crash_item_content_or_NULL(crash_data, FILENAME_TAINTED); + release = get_problem_item_content_or_NULL(problem_data, "release"); + const char *arch = get_problem_item_content_or_NULL(problem_data, FILENAME_ARCHITECTURE); + const char *duphash = get_problem_item_content_or_NULL(problem_data, FILENAME_DUPHASH); + const char *reason = get_problem_item_content_or_NULL(problem_data, FILENAME_REASON); + const char *function = get_problem_item_content_or_NULL(problem_data, FILENAME_CRASH_FUNCTION); + const char *analyzer = get_problem_item_content_or_NULL(problem_data, FILENAME_ANALYZER); + const char *tainted_str = get_problem_item_content_or_NULL(problem_data, FILENAME_TAINTED); struct strbuf *buf_summary = strbuf_new(); strbuf_append_strf(buf_summary, "[abrt] %s", package); @@ -460,7 +460,7 @@ xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) char *status_whiteboard = xasprintf("abrt_hash:%s", duphash); - char *bz_dsc = make_description_bz(crash_data); + char *bz_dsc = make_description_bz(problem_data); char *full_dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); free(bz_dsc); @@ -520,12 +520,12 @@ xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) return bug_id; } -int ctx::add_attachments(const char* bug_id_str, crash_data_t *crash_data) +int ctx::add_attachments(const char* bug_id_str, problem_data_t *problem_data) { GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { const char *content = value->content; @@ -629,7 +629,7 @@ static void report_to_bugzilla( struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) xfunc_die(); /* dd_opendir already emitted error msg */ - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); const char *env; @@ -655,8 +655,8 @@ static void report_to_bugzilla( env = getenv("Bugzilla_SSLVerify"); ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); - const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); - const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); + const char *component = get_problem_item_content_or_NULL(problem_data, FILENAME_COMPONENT); + const char *duphash = get_problem_item_content_or_NULL(problem_data, FILENAME_DUPHASH); if (!duphash) error_msg_and_die(_("Essential file '%s' is missing, can't continue.."), FILENAME_DUPHASH); @@ -665,9 +665,9 @@ static void report_to_bugzilla( error_msg_and_die(_("Essential file '%s' is empty, can't continue.."), FILENAME_DUPHASH); - const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); + const char *release = get_problem_item_content_or_NULL(problem_data, FILENAME_OS_RELEASE); if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */ - release = get_crash_item_content_or_NULL(crash_data, "release"); + release = get_problem_item_content_or_NULL(problem_data, "release"); ctx bz_server(bugzilla_xmlrpc, ssl_verify); @@ -764,7 +764,7 @@ static void report_to_bugzilla( else if (all_bugs_size == 0) // Create new bug { log(_("Creating a new bug")); - bug_id = bz_server.new_bug(crash_data, depend_on_bugno); + bug_id = bz_server.new_bug(problem_data, depend_on_bugno); if (bug_id < 0) { throw_if_xml_fault_occurred(&bz_server.env); @@ -774,7 +774,7 @@ static void report_to_bugzilla( log("Adding attachments to bug %ld", (long)bug_id); char bug_id_str[sizeof(long)*3 + 2]; sprintf(bug_id_str, "%ld", (long) bug_id); - int ret = bz_server.add_attachments(bug_id_str, crash_data); + int ret = bz_server.add_attachments(bug_id_str, problem_data); if (ret == -1) { throw_if_xml_fault_occurred(&bz_server.env); @@ -849,15 +849,15 @@ static void report_to_bugzilla( throw_if_xml_fault_occurred(&bz_server.env); } - char *dsc = make_description_comment(crash_data); + char *dsc = make_description_comment(problem_data); if (dsc) { - const char* package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); - const char* release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); + const char* package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE); + const char* release = get_problem_item_content_or_NULL(problem_data, FILENAME_OS_RELEASE); if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */ - release = get_crash_item_content_or_NULL(crash_data, "release"); - const char* arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); - const char* is_private = get_crash_item_content_or_NULL(crash_data, "is_private"); + release = get_problem_item_content_or_NULL(problem_data, "release"); + const char* arch = get_problem_item_content_or_NULL(problem_data, FILENAME_ARCHITECTURE); + const char* is_private = get_problem_item_content_or_NULL(problem_data, "is_private"); char *full_dsc = xasprintf("Package: %s\n" "Architecture: %s\n" @@ -900,7 +900,7 @@ static void report_to_bugzilla( dd_close(dd); } - free_crash_data(crash_data); + free_problem_data(problem_data); bug_info_destroy(&bz); } diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index e9d3a574..7b054a2e 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -90,10 +90,10 @@ static void report_to_kerneloops( if (!dd) exit(1); /* error msg is already logged */ - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); - const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); + const char *backtrace = get_problem_item_content_or_NULL(problem_data, FILENAME_BACKTRACE); if (!backtrace) error_msg_and_die("Error sending kernel oops due to missing backtrace"); @@ -108,7 +108,7 @@ static void report_to_kerneloops( if (ret != CURLE_OK) error_msg_and_die("Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); - free_crash_data(crash_data); + free_problem_data(problem_data); /* Server replies with: * 200 thank you for submitting the kernel oops information diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index 2efaad5c..a4ee31cd 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -65,7 +65,7 @@ static void create_and_send_email( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); char* env; @@ -82,14 +82,14 @@ static void create_and_send_email( unsigned arg_size = 0; args = append_str_to_vector(args, &arg_size, "/bin/mailx"); - char *dsc = make_description_mailx(crash_data); + char *dsc = make_description_mailx(problem_data); if (send_binary_data) { GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { if (value->flags & CD_FLAG_BIN) @@ -116,7 +116,7 @@ static void create_and_send_email( args -= arg_size; free(args); - free_crash_data(crash_data); + free_problem_data(problem_data); dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 4ca0be0b..1fbdf35a 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -76,13 +76,13 @@ int main(int argc, char **argv) if (!dd) return 1; /* error message is already logged */ - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); - char *dsc = make_description_logger(crash_data); + char *dsc = make_description_logger(problem_data); fputs(dsc, stdout); free(dsc); - free_crash_data(crash_data); + free_problem_data(problem_data); if (output_file) { diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index df698ff0..fbdc7f7e 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -34,7 +34,7 @@ static void report_to_rhtsupport( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + problem_data_t *problem_data = create_problem_data_from_dump_dir(dd); dd_close(dd); /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ @@ -66,7 +66,7 @@ static void report_to_rhtsupport( if (!login[0] || !password[0]) { - free_crash_data(crash_data); + free_problem_data(problem_data); free(url); free(login); free(password); @@ -74,9 +74,9 @@ static void report_to_rhtsupport( return; } - package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); - reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); - function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); + package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE); + reason = get_problem_item_content_or_NULL(problem_data, FILENAME_REASON); + function = get_problem_item_content_or_NULL(problem_data, FILENAME_CRASH_FUNCTION); { struct strbuf *buf_summary = strbuf_new(); @@ -87,7 +87,7 @@ static void report_to_rhtsupport( strbuf_append_strf(buf_summary, ": %s", reason); summary = strbuf_free_nobuf(buf_summary); - char *bz_dsc = make_description_bz(crash_data); + char *bz_dsc = make_description_bz(problem_data); dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); free(bz_dsc); } @@ -126,8 +126,8 @@ static void report_to_rhtsupport( { GHashTableIter iter; char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); + struct problem_item *value; + g_hash_table_iter_init(&iter, problem_data); while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { if (strcmp(name, FILENAME_COUNT) == 0) continue; @@ -258,7 +258,7 @@ static void report_to_rhtsupport( free(url); free(login); free(password); - free_crash_data(crash_data); + free_problem_data(problem_data); if (errmsg) error_msg_and_die("%s", errmsg); diff --git a/src/plugins/abrt-plugins.7 b/src/plugins/abrt-plugins.7 index d8027057..52641fd7 100644 --- a/src/plugins/abrt-plugins.7 +++ b/src/plugins/abrt-plugins.7 @@ -5,7 +5,7 @@ abrt-plugins \- plugins for the abrt crash reporter program .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data (core file, application's command line etc.) +it collects the problem data (core file, application's command line etc.) and takes action according to the type of application that crashed and according to the configuration specified in the .I abrt.conf diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am index 94dc3abb..c7b2dd67 100644 --- a/src/report-python/Makefile.am +++ b/src/report-python/Makefile.am @@ -8,7 +8,7 @@ pyreportexec_LTLIBRARIES = _pyreport.la _pyreport_la_SOURCES = \ reportmodule.c \ - crash_data.c \ + problem_data.c \ dump_dir.c \ run_event.c \ common.h diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py index 0b0f5685..1e87dc47 100644 --- a/src/report-python/__init__.py +++ b/src/report-python/__init__.py @@ -108,7 +108,7 @@ def createAlertSignature(component, hashmarkername, hashvalue, summary, alertSig #### return version return _hardcoded_default_version - cd = crash_data() + cd = problem_data() cd.add("component", component) cd.add("hashmarkername", hashmarkername) cd.add("localhash", hashvalue) @@ -126,5 +126,5 @@ def report(cd, io_unused): ### Silmpler alternative: state = run_event_state() #state.logging_callback = logfunc - r = state.run_event_on_crash_data(cd, "report") + r = state.run_event_on_problem_data(cd, "report") return r diff --git a/src/report-python/common.h b/src/report-python/common.h index d6d209e9..c94e8d90 100644 --- a/src/report-python/common.h +++ b/src/report-python/common.h @@ -19,14 +19,14 @@ #include #include "dump_dir.h" -#include "crash_data.h" +#include "problem_data.h" #include "run_event.h" /* exception object */ extern PyObject *ReportError; /* type objects */ -extern PyTypeObject p_crash_data_type; +extern PyTypeObject p_problem_data_type; extern PyTypeObject p_dump_dir_type; extern PyTypeObject p_run_event_state_type; @@ -43,5 +43,5 @@ typedef struct { typedef struct { PyObject_HEAD - crash_data_t *cd; -} p_crash_data; + problem_data_t *cd; +} p_problem_data; diff --git a/src/report-python/crash_data.c b/src/report-python/crash_data.c deleted file mode 100644 index 217560e5..00000000 --- a/src/report-python/crash_data.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - 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. -*/ -#include -#include - -#include -#include "common.h" - -static void -p_crash_data_dealloc(PyObject *pself) -{ - p_crash_data *self = (p_crash_data*)pself; - free_crash_data(self->cd); - self->cd = NULL; - self->ob_type->tp_free(pself); -} - -static PyObject * -p_crash_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - p_crash_data *self = (p_crash_data *)type->tp_alloc(type, 0); - if (self) - self->cd = new_crash_data(); - return (PyObject *)self; -} - -//static int -//p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds) -//{ -// return 0; -//} - -/* -void add_to_crash_data_ext(crash_data_t *crash_data, - const char *name, - const char *content, - unsigned flags); -*/ -static PyObject *p_crash_data_add(PyObject *pself, PyObject *args) -{ - p_crash_data *self = (p_crash_data*)pself; - - const char *name; - const char *content; - int flags = 0; - if (!PyArg_ParseTuple(args, "ss|i", &name, &content, &flags)) - { - /* PyArg_ParseTuple raises the exception saying why it fails - * eg: TypeError: function takes exactly 2 arguments (1 given) - */ - return NULL; - } - add_to_crash_data_ext(self->cd, name, content, flags); - - /* every function returns PyObject, to return void we need to do this */ - Py_RETURN_NONE; -} - -/* struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key); */ -static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) -{ - p_crash_data *self = (p_crash_data*)pself; - const char *key; - if (!PyArg_ParseTuple(args, "s", &key)) - { - return NULL; - } - struct crash_item *ci = get_crash_data_item_or_NULL(self->cd, key); - if (ci == NULL) - { - Py_RETURN_NONE; - } - return Py_BuildValue("sI", ci->content, ci->flags); -} - -/* struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const char *base_dir_name); */ -static PyObject *p_create_dump_dir_from_crash_data(PyObject *pself, PyObject *args) -{ - p_crash_data *self = (p_crash_data*)pself; - const char *base_dir_name = NULL; - if (!PyArg_ParseTuple(args, "|s", &base_dir_name)) - { - return NULL; - } - p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type); - if (!new_dd) - return NULL; - struct dump_dir *dd = create_dump_dir_from_crash_data(self->cd, base_dir_name); - if (!dd) - { - PyObject_Del((PyObject*)new_dd); - PyErr_SetString(ReportError, "Can't create the dump dir"); - return NULL; - } - new_dd->dd = dd; - return (PyObject*)new_dd; -} - -//static PyMemberDef p_crash_data_members[] = { -// { NULL } -//}; - -static PyMethodDef p_crash_data_methods[] = { - /* method_name, func, flags, doc_string */ - { "add" , p_crash_data_add , METH_VARARGS }, - { "get" , p_get_crash_data_item , METH_VARARGS }, - { "create_dump_dir", p_create_dump_dir_from_crash_data, METH_VARARGS }, - { NULL } -}; - -PyTypeObject p_crash_data_type = { - PyObject_HEAD_INIT(NULL) - .tp_name = "report.crash_data", - .tp_basicsize = sizeof(p_crash_data), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_new = p_crash_data_new, - .tp_dealloc = p_crash_data_dealloc, - //.tp_init = p_crash_data_init, - //.tp_members = p_crash_data_members, - .tp_methods = p_crash_data_methods, -}; diff --git a/src/report-python/dump_dir.c b/src/report-python/dump_dir.c index c34cc869..e14e68d2 100644 --- a/src/report-python/dump_dir.c +++ b/src/report-python/dump_dir.c @@ -1,5 +1,5 @@ /* - On-disk storage of crash dumps + On-disk storage of problem data Copyright (C) 2010 Abrt team Copyright (C) 2010 RedHat inc. diff --git a/src/report-python/problem_data.c b/src/report-python/problem_data.c new file mode 100644 index 00000000..ac80362a --- /dev/null +++ b/src/report-python/problem_data.c @@ -0,0 +1,137 @@ +/* + 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. +*/ +#include +#include + +#include +#include "common.h" + +static void +p_problem_data_dealloc(PyObject *pself) +{ + p_problem_data *self = (p_problem_data*)pself; + free_problem_data(self->cd); + self->cd = NULL; + self->ob_type->tp_free(pself); +} + +static PyObject * +p_problem_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + p_problem_data *self = (p_problem_data *)type->tp_alloc(type, 0); + if (self) + self->cd = new_problem_data(); + return (PyObject *)self; +} + +//static int +//p_problem_data_init(PyObject *pself, PyObject *args, PyObject *kwds) +//{ +// return 0; +//} + +/* +void add_to_problem_data_ext(problem_data_t *problem_data, + const char *name, + const char *content, + unsigned flags); +*/ +static PyObject *p_problem_data_add(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + + const char *name; + const char *content; + int flags = 0; + if (!PyArg_ParseTuple(args, "ss|i", &name, &content, &flags)) + { + /* PyArg_ParseTuple raises the exception saying why it fails + * eg: TypeError: function takes exactly 2 arguments (1 given) + */ + return NULL; + } + add_to_problem_data_ext(self->cd, name, content, flags); + + /* every function returns PyObject, to return void we need to do this */ + Py_RETURN_NONE; +} + +/* struct problem_item *get_problem_data_item_or_NULL(problem_data_t *problem_data, const char *key); */ +static PyObject *p_get_problem_data_item(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + const char *key; + if (!PyArg_ParseTuple(args, "s", &key)) + { + return NULL; + } + struct problem_item *ci = get_problem_data_item_or_NULL(self->cd, key); + if (ci == NULL) + { + Py_RETURN_NONE; + } + return Py_BuildValue("sI", ci->content, ci->flags); +} + +/* struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name); */ +static PyObject *p_create_dump_dir_from_problem_data(PyObject *pself, PyObject *args) +{ + p_problem_data *self = (p_problem_data*)pself; + const char *base_dir_name = NULL; + if (!PyArg_ParseTuple(args, "|s", &base_dir_name)) + { + return NULL; + } + p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type); + if (!new_dd) + return NULL; + struct dump_dir *dd = create_dump_dir_from_problem_data(self->cd, base_dir_name); + if (!dd) + { + PyObject_Del((PyObject*)new_dd); + PyErr_SetString(ReportError, "Can't create the dump dir"); + return NULL; + } + new_dd->dd = dd; + return (PyObject*)new_dd; +} + +//static PyMemberDef p_problem_data_members[] = { +// { NULL } +//}; + +static PyMethodDef p_problem_data_methods[] = { + /* method_name, func, flags, doc_string */ + { "add" , p_problem_data_add , METH_VARARGS }, + { "get" , p_get_problem_data_item , METH_VARARGS }, + { "create_dump_dir", p_create_dump_dir_from_problem_data, METH_VARARGS }, + { NULL } +}; + +PyTypeObject p_problem_data_type = { + PyObject_HEAD_INIT(NULL) + .tp_name = "report.problem_data", + .tp_basicsize = sizeof(p_problem_data), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_new = p_problem_data_new, + .tp_dealloc = p_problem_data_dealloc, + //.tp_init = p_problem_data_init, + //.tp_members = p_problem_data_members, + .tp_methods = p_problem_data_methods, +}; diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c index a684984e..c40cfaf6 100644 --- a/src/report-python/reportmodule.c +++ b/src/report-python/reportmodule.c @@ -36,9 +36,9 @@ static PyMethodDef module_methods[] = { PyMODINIT_FUNC init_pyreport(void) { - if (PyType_Ready(&p_crash_data_type) < 0) + if (PyType_Ready(&p_problem_data_type) < 0) { - printf("PyType_Ready(&p_crash_data_type) < 0\n"); + printf("PyType_Ready(&p_problem_data_type) < 0\n"); return; } if (PyType_Ready(&p_dump_dir_type) < 0) @@ -66,8 +66,8 @@ init_pyreport(void) PyModule_AddObject(m, "error", ReportError); /* init type objects */ - Py_INCREF(&p_crash_data_type); - PyModule_AddObject(m, "crash_data", (PyObject *)&p_crash_data_type); + Py_INCREF(&p_problem_data_type); + PyModule_AddObject(m, "problem_data", (PyObject *)&p_problem_data_type); PyModule_AddObject(m, "CD_FLAG_BIN" , Py_BuildValue("i", CD_FLAG_BIN )); PyModule_AddObject(m, "CD_FLAG_TXT" , Py_BuildValue("i", CD_FLAG_TXT )); PyModule_AddObject(m, "CD_FLAG_ISEDITABLE" , Py_BuildValue("i", CD_FLAG_ISEDITABLE )); diff --git a/src/report-python/run_event.c b/src/report-python/run_event.c index 684c7fc7..50e3794e 100644 --- a/src/report-python/run_event.c +++ b/src/report-python/run_event.c @@ -21,7 +21,7 @@ #include #include "common.h" -#include "crash_data.h" +#include "problem_data.h" #include "run_event.h" typedef struct { @@ -110,17 +110,17 @@ static PyObject *p_run_event_on_dir_name(PyObject *pself, PyObject *args) return obj; } -/* int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, const char *event); */ -static PyObject *p_run_event_on_crash_data(PyObject *pself, PyObject *args) +/* int run_event_on_problem_data(struct run_event_state *state, problem_data_t *data, const char *event); */ +static PyObject *p_run_event_on_problem_data(PyObject *pself, PyObject *args) { p_run_event_state *self = (p_run_event_state*)pself; - p_crash_data *cd; + p_problem_data *cd; const char *event; - if (!PyArg_ParseTuple(args, "O!s", &p_crash_data_type, &cd, &event)) + if (!PyArg_ParseTuple(args, "O!s", &p_problem_data_type, &cd, &event)) { return NULL; } - int r = run_event_on_crash_data(self->state, cd->cd, event); + int r = run_event_on_problem_data(self->state, cd->cd, event); PyObject *obj = Py_BuildValue("i", r); return obj; } @@ -194,7 +194,7 @@ static int set_logging_callback(PyObject *pself, PyObject *callback, void *unuse static PyMethodDef p_run_event_state_methods[] = { /* method_name, func, flags, doc_string */ { "run_event_on_dir_name" , p_run_event_on_dir_name , METH_VARARGS }, - { "run_event_on_crash_data", p_run_event_on_crash_data, METH_VARARGS }, + { "run_event_on_problem_data", p_run_event_on_problem_data, METH_VARARGS }, { NULL } }; diff --git a/src/report-python/test_crash_data b/src/report-python/test_crash_data deleted file mode 100755 index 6f719a8f..00000000 --- a/src/report-python/test_crash_data +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python - -from report import * - -cd = crash_data() -cd.add("foo", "bar") - -dd = cd.create_dump_dir() - -if dd: - print "dd is nonzero" -else: - print "dd is zero" - -print "closing" -dd.close() - -if dd: - print "dd is nonzero" -else: - print "dd is zero" diff --git a/src/report-python/test_crash_data2 b/src/report-python/test_crash_data2 deleted file mode 100755 index 2594f863..00000000 --- a/src/report-python/test_crash_data2 +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/python - -from report import * - -cd = crash_data() -cd.add("foo", "bar") - -print "foo:", cd.get("foo") -print "nonexistent:", cd.get("nonexistent") -print "done" diff --git a/src/report-python/test_full b/src/report-python/test_full index 103535dd..107c4857 100755 --- a/src/report-python/test_full +++ b/src/report-python/test_full @@ -3,7 +3,7 @@ import sys from report import * -def run_event_on_crash_data(cd, event, log_function = None): +def run_event_on_problem_data(cd, event, log_function = None): dd = cd.create_dump_dir("/tmp") dir_name = dd.name print "Created dump_dir:", dir_name @@ -20,8 +20,8 @@ def run_event_on_crash_data(cd, event, log_function = None): def log_function(line): print "LOG:", line -cd = crash_data() +cd = problem_data() cd.add("foo", "bar") cd.add("analyzer", "baz", CD_FLAG_ISNOTEDITABLE) -r = run_event_on_crash_data(cd, "post-create", log_function) +r = run_event_on_problem_data(cd, "post-create", log_function) print "Result:", r diff --git a/src/report-python/test_full2 b/src/report-python/test_full2 index 734946eb..e6cfd4d9 100755 --- a/src/report-python/test_full2 +++ b/src/report-python/test_full2 @@ -6,12 +6,12 @@ from report import * def log_function(line): print "LOG:", line -cd = crash_data() +cd = problem_data() cd.add("foo", "bar") cd.add("analyzer", "baz", CD_FLAG_ISNOTEDITABLE) st = run_event_state() st.logging_callback = log_function -r = st.run_event_on_crash_data(cd, "post-create") +r = st.run_event_on_problem_data(cd, "post-create") print "Result:", r diff --git a/src/report-python/test_problem_data b/src/report-python/test_problem_data new file mode 100644 index 00000000..16f1f9ae --- /dev/null +++ b/src/report-python/test_problem_data @@ -0,0 +1,21 @@ +#!/usr/bin/python + +from report import * + +cd = problem_data() +cd.add("foo", "bar") + +dd = cd.create_dump_dir() + +if dd: + print "dd is nonzero" +else: + print "dd is zero" + +print "closing" +dd.close() + +if dd: + print "dd is nonzero" +else: + print "dd is zero" diff --git a/src/report-python/test_problem_data2 b/src/report-python/test_problem_data2 new file mode 100644 index 00000000..3d3692b9 --- /dev/null +++ b/src/report-python/test_problem_data2 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +from report import * + +cd = problem_data() +cd.add("foo", "bar") + +print "foo:", cd.get("foo") +print "nonexistent:", cd.get("nonexistent") +print "done" diff --git a/src/report-python/test_setroubleshoot_example2 b/src/report-python/test_setroubleshoot_example2 index 8aebcdfe..b712cda7 100755 --- a/src/report-python/test_setroubleshoot_example2 +++ b/src/report-python/test_setroubleshoot_example2 @@ -22,6 +22,6 @@ def logging_callback(line): return state = report.run_event_state() state.logging_callback = logging_callback -rc = state.run_event_on_crash_data(signature, "report") +rc = state.run_event_on_problem_data(signature, "report") print "rc:", rc -- cgit