From b808fc36602756d1c1495179331a4e92a7b094dc Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Wed, 1 Dec 2010 14:55:33 +0100 Subject: get_reporter_plugin_settings() returns GHashTable static void get_reporter_plugin_settings(const vector_string_t& reporters, map_map_string_t &settings) a new interface is static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters) Signed-off-by: Nikola Pajkovsky --- src/cli/report.cpp | 55 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 78a38916..3f2a4902 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -502,24 +502,35 @@ static bool set_echo(bool enabled) return true; } +static void free_map_string_t(gpointer data) +{ + delete (map_string_t *)data; +} + /** * Gets reporter plugin settings. * @param reporters * List of reporter names. Settings of these reporters are handled. - * @param settings + * @return settings * A structure filled with reporter plugin settings. + * It's GHashTable and must be passed to + * g_hash_table_destroy(); */ -static void get_reporter_plugin_settings(const vector_string_t& reporters, - map_map_string_t &settings) +static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters) { /* First of all, load system-wide report plugin settings. */ + GHashTable *settings = g_hash_table_new_full(g_str_hash, g_str_equal, + free, free_map_string_t); + for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) { - map_string_t single_plugin_settings = call_GetPluginSettings(it->c_str()); + map_string_t *single_plugin_settings = new map_string_t; + *single_plugin_settings = call_GetPluginSettings(it->c_str()); + // Copy the received settings as defaults. // Plugins won't work without it, if some value is missing // they use their default values for all fields. - settings[it->c_str()] = single_plugin_settings; + g_hash_table_insert(settings, xstrdup(it->c_str()), (void*)single_plugin_settings); } /* Second, load user-specific settings, which override @@ -528,24 +539,30 @@ static void get_reporter_plugin_settings(const vector_string_t& reporters, const char* homedir = pw ? pw->pw_dir : NULL; if (homedir) { - map_map_string_t::const_iterator itend = settings.end(); - for (map_map_string_t::iterator it = settings.begin(); it != itend; ++it) + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, settings); + while (g_hash_table_iter_next (&iter, &key, &value)) { map_string_t single_plugin_settings; - std::string path = std::string(homedir) + "/.abrt/" - + it->first + ".conf"; + + char *path = xasprintf("%s/.abrt/%s.conf", homedir, (char *)key); + /* Load plugin config in the home dir. Do not skip lines with empty value (but containing a "key="), because user may want to override password from /etc/abrt/plugins/*.conf, but he prefers to enter it every time he reports. */ - bool success = LoadPluginSettings(path.c_str(), single_plugin_settings, false); + bool success = LoadPluginSettings(path, single_plugin_settings, false); + free(path); if (!success) continue; // Merge user's plugin settings into already loaded settings. map_string_t::const_iterator valit, valitend = single_plugin_settings.end(); for (valit = single_plugin_settings.begin(); valit != valitend; ++valit) - it->second[valit->first] = valit->second; + (*(map_string_t*)value)[valit->first] = valit->second; } } + return settings; } /** @@ -628,8 +645,7 @@ int report(const char *crash_id, int flags) } /* Get settings */ - map_map_string_t reporters_settings; - get_reporter_plugin_settings(reporters, reporters_settings); + GHashTable *reporters_settings = get_reporter_plugin_settings(reporters); int errors = 0; int plugins = 0; @@ -661,18 +677,18 @@ int report(const char *crash_id, int flags) continue; } - map_map_string_t::iterator settings = reporters_settings.find(it->c_str()); - if (settings != reporters_settings.end()) + map_string_t *settings = (map_string_t *)g_hash_table_lookup(reporters_settings, it->c_str()); + if (settings) { - map_string_t::iterator rating_setting = settings->second.find("RatingRequired"); - if (rating_setting != settings->second.end() + map_string_t::iterator rating_setting = settings->find("RatingRequired"); + if (rating_setting != settings->end() && string_to_bool(rating_setting->second.c_str()) && rating < 3) { puts(_("Reporting disabled because the backtrace is unusable")); const char *package = get_crash_data_item_content_or_NULL(cr, FILENAME_PACKAGE); - if (package[0]) + if (package && package[0]) printf(_("Please try to install debuginfo manually using the command: \"debuginfo-install %s\" and try again\n"), package); plugins++; @@ -688,7 +704,7 @@ int report(const char *crash_id, int flags) continue; } - ask_for_missing_settings(it->c_str(), settings->second); + ask_for_missing_settings(it->c_str(), *settings); vector_string_t cur_reporter(1, *it); report_status_t r = call_Report(cr, cur_reporter, reporters_settings); @@ -701,6 +717,7 @@ int report(const char *crash_id, int flags) } } + g_hash_table_destroy(reporters_settings); printf(_("Crash reported via %d report events (%d errors)\n"), plugins, errors); return errors != 0; } -- cgit From 0e2f5ab4c66a65ce5c60297cb7915c1ce1a3bd42 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 1 Dec 2010 22:03:02 +0100 Subject: GHashTable: must use g_hash_table_replace instead of _insert to not leak key Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 3f2a4902..27e12ac8 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -530,7 +530,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters // Copy the received settings as defaults. // Plugins won't work without it, if some value is missing // they use their default values for all fields. - g_hash_table_insert(settings, xstrdup(it->c_str()), (void*)single_plugin_settings); + g_hash_table_replace(settings, xstrdup(it->c_str()), (void*)single_plugin_settings); } /* Second, load user-specific settings, which override @@ -542,8 +542,8 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters GHashTableIter iter; gpointer key, value; - g_hash_table_iter_init (&iter, settings); - while (g_hash_table_iter_next (&iter, &key, &value)) + g_hash_table_iter_init(&iter, settings); + while (g_hash_table_iter_next(&iter, &key, &value)) { map_string_t single_plugin_settings; -- cgit From 3ea8cd037dcd5a8439baceadc8df70664eff701c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 3 Dec 2010 18:56:33 +0100 Subject: preparatory patch: add -v to abrt-cli; remove unused func; make func static Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 27e12ac8..88154d53 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -435,25 +435,6 @@ static void read_from_stdin(const char *question, char *result, int result_size) strchrnul(result, '\n')[0] = '\0'; } -/** Splits a string into substrings using chosen delimiters. - * @param delim - * Specifies a set of characters that delimit the - * tokens in the parsed string - */ -static GList *split(const char *s, const char delim) -{ - GList *elems = NULL; - while (1) - { - const char *end = strchrnul(s, delim); - elems = g_list_append(elems, xstrndup(s, end - s)); - if (*end == '\0') - break; - s = end + 1; - } - return elems; -} - /** * Asks a [y/n] question on stdin/stdout. * Returns true if the answer is yes, false otherwise. -- cgit From 47728cc3c70c2b6d3a645e5760b39b20bd946e39 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 6 Dec 2010 16:56:50 +0100 Subject: This patch changes crash data to use C structures. The smallest data element is: struct crash_item { char *content; unsigned flags; }; where content is, eh, content, and flags is a bit flag field. crash_data_t is a map of crash_item's, implemented as a pointer to heap-allocated GHashTable. vector_of_crash_data_t is a vector of crash_data_t's, implemented as a pointer to heap-allocated GPtrArray. Most operations have light wrappers around them to hide the nature of the containers. For example, to free vector_of_crash_data, you need to use free_vector_of_crash_data(ptr) instead of open-coding g_ptr_array_free. The wrapper is thin. The goal is not so much to hide the implementation, but more to make it easier to use the correct function. dbus (un)marshalling functions convert crash_item to three-element array of strings, in order to keep compatibility with abrt-gui (python). This can be changed later to use native representation. crash_data_t and vector_of_crash_data_t are represented in "natural" way, no funny stuff there. Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 77 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 36 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 88154d53..9ee37576 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -142,30 +142,30 @@ 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, const map_crash_data_t &report, +static void write_crash_report_field(FILE *fp, crash_data_t *crash_data, const char *field, const char *description) { - const map_crash_data_t::const_iterator it = report.find(field); - if (it == report.end()) + const struct crash_item *value = get_crash_data_item_or_NULL(crash_data, field); + if (!value) { // exit silently, all fields are optional for now //error_msg("Field %s not found", field); return; } - if (it->second[CD_TYPE] == CD_SYS) + if (value->flags & CD_FLAG_SYS) { error_msg("Cannot update field %s because it is a system value", field); return; } - fprintf(fp, "%s%s\n", FIELD_SEP, it->first.c_str()); + fprintf(fp, "%s%s\n", FIELD_SEP, field); fprintf(fp, "%s\n", description); - if (it->second[CD_EDITABLE] != CD_ISEDITABLE) + if (!(value->flags & CD_FLAG_ISEDITABLE)) fprintf(fp, _("# This field is read only\n")); - char *escaped_content = escape(it->second[CD_CONTENT].c_str()); + char *escaped_content = escape(value->content); fprintf(fp, "%s\n", escaped_content); free(escaped_content); } @@ -177,7 +177,7 @@ static void write_crash_report_field(FILE *fp, const map_crash_data_t &report, * 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(const map_crash_data_t &report, FILE *fp) +static void write_crash_report(crash_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"); @@ -208,7 +208,7 @@ static void write_crash_report(const map_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, map_crash_data_t &report, +static int read_crash_report_field(const char *text, crash_data_t *report, const char *field) { char separator[sizeof("\n" FIELD_SEP)-1 + strlen(field) + 2]; // 2 = '\n\0' @@ -225,21 +225,21 @@ static int read_crash_report_field(const char *text, map_crash_data_t &report, else length = end - textfield; - const map_crash_data_t::iterator it = report.find(field); - if (it == report.end()) + struct crash_item *value = get_crash_data_item_or_NULL(report, field); + if (!value) { error_msg("Field %s not found", field); return 0; } - if (it->second[CD_TYPE] == CD_SYS) + if (value->flags & CD_FLAG_SYS) { error_msg("Cannot update field %s because it is a system value", field); return 0; } // Do not change noneditable fields. - if (it->second[CD_EDITABLE] != CD_ISEDITABLE) + if (!(value->flags & CD_FLAG_ISEDITABLE)) return 0; // Compare the old field contents with the new field contents. @@ -248,16 +248,16 @@ static int read_crash_report_field(const char *text, map_crash_data_t &report, newvalue[length] = '\0'; trim(newvalue); - char oldvalue[it->second[CD_CONTENT].length() + 1]; - strcpy(oldvalue, it->second[CD_CONTENT].c_str()); + char oldvalue[strlen(value->content) + 1]; + strcpy(oldvalue, value->content); trim(oldvalue); // Return if no change in the contents detected. - int cmp = strcmp(newvalue, oldvalue); - if (!cmp) + if (strcmp(newvalue, oldvalue) == 0) return 0; - it->second[CD_CONTENT].assign(newvalue); + free(value->content); + value->content = xstrdup(newvalue); return 1; } @@ -269,7 +269,7 @@ static int read_crash_report_field(const char *text, map_crash_data_t &report, * 1 if any field was changed. * Changes to read-only fields are ignored. */ -static int read_crash_report(map_crash_data_t &report, const char *text) +static int read_crash_report(crash_data_t *report, const char *text) { int result = 0; result |= read_crash_report_field(text, report, FILENAME_COMMENT); @@ -292,13 +292,13 @@ static int read_crash_report(map_crash_data_t &report, const char *text) * Ensures that the fields needed for editor are present in the crash data. * Fields: comments, how to reproduce. */ -static void create_fields_for_editor(map_crash_data_t &crash_data) +static void create_fields_for_editor(crash_data_t *crash_data) { - if (crash_data.find(FILENAME_COMMENT) == crash_data.end()) - add_to_crash_data_ext(crash_data, FILENAME_COMMENT, CD_TXT, CD_ISEDITABLE, ""); + 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 (crash_data.find(FILENAME_REPRODUCE) == crash_data.end()) - add_to_crash_data_ext(crash_data, FILENAME_REPRODUCE, CD_TXT, CD_ISEDITABLE, "1. \n2. \n3. \n"); + if (!get_crash_data_item_or_NULL(crash_data, FILENAME_REPRODUCE)) + add_to_crash_data_ext(crash_data, FILENAME_REPRODUCE, "1. \n2. \n3. \n", CD_FLAG_TXT + CD_FLAG_ISEDITABLE); } /** @@ -342,7 +342,7 @@ static int launch_editor(const char *path) * 2 on failure, unable to create, open, or close temporary file * 3 on failure, cannot launch text editor */ -static int run_report_editor(map_crash_data_t &cr) +static int run_report_editor(crash_data_t *crash_data) { /* Open a temporary file and write the crash report to it. */ char filename[] = "/tmp/abrt-report.XXXXXX"; @@ -360,7 +360,7 @@ static int run_report_editor(map_crash_data_t &cr) return 2; } - write_crash_report(cr, fp); + write_crash_report(crash_data, fp); if (fclose(fp)) /* errno is set */ { @@ -405,7 +405,7 @@ static int run_report_editor(map_crash_data_t &cr) remove_comments_and_unescape(text); // Updates the crash report from the file text. - int report_changed = read_crash_report(cr, text); + int report_changed = read_crash_report(crash_data, text); free(text); if (report_changed) puts(_("\nThe report has been updated")); @@ -587,27 +587,31 @@ int report(const char *crash_id, int flags) if (flags & CLI_REPORT_SILENT_IF_NOT_FOUND) logmode = 0; // Ask for an initial report. - map_crash_data_t cr = call_CreateReport(crash_id); + crash_data_t *crash_data = call_CreateReport(crash_id); logmode = old_logmode; - if (cr.size() == 0) + if (!crash_data || g_hash_table_size(crash_data) == 0) { + free_crash_data(crash_data); return -1; } - const char *rating_str = get_crash_data_item_content_or_NULL(cr, FILENAME_RATING); + const char *rating_str = get_crash_item_content_or_NULL(crash_data, FILENAME_RATING); unsigned rating = rating_str ? xatou(rating_str) : 4; /* Open text editor and give a chance to review the backtrace etc. */ if (!(flags & CLI_REPORT_BATCH)) { - create_fields_for_editor(cr); - int result = run_report_editor(cr); + create_fields_for_editor(crash_data); + int result = run_report_editor(crash_data); if (result != 0) + { + free_crash_data(crash_data); return result; + } } /* Get possible reporters associated with this particular crash. */ - const char *events = get_crash_data_item_content_or_NULL(cr, CD_EVENTS); + const char *events = get_crash_item_content_or_NULL(crash_data, CD_EVENTS); vector_string_t reporters; if (events) while (*events) { @@ -633,7 +637,7 @@ int report(const char *crash_id, int flags) if (flags & CLI_REPORT_BATCH) { puts(_("Reporting...")); - report_status_t r = call_Report(cr, reporters, reporters_settings); + report_status_t r = call_Report(crash_data, reporters, reporters_settings); report_status_t::iterator it = r.begin(); while (it != r.end()) { @@ -668,7 +672,7 @@ int report(const char *crash_id, int flags) { puts(_("Reporting disabled because the backtrace is unusable")); - const char *package = get_crash_data_item_content_or_NULL(cr, FILENAME_PACKAGE); + const char *package = get_crash_item_content_or_NULL(crash_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); @@ -688,7 +692,7 @@ int report(const char *crash_id, int flags) ask_for_missing_settings(it->c_str(), *settings); vector_string_t cur_reporter(1, *it); - report_status_t r = call_Report(cr, cur_reporter, reporters_settings); + report_status_t r = call_Report(crash_data, cur_reporter, reporters_settings); assert(r.size() == 1); /* one reporter --> one report status */ vector_string_t &v = r.begin()->second; printf("%s: %s\n", r.begin()->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str()); @@ -699,6 +703,7 @@ int report(const char *crash_id, int flags) } g_hash_table_destroy(reporters_settings); + free_crash_data(crash_data); printf(_("Crash reported via %d report events (%d errors)\n"), plugins, errors); return errors != 0; } -- cgit From fc9639c850a341e3010465ecb0eecb7f0cd03fc9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Dec 2010 10:30:30 +0100 Subject: remove unused function parse_args; make a few functions extern "C" Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 9ee37576..4c38e852 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -505,13 +505,13 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) { - map_string_t *single_plugin_settings = new map_string_t; + map_string_t *single_plugin_settings = new map_string_t; *single_plugin_settings = call_GetPluginSettings(it->c_str()); // Copy the received settings as defaults. // Plugins won't work without it, if some value is missing // they use their default values for all fields. - g_hash_table_replace(settings, xstrdup(it->c_str()), (void*)single_plugin_settings); + g_hash_table_replace(settings, xstrdup(it->c_str()), single_plugin_settings); } /* Second, load user-specific settings, which override -- cgit From 816f3e001271ed8ab7fdadb6d90aeb2c61362dac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 14:51:47 +0100 Subject: removal of C++isms from libabrt, part 1 This patch converts libabrt usage of C++ map to a glib-based container, GHashTable. It is typedef-ed to map_string_h. We can't typedef it to map_string_t, since other parts of ABRT (daemon, cli) still use that name for C++ container. Also, exceptions are removed everywhere. Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 4c38e852..556e06b4 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -521,26 +521,35 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters if (homedir) { GHashTableIter iter; - gpointer key, value; - + char *key; + map_string_t *value; g_hash_table_iter_init(&iter, settings); - while (g_hash_table_iter_next(&iter, &key, &value)) + while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) { - map_string_t single_plugin_settings; - - char *path = xasprintf("%s/.abrt/%s.conf", homedir, (char *)key); - - /* Load plugin config in the home dir. Do not skip lines with empty value (but containing a "key="), - because user may want to override password from /etc/abrt/plugins/*.conf, but he prefers to - enter it every time he reports. */ - bool success = LoadPluginSettings(path, single_plugin_settings, false); + /* Load plugin config in the home dir. Do not skip lines + * with empty value (but containing a "key="), + * because user may want to override password + * from /etc/abrt/plugins/*.conf, but he prefers to + * enter it every time he reports. */ + map_string_h *single_plugin_settings = new_map_string(); + char *path = xasprintf("%s/.abrt/%s.conf", homedir, key); + bool success = load_conf_file(path, single_plugin_settings, /*skip key w/o values:*/ false); free(path); if (!success) + { + free_map_string(single_plugin_settings); continue; - // Merge user's plugin settings into already loaded settings. - map_string_t::const_iterator valit, valitend = single_plugin_settings.end(); - for (valit = single_plugin_settings.begin(); valit != valitend; ++valit) - (*(map_string_t*)value)[valit->first] = valit->second; + } + + /* Merge user's plugin settings into already loaded settings */ + GHashTableIter iter2; + char *key2; + char *value2; + g_hash_table_iter_init(&iter2, single_plugin_settings); + while (g_hash_table_iter_next(&iter2, (void**)&key2, (void**)&value2)) + (*value)[key2] = xstrdup(value2); + + free_map_string(single_plugin_settings); } } return settings; -- cgit From 28c588d6a86daa3d2f2bb7cdb4604d79e7dcf08b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Dec 2010 12:29:54 +0100 Subject: create report-libs-devel package; separate out report headers Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 556e06b4..f87486a7 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -356,15 +356,14 @@ static int run_report_editor(crash_data_t *crash_data) FILE *fp = fdopen(fd, "w"); if (!fp) /* errno is set */ { - perror_msg("can't open '%s' to save the crash report", filename); - return 2; + die_out_of_memory(); } write_crash_report(crash_data, fp); if (fclose(fp)) /* errno is set */ { - perror_msg("can't close '%s'", filename); + perror_msg("can't write '%s'", filename); return 2; } @@ -381,21 +380,18 @@ static int run_report_editor(crash_data_t *crash_data) } fseek(fp, 0, SEEK_END); - long size = ftell(fp); + unsigned long size = ftell(fp); fseek(fp, 0, SEEK_SET); char *text = (char*)xmalloc(size + 1); if (fread(text, 1, size, fp) != size) { error_msg("can't read '%s'", filename); + fclose(fp); return 2; } text[size] = '\0'; - if (fclose(fp) != 0) /* errno is set */ - { - perror_msg("can't close '%s'", filename); - return 2; - } + fclose(fp); // Delete the tempfile. if (unlink(filename) == -1) /* errno is set */ @@ -448,7 +444,8 @@ static bool ask_yesno(const char *question) fflush(NULL); char answer[16]; - fgets(answer, sizeof(answer), stdin); + if (!fgets(answer, sizeof(answer), stdin)) + return false; /* Use strncmp here because the answer might contain a newline as the last char. */ return 0 == strncmp(answer, yes, strlen(yes)); @@ -529,7 +526,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters /* Load plugin config in the home dir. Do not skip lines * with empty value (but containing a "key="), * because user may want to override password - * from /etc/abrt/plugins/*.conf, but he prefers to + * from /etc/abrt/plugins/foo.conf, but he prefers to * enter it every time he reports. */ map_string_h *single_plugin_settings = new_map_string(); char *path = xasprintf("%s/.abrt/%s.conf", homedir, key); -- cgit From 529935edd6733438531232b28174541ca6f92692 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 13 Dec 2010 23:08:04 +0100 Subject: small fixes to map_string_t conversion suggested by Karel Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index f87486a7..8b8f9cc6 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -518,10 +518,10 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters if (homedir) { GHashTableIter iter; - char *key; - map_string_t *value; + char *plugin_name; + map_string_t *plugin_settings; g_hash_table_iter_init(&iter, settings); - while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) + while (g_hash_table_iter_next(&iter, (void**)&plugin_name, (void**)&plugin_settings)) { /* Load plugin config in the home dir. Do not skip lines * with empty value (but containing a "key="), @@ -529,7 +529,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters * from /etc/abrt/plugins/foo.conf, but he prefers to * enter it every time he reports. */ map_string_h *single_plugin_settings = new_map_string(); - char *path = xasprintf("%s/.abrt/%s.conf", homedir, key); + char *path = xasprintf("%s/.abrt/%s.conf", homedir, plugin_name); bool success = load_conf_file(path, single_plugin_settings, /*skip key w/o values:*/ false); free(path); if (!success) @@ -540,11 +540,11 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters /* Merge user's plugin settings into already loaded settings */ GHashTableIter iter2; - char *key2; - char *value2; + char *key; + char *value; g_hash_table_iter_init(&iter2, single_plugin_settings); - while (g_hash_table_iter_next(&iter2, (void**)&key2, (void**)&value2)) - (*value)[key2] = xstrdup(value2); + while (g_hash_table_iter_next(&iter2, (void**)&key, (void**)&value)) + (*plugin_settings)[key] = xstrdup(value); free_map_string(single_plugin_settings); } -- cgit From d7d62ea5ee19f5cad52dcfb2f2a49d8d36fa1228 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 18:34:08 +0100 Subject: introduce and use new helper function list_free_with_free Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 8b8f9cc6..d0a74955 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -15,8 +15,6 @@ 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 "report.h" #include "run-command.h" #include "dbus.h" -- cgit From 5c71e00f814f679bd6ea652eda8552f746b5f725 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 27 Jan 2011 15:59:28 +0100 Subject: preparatory changes for abrt-cli local processing change Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 54 ++++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index d0a74955..38653e67 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -33,13 +33,10 @@ static char *trim(char *str) return NULL; // Remove leading spaces. - char *ibuf; - ibuf = skip_whitespace(str); - int i = strlen(ibuf); - if (str != ibuf) - memmove(str, ibuf, i + 1); + overlapping_strcpy(str, skip_whitespace(str)); // Remove trailing spaces. + int i = strlen(str); while (--i >= 0) { if (!isspace(str[i])) @@ -450,28 +447,17 @@ static bool ask_yesno(const char *question) } /* Returns true if echo has been changed from another state. */ -static bool set_echo(bool enabled) +static bool set_echo(bool enable) { - if (isatty(STDIN_FILENO) == 0) - { - /* Clean errno, which is set by isatty. */ - errno = 0; - return false; - } - struct termios t; if (tcgetattr(STDIN_FILENO, &t) < 0) return false; - /* No change needed. */ - if ((bool)(t.c_lflag & ECHO) == enabled) + /* No change needed? */ + if ((bool)(t.c_lflag & ECHO) == enable) return false; - if (enabled) - t.c_lflag |= ECHO; - else - t.c_lflag &= ~ECHO; - + t.c_lflag ^= ECHO; if (tcsetattr(STDIN_FILENO, TCSANOW, &t) < 0) perror_msg_and_die("tcsetattr"); @@ -510,7 +496,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters } /* Second, load user-specific settings, which override - the system-wide settings. */ + * the system-wide settings. */ struct passwd* pw = getpwuid(geteuid()); const char* homedir = pw ? pw->pw_dir : NULL; if (homedir) @@ -584,15 +570,11 @@ static void ask_for_missing_settings(const char *plugin_name, map_string_t &sing } } -/* Reports the crash with corresponding crash_id over DBus. */ -int report(const char *crash_id, int flags) +/* Reports the crash over DBus. */ +int report(const char *dump_dir_name, int flags) { - int old_logmode = logmode; - if (flags & CLI_REPORT_SILENT_IF_NOT_FOUND) - logmode = 0; // Ask for an initial report. - crash_data_t *crash_data = call_CreateReport(crash_id); - logmode = old_logmode; + crash_data_t *crash_data = call_CreateReport(dump_dir_name); if (!crash_data || g_hash_table_size(crash_data) == 0) { free_crash_data(crash_data); @@ -616,7 +598,7 @@ int report(const char *crash_id, int flags) /* Get possible reporters associated with this particular crash. */ const char *events = get_crash_item_content_or_NULL(crash_data, CD_EVENTS); - vector_string_t reporters; + vector_string_t report_events; if (events) while (*events) { const char *end = strchrnul(events, '\n'); @@ -624,7 +606,7 @@ int report(const char *crash_id, int flags) && (events[6] == '\0' || events[6] == '_') ) { char *tmp = xstrndup(events, end - events); - reporters.push_back(tmp); + report_events.push_back(tmp); free(tmp); } events = end; @@ -634,14 +616,14 @@ int report(const char *crash_id, int flags) } /* Get settings */ - GHashTable *reporters_settings = get_reporter_plugin_settings(reporters); + GHashTable *reporters_settings = get_reporter_plugin_settings(report_events); int errors = 0; int plugins = 0; if (flags & CLI_REPORT_BATCH) { puts(_("Reporting...")); - report_status_t r = call_Report(crash_data, reporters, reporters_settings); + report_status_t r = call_Report(crash_data, report_events, reporters_settings); report_status_t::iterator it = r.begin(); while (it != r.end()) { @@ -656,10 +638,10 @@ int report(const char *crash_id, int flags) else { /* For every reporter, ask if user really wants to report using it. */ - for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) + for (vector_string_t::const_iterator it = report_events.begin(); it != report_events.end(); ++it) { char question[255]; - snprintf(question, 255, _("Report using %s?"), it->c_str()); + snprintf(question, sizeof(question), _("Report using %s?"), it->c_str()); if (!ask_yesno(question)) { puts(_("Skipping...")); @@ -695,8 +677,8 @@ int report(const char *crash_id, int flags) ask_for_missing_settings(it->c_str(), *settings); - vector_string_t cur_reporter(1, *it); - report_status_t r = call_Report(crash_data, cur_reporter, reporters_settings); + vector_string_t cur_event(1, *it); + report_status_t r = call_Report(crash_data, cur_event, reporters_settings); assert(r.size() == 1); /* one reporter --> one report status */ vector_string_t &v = r.begin()->second; printf("%s: %s\n", r.begin()->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str()); -- cgit From 876664f002c5f90e5722602956a6d60591619680 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Feb 2011 15:57:39 +0100 Subject: abrt-cli: converted to process events locally Only -d DIR operation still goes through the daemon. Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 350 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 253 insertions(+), 97 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 38653e67..56740e25 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -464,36 +464,51 @@ static bool set_echo(bool enable) return true; } -static void free_map_string_t(gpointer data) -{ - delete (map_string_t *)data; -} /** * Gets reporter plugin settings. - * @param reporters - * List of reporter names. Settings of these reporters are handled. * @return settings * A structure filled with reporter plugin settings. * It's GHashTable and must be passed to * g_hash_table_destroy(); */ -static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters) +static void get_plugin_system_settings(GHashTable *settings) { - /* First of all, load system-wide report plugin settings. */ - GHashTable *settings = g_hash_table_new_full(g_str_hash, g_str_equal, - free, free_map_string_t); + DIR *dir = opendir(PLUGINS_CONF_DIR); + if (!dir) + return; - for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) + struct dirent *dent; + while ((dent = readdir(dir)) != NULL) { - map_string_t *single_plugin_settings = new map_string_t; - *single_plugin_settings = call_GetPluginSettings(it->c_str()); - - // Copy the received settings as defaults. - // Plugins won't work without it, if some value is missing - // they use their default values for all fields. - g_hash_table_replace(settings, xstrdup(it->c_str()), single_plugin_settings); + char *ext = strrchr(dent->d_name, '.'); + if (!ext || strcmp(ext + 1, "conf") != 0) + continue; + if (!is_regular_file(dent, PLUGINS_CONF_DIR)) + continue; + VERB3 log("Found %s", dent->d_name); + + char *conf_file = concat_path_file(PLUGINS_CONF_DIR, dent->d_name); + map_string_h *single_plugin_settings = new_map_string(); + if (load_conf_file(conf_file, single_plugin_settings, /*skip w/o value:*/ false)) + VERB3 log("Loaded %s", dent->d_name); + free(conf_file); + + *ext = '\0'; + g_hash_table_replace(settings, xstrdup(dent->d_name), single_plugin_settings); } + closedir(dir); +} + +static GHashTable *get_plugin_settings(void) +{ + /* First of all, load system-wide plugin settings. */ + GHashTable *settings = g_hash_table_new_full( + g_str_hash, g_str_equal, + free, (void (*)(void*))free_map_string + ); + + get_plugin_system_settings(settings); /* Second, load user-specific settings, which override * the system-wide settings. */ @@ -503,7 +518,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters { GHashTableIter iter; char *plugin_name; - map_string_t *plugin_settings; + map_string_h *plugin_settings; g_hash_table_iter_init(&iter, settings); while (g_hash_table_iter_next(&iter, (void**)&plugin_name, (void**)&plugin_settings)) { @@ -528,7 +543,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters char *value; g_hash_table_iter_init(&iter2, single_plugin_settings); while (g_hash_table_iter_next(&iter2, (void**)&key, (void**)&value)) - (*plugin_settings)[key] = xstrdup(value); + g_hash_table_replace(plugin_settings, xstrdup(key), xstrdup(value)); free_map_string(single_plugin_settings); } @@ -539,13 +554,13 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters /** * Asks user for missing login information */ -static void ask_for_missing_settings(const char *plugin_name, map_string_t &single_plugin_settings) +static void ask_for_missing_settings(const char *plugin_name, map_string_h *single_plugin_settings) { // Login information is missing. - bool loginMissing = single_plugin_settings.find("Login") != single_plugin_settings.end() - && 0 == strcmp(single_plugin_settings["Login"].c_str(), ""); - bool passwordMissing = single_plugin_settings.find("Password") != single_plugin_settings.end() - && 0 == strcmp(single_plugin_settings["Password"].c_str(), ""); + const char *login = get_map_string_item_or_NULL(single_plugin_settings, "Login"); + const char *password = get_map_string_item_or_NULL(single_plugin_settings, "Password"); + bool loginMissing = (login && login[0] == '\0'); + bool passwordMissing = (password && password[0] == '\0'); if (!loginMissing && !passwordMissing) return; @@ -555,7 +570,7 @@ static void ask_for_missing_settings(const char *plugin_name, map_string_t &sing if (loginMissing) { read_from_stdin(_("Enter your login: "), result, 64); - single_plugin_settings["Login"] = std::string(result); + g_hash_table_replace(single_plugin_settings, xstrdup("Login"), xstrdup(result)); } if (passwordMissing) { @@ -566,77 +581,224 @@ static void ask_for_missing_settings(const char *plugin_name, map_string_t &sing // Newline was not added by pressing Enter because ECHO was disabled, so add it now. puts(""); - single_plugin_settings["Password"] = std::string(result); + g_hash_table_replace(single_plugin_settings, xstrdup("Password"), xstrdup(result)); } } -/* Reports the crash over DBus. */ -int report(const char *dump_dir_name, int flags) + +struct logging_state { + char *last_line; +}; +static char *do_log_and_save_line(char *log_line, void *param) +{ + struct logging_state *l_state = (struct logging_state *)param; + log("%s", log_line); + free(l_state->last_line); + l_state->last_line = log_line; + return NULL; +} +static int run_events(const char *dump_dir_name, + const vector_string_t& events, + GHashTable *map_map_settings +) { + int error_cnt = 0; + GList *env_list = NULL; + + // Export overridden settings as environment variables + GHashTableIter iter; + char *plugin_name; + map_string_h *single_plugin_settings; + g_hash_table_iter_init(&iter, map_map_settings); + while (g_hash_table_iter_next(&iter, (void**)&plugin_name, (void**)&single_plugin_settings)) + { + GHashTableIter iter2; + char *key; + char *value; + g_hash_table_iter_init(&iter2, single_plugin_settings); + while (g_hash_table_iter_next(&iter2, (void**)&key, (void**)&value)) + { + char *s = xasprintf("%s_%s=%s", plugin_name, key, value); + VERB3 log("Exporting '%s'", s); + putenv(s); + env_list = g_list_append(env_list, s); + } + } + + // Run events + bool at_least_one_reporter_succeeded = false; + std::string message; + struct logging_state l_state; + l_state.last_line = NULL; + struct run_event_state *run_state = new_run_event_state(); + run_state->logging_callback = do_log_and_save_line; + run_state->logging_param = &l_state; + for (unsigned i = 0; i < events.size(); i++) + { + std::string event = events[i]; + + int r = run_event_on_dir_name(run_state, dump_dir_name, event.c_str()); + if (r == -1) + { + l_state.last_line = xasprintf("Error: no processing is specified for event '%s'", event.c_str()); + } + if (r == 0) + { + at_least_one_reporter_succeeded = true; + printf("%s: %s\n", event.c_str(), (l_state.last_line ? : "Reporting succeeded")); + if (message != "") + message += ";"; + message += (l_state.last_line ? : "Reporting succeeded"); + } + else + { + error_msg("Reporting via '%s' was not successful%s%s", + event.c_str(), + l_state.last_line ? ": " : "", + l_state.last_line ? l_state.last_line : "" + ); + error_cnt++; + } + free(l_state.last_line); + l_state.last_line = NULL; + } + free_run_event_state(run_state); + + // Unexport overridden settings + for (GList *li = env_list; li; li = g_list_next(li)) + { + char *s = (char*)li->data; + /* Need to make a copy: just cutting s at '=' and unsetenv'ing + * the result would be a bug! s _itself_ is in environment now, + * we must not modify it there! + */ + char *name = xstrndup(s, strchrnul(s, '=') - s); + VERB3 log("Unexporting '%s'", name); + unsetenv(name); + free(name); + free(s); + } + g_list_free(env_list); + + // Save reporting results + if (at_least_one_reporter_succeeded) + { + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (dd) + { + dd_save_text(dd, FILENAME_MESSAGE, message.c_str()); + dd_close(dd); + } + } + + return error_cnt; +} + + +static char *do_log(char *log_line, void *param) { - // Ask for an initial report. - crash_data_t *crash_data = call_CreateReport(dump_dir_name); - if (!crash_data || g_hash_table_size(crash_data) == 0) + log("%s", log_line); + return log_line; +} +int run_analyze_event(const char *dump_dir_name) +{ + VERB2 log("run_analyze_event('%s')", dump_dir_name); + + struct run_event_state *run_state = new_run_event_state(); + run_state->logging_callback = do_log; + int res = run_event_on_dir_name(run_state, dump_dir_name, "analyze"); + free_run_event_state(run_state); + + if (res != 0 && res != -1) /* -1 is "nothing was done", here it is ok */ { - free_crash_data(crash_data); - return -1; + error_msg("Error while running analyze event on '%s'", dump_dir_name); + return 1; } + return 0; +} + + +/* Report the crash */ +int report(const char *dump_dir_name, int flags) +{ + if (run_analyze_event(dump_dir_name) != 0) + return 1; - const char *rating_str = get_crash_item_content_or_NULL(crash_data, FILENAME_RATING); - unsigned rating = rating_str ? xatou(rating_str) : 4; + /* Load crash_data from (possibly updated by analyze) dump dir */ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + return -1; + + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); + char *events_as_lines = list_possible_events(dd, NULL, ""); + dd_close(dd); - /* Open text editor and give a chance to review the backtrace etc. */ 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); if (result != 0) { free_crash_data(crash_data); - return result; + free(events_as_lines); + return 1; + } + /* Save comment, "how to reproduce", backtrace */ + 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 *reproduce = get_crash_item_content_or_NULL(crash_data, FILENAME_REPRODUCE); + const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); + if (comment) + dd_save_text(dd, FILENAME_COMMENT, comment); + if (reproduce) + dd_save_text(dd, FILENAME_REPRODUCE, reproduce); + if (backtrace) + dd_save_text(dd, FILENAME_BACKTRACE, backtrace); + dd_close(dd); } } - /* Get possible reporters associated with this particular crash. */ - const char *events = get_crash_item_content_or_NULL(crash_data, CD_EVENTS); + /* Get possible reporters associated with this particular crash */ vector_string_t report_events; - if (events) while (*events) + if (events_as_lines) { - const char *end = strchrnul(events, '\n'); - if (strncmp(events, "report", 6) == 0 - && (events[6] == '\0' || events[6] == '_') - ) { - char *tmp = xstrndup(events, end - events); - report_events.push_back(tmp); - free(tmp); + char *events = events_as_lines; + while (*events) + { + char *end = strchrnul(events, '\n'); + if (strncmp(events, "report", 6) == 0 + && (events[6] == '\0' || events[6] == '_') + ) { + char *tmp = xstrndup(events, end - events); + report_events.push_back(tmp); + free(tmp); + } + events = end; + if (!*events) + break; + events++; } - events = end; - if (!*events) - break; - events++; } /* Get settings */ - GHashTable *reporters_settings = get_reporter_plugin_settings(report_events); + GHashTable *map_map_settings = get_plugin_settings(); int errors = 0; int plugins = 0; if (flags & CLI_REPORT_BATCH) { puts(_("Reporting...")); - report_status_t r = call_Report(crash_data, report_events, reporters_settings); - report_status_t::iterator it = r.begin(); - while (it != r.end()) - { - vector_string_t &v = it->second; - printf("%s: %s\n", it->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str()); - plugins++; - if (v[REPORT_STATUS_IDX_FLAG] == "0") - errors++; - it++; - } + errors += run_events(dump_dir_name, report_events, map_map_settings); + plugins += report_events.size(); } else { + const char *rating_str = get_crash_item_content_or_NULL(crash_data, FILENAME_RATING); + unsigned rating = rating_str ? xatou(rating_str) : 4; + /* For every reporter, ask if user really wants to report using it. */ for (vector_string_t::const_iterator it = report_events.begin(); it != report_events.end(); ++it) { @@ -648,48 +810,42 @@ int report(const char *dump_dir_name, int flags) continue; } - map_string_t *settings = (map_string_t *)g_hash_table_lookup(reporters_settings, it->c_str()); - if (settings) +//TODO: rethink how we associate report events with configs + if (strncmp(it->c_str(), "report_", strlen("report_")) == 0) { - map_string_t::iterator rating_setting = settings->find("RatingRequired"); - if (rating_setting != settings->end() - && string_to_bool(rating_setting->second.c_str()) - && rating < 3) + const char *config_name = it->c_str() + strlen("report_"); + map_string_h *single_plugin_settings = (map_string_h *)g_hash_table_lookup(map_map_settings, config_name); + if (single_plugin_settings) { - puts(_("Reporting disabled because the backtrace is unusable")); - - const char *package = get_crash_item_content_or_NULL(crash_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); - - plugins++; - errors++; - continue; + const char *rating_required = get_map_string_item_or_NULL(single_plugin_settings, "RatingRequired"); + if (rating_required + && string_to_bool(rating_required) == true + && rating < 3 + ) { + puts(_("Reporting disabled because the backtrace is unusable")); + + const char *package = get_crash_item_content_or_NULL(crash_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); + + plugins++; + errors++; + continue; + } + ask_for_missing_settings(it->c_str(), single_plugin_settings); } } - else - { - puts(_("Error loading reporter settings")); - plugins++; - errors++; - continue; - } - - ask_for_missing_settings(it->c_str(), *settings); vector_string_t cur_event(1, *it); - report_status_t r = call_Report(crash_data, cur_event, reporters_settings); - assert(r.size() == 1); /* one reporter --> one report status */ - vector_string_t &v = r.begin()->second; - printf("%s: %s\n", r.begin()->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str()); + errors += run_events(dump_dir_name, cur_event, map_map_settings); plugins++; - if (v[REPORT_STATUS_IDX_FLAG] == "0") - errors++; } } - g_hash_table_destroy(reporters_settings); - free_crash_data(crash_data); + g_hash_table_destroy(map_map_settings); + printf(_("Crash reported via %d report events (%d errors)\n"), plugins, errors); - return errors != 0; + free_crash_data(crash_data); + free(events_as_lines); + return errors; } -- cgit From 058e0d3144b32d048c2a7637447881256e4c9997 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Feb 2011 15:58:44 +0100 Subject: use run_state->children_count == 0 check for "event not conf'd" condition run_event_on_FOO() was returning -1 when it found that not even one program was run on the requested event. Which is not a very natural return value: in many cases this isn't an error. This change makes it return 0 in this case. It is ok since now we have run_state->children_count member which can be checked for 0 by those callers which want to detect this condition. Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 56740e25..29c5e06f 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -637,9 +637,10 @@ static int run_events(const char *dump_dir_name, std::string event = events[i]; int r = run_event_on_dir_name(run_state, dump_dir_name, event.c_str()); - if (r == -1) + if (r == 0 && run_state->children_count == 0) { l_state.last_line = xasprintf("Error: no processing is specified for event '%s'", event.c_str()); + r = -1; } if (r == 0) { @@ -707,13 +708,7 @@ int run_analyze_event(const char *dump_dir_name) run_state->logging_callback = do_log; int res = run_event_on_dir_name(run_state, dump_dir_name, "analyze"); free_run_event_state(run_state); - - if (res != 0 && res != -1) /* -1 is "nothing was done", here it is ok */ - { - error_msg("Error while running analyze event on '%s'", dump_dir_name); - return 1; - } - return 0; + return res; } -- cgit From f8c0e544a905ba42c8b550409f492081534977f5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 10 Feb 2011 15:48:15 +0100 Subject: get rid of FILENAME_DESCRIPTION, rename "release" to "os_release" Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 29c5e06f..5c85fa28 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -192,7 +192,7 @@ static void write_crash_report(crash_data_t *report, FILE *fp) write_crash_report_field(fp, report, FILENAME_KERNEL, _("# Kernel version")); write_crash_report_field(fp, report, FILENAME_PACKAGE, _("# Package")); write_crash_report_field(fp, report, FILENAME_REASON, _("# Reason of crash")); - write_crash_report_field(fp, report, FILENAME_RELEASE, _("# Release string of the operating system")); + write_crash_report_field(fp, report, FILENAME_OS_RELEASE, _("# Release string of the operating system")); } /* @@ -279,7 +279,7 @@ static int read_crash_report(crash_data_t *report, const char *text) result |= read_crash_report_field(text, report, FILENAME_KERNEL); result |= read_crash_report_field(text, report, FILENAME_PACKAGE); result |= read_crash_report_field(text, report, FILENAME_REASON); - result |= read_crash_report_field(text, report, FILENAME_RELEASE); + result |= read_crash_report_field(text, report, FILENAME_OS_RELEASE); return result; } -- cgit From 2abf0fc078221715abbd20c8451d300eaf787848 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 10 Feb 2011 18:04:43 +0100 Subject: abrt-gtk: make Delete key actually delete the dump dir Signed-off-by: Denys Vlasenko --- src/cli/report.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 5c85fa28..7f317f05 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -17,7 +17,6 @@ */ #include "report.h" #include "run-command.h" -#include "dbus.h" #include "abrtlib.h" /* Field separator for the crash report file that is edited by user. */ -- cgit From a330886781635606626b3b91432525128d0e8a8f Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 7 Feb 2011 11:54:07 +0100 Subject: get rid of unused CD_FLAG_SYS Signed-off-by: Nikola Pajkovsky --- src/cli/report.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 7f317f05..6b2bf2e2 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -147,12 +147,6 @@ static void write_crash_report_field(FILE *fp, crash_data_t *crash_data, return; } - if (value->flags & CD_FLAG_SYS) - { - error_msg("Cannot update field %s because it is a system value", field); - return; - } - fprintf(fp, "%s%s\n", FIELD_SEP, field); fprintf(fp, "%s\n", description); @@ -226,12 +220,6 @@ static int read_crash_report_field(const char *text, crash_data_t *report, return 0; } - if (value->flags & CD_FLAG_SYS) - { - error_msg("Cannot update field %s because it is a system value", field); - return 0; - } - // Do not change noneditable fields. if (!(value->flags & CD_FLAG_ISEDITABLE)) return 0; -- cgit