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/dbus.cpp | 6 +++--- src/cli/dbus.h | 3 ++- src/cli/report.cpp | 55 +++++++++++++++++++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 23 deletions(-) (limited to 'src/cli') diff --git a/src/cli/dbus.cpp b/src/cli/dbus.cpp index 7565d5bc..f9271b85 100644 --- a/src/cli/dbus.cpp +++ b/src/cli/dbus.cpp @@ -161,7 +161,7 @@ map_crash_data_t call_CreateReport(const char* crash_id) report_status_t call_Report(const map_crash_data_t& report, const vector_string_t& reporters, - const map_map_string_t &plugins) + GHashTable *plugins) { DBusMessage* msg = new_call_msg(__func__ + 5); DBusMessageIter out_iter; @@ -172,8 +172,8 @@ report_status_t call_Report(const map_crash_data_t& report, /* parameter #2: reporters to use */ store_val(&out_iter, reporters); /* parameter #3 (opt): plugin config */ - if (!plugins.empty()) - store_val(&out_iter, plugins); + if (g_hash_table_size(plugins)) + store_hash_table_map_string_t(&out_iter, plugins); DBusMessage *reply = send_get_reply_and_unref(msg); diff --git a/src/cli/dbus.h b/src/cli/dbus.h index 9c99c662..b837869d 100644 --- a/src/cli/dbus.h +++ b/src/cli/dbus.h @@ -18,6 +18,7 @@ #ifndef ABRT_CLI_DBUS_H #define ABRT_CLI_DBUS_H +#include #include "abrt_dbus.h" #include "abrt_crash_dump.h" @@ -41,7 +42,7 @@ map_crash_data_t call_CreateReport(const char *crash_id); */ report_status_t call_Report(const map_crash_data_t& report, const vector_string_t& reporters, - const map_map_string_t &plugins); + GHashTable *plugins); int32_t call_DeleteDebugDump(const char* crash_id); 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') 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/CLI.cpp | 6 ++++-- src/cli/report.cpp | 19 ------------------- 2 files changed, 4 insertions(+), 21 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 44271329..64d629b8 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -210,6 +210,7 @@ static const struct option longopts[] = { /* name, has_arg, flag, val */ { "help" , no_argument, NULL, '?' }, + { "verbose" , no_argument, NULL, 'v' }, { "version" , no_argument, NULL, 'V' }, { "list" , no_argument, NULL, 'l' }, { "full" , no_argument, NULL, 'f' }, @@ -243,6 +244,7 @@ static void usage(char *argv0) printf(_("Usage: %s [OPTION]\n\n" "Startup:\n" " -V, --version display the version of %s and exit\n" + " -v, --verbose increase verbosity\n" " -?, --help print this help\n\n" "Actions:\n" " -l, --list print a list of all crashes which are not yet reported\n" @@ -278,8 +280,7 @@ int main(int argc, char** argv) while (1) { /* Do not use colons, arguments are handled after parsing all options. */ - int c = getopt_long_only(argc, argv, "?Vrdlfyib", - longopts, NULL); + int c = getopt_long(argc, argv, "?Vvrdlfyib", longopts, NULL); #define SET_OP(newop) \ if (op != -1 && op != newop) \ @@ -298,6 +299,7 @@ int main(int argc, char** argv) case 'f': full = true; break; case 'y': always = true; break; case 'b': backtrace = true; break; + case 'v': g_verbose++; break; case -1: /* end of options */ break; default: /* some error */ case '?': 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/CLI.cpp | 91 +++++++++++++++++++++++++++++------------------------- src/cli/dbus.cpp | 16 +++++----- src/cli/dbus.h | 6 ++-- src/cli/report.cpp | 77 ++++++++++++++++++++++++--------------------- 4 files changed, 101 insertions(+), 89 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 64d629b8..fd8ec4f0 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -38,10 +38,10 @@ static char *localize_crash_time(const char *timestr) } /** Prints basic information about a crash to stdout. */ -static void print_crash(const map_crash_data_t &crash) +static void print_crash(crash_data_t *crash_data) { /* Create a localized string from crash time. */ - const char *timestr = get_crash_data_item_content(crash, FILENAME_TIME).c_str(); + const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME); const char *timeloc = localize_crash_time(timestr); printf(_("\tCrash dump : %s\n" @@ -50,17 +50,18 @@ static void print_crash(const map_crash_data_t &crash) "\tExecutable : %s\n" "\tCrash Time : %s\n" "\tCrash Count: %s\n"), - get_crash_data_item_content(crash, CD_DUMPDIR).c_str(), - get_crash_data_item_content(crash, FILENAME_UID).c_str(), - get_crash_data_item_content(crash, FILENAME_PACKAGE).c_str(), - get_crash_data_item_content(crash, FILENAME_EXECUTABLE).c_str(), + get_crash_item_content_or_NULL(crash_data, CD_DUMPDIR), + get_crash_item_content_or_NULL(crash_data, FILENAME_UID), + get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), + get_crash_item_content_or_NULL(crash_data, FILENAME_EXECUTABLE), timeloc, - get_crash_data_item_content(crash, FILENAME_COUNT).c_str()); + get_crash_item_content_or_NULL(crash_data, FILENAME_COUNT) + ); free((void *)timeloc); /* Print the hostname if it's available. */ - const char *hostname = get_crash_data_item_content_or_NULL(crash, FILENAME_HOSTNAME); + const char *hostname = get_crash_item_content_or_NULL(crash_data, FILENAME_HOSTNAME); if (hostname) printf(_("\tHostname : %s\n"), hostname); } @@ -70,14 +71,14 @@ static void print_crash(const map_crash_data_t &crash) * @param include_reported * Do not skip entries marked as already reported. */ -static void print_crash_list(const vector_map_crash_data_t& crash_list, bool include_reported) +static void print_crash_list(vector_of_crash_data_t *crash_list, bool include_reported) { - for (unsigned i = 0; i < crash_list.size(); ++i) + for (unsigned i = 0; i < crash_list->len; ++i) { - const map_crash_data_t& crash = crash_list[i]; + crash_data_t *crash = get_crash_data(crash_list, i); if (!include_reported) { - const char *msg = get_crash_data_item_content_or_NULL(crash, FILENAME_MESSAGE); + const char *msg = get_crash_item_content_or_NULL(crash, FILENAME_MESSAGE); if (!msg || !msg[0]) continue; } @@ -90,9 +91,9 @@ static void print_crash_list(const vector_map_crash_data_t& crash_list, bool inc /** * Prints full information about a crash */ -static void print_crash_info(const map_crash_data_t& crash, bool show_backtrace) +static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) { - const char *timestr = get_crash_data_item_content(crash, FILENAME_TIME).c_str(); + const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME); const char *timeloc = localize_crash_time(timestr); printf(_("Dump directory: %s\n" @@ -104,50 +105,51 @@ static void print_crash_info(const map_crash_data_t& crash, bool show_backtrace) "Executable: %s\n" "System: %s, kernel %s\n" "Reason: %s\n"), - get_crash_data_item_content(crash, CD_DUMPDIR).c_str(), + get_crash_item_content_or_die(crash_data, CD_DUMPDIR), timeloc, - get_crash_data_item_content(crash, FILENAME_ANALYZER).c_str(), - get_crash_data_item_content(crash, FILENAME_COMPONENT).c_str(), - get_crash_data_item_content(crash, FILENAME_PACKAGE).c_str(), - get_crash_data_item_content(crash, FILENAME_CMDLINE).c_str(), - get_crash_data_item_content(crash, FILENAME_EXECUTABLE).c_str(), - get_crash_data_item_content(crash, FILENAME_RELEASE).c_str(), - get_crash_data_item_content(crash, FILENAME_KERNEL).c_str(), - get_crash_data_item_content(crash, FILENAME_REASON).c_str()); + get_crash_item_content_or_die(crash_data, FILENAME_ANALYZER), + get_crash_item_content_or_die(crash_data, FILENAME_COMPONENT), + get_crash_item_content_or_die(crash_data, FILENAME_PACKAGE), + get_crash_item_content_or_die(crash_data, FILENAME_CMDLINE), + get_crash_item_content_or_die(crash_data, FILENAME_EXECUTABLE), + get_crash_item_content_or_die(crash_data, FILENAME_RELEASE), + get_crash_item_content_or_die(crash_data, FILENAME_KERNEL), + get_crash_item_content_or_die(crash_data, FILENAME_REASON) + ); free((void *)timeloc); /* Print optional fields only if they are available */ /* Coredump is not present in kerneloopses and Python exceptions. */ - const char *coredump = get_crash_data_item_content_or_NULL(crash, FILENAME_COREDUMP); + const char *coredump = get_crash_item_content_or_NULL(crash_data, FILENAME_COREDUMP); if (coredump) printf(_("Coredump file: %s\n"), coredump); - const char *rating = get_crash_data_item_content_or_NULL(crash, FILENAME_RATING); + const char *rating = get_crash_item_content_or_NULL(crash_data, FILENAME_RATING); if (rating) printf(_("Rating: %s\n"), rating); /* Crash function is not present in kerneloopses, and before the full report is created.*/ - const char *crash_function = get_crash_data_item_content_or_NULL(crash, FILENAME_CRASH_FUNCTION); + const char *crash_function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); if (crash_function) printf(_("Crash function: %s\n"), crash_function); - const char *hostname = get_crash_data_item_content_or_NULL(crash, FILENAME_HOSTNAME); + const char *hostname = get_crash_item_content_or_NULL(crash_data, FILENAME_HOSTNAME); if (hostname) printf(_("Hostname: %s\n"), hostname); - const char *reproduce = get_crash_data_item_content_or_NULL(crash, FILENAME_REPRODUCE); + const char *reproduce = get_crash_item_content_or_NULL(crash_data, FILENAME_REPRODUCE); if (reproduce) printf(_("\nHow to reproduce:\n%s\n"), reproduce); - const char *comment = get_crash_data_item_content_or_NULL(crash, FILENAME_COMMENT); + const char *comment = get_crash_item_content_or_NULL(crash_data, FILENAME_COMMENT); if (comment) printf(_("\nComment:\n%s\n"), comment); if (show_backtrace) { - const char *backtrace = get_crash_data_item_content_or_NULL(crash, FILENAME_BACKTRACE); + const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); if (backtrace) printf(_("\nBacktrace:\n%s\n"), backtrace); } @@ -159,15 +161,17 @@ static void print_crash_info(const map_crash_data_t& crash, bool show_backtrace) */ static char *guess_crash_id(const char *str) { - vector_map_crash_data_t ci = call_GetCrashInfos(); - unsigned num_crashinfos = ci.size(); + vector_of_crash_data_t *ci = call_GetCrashInfos(); + unsigned num_crashinfos = ci->len; if (str[0] == '@') /* "--report @N" syntax */ { unsigned position = xatoi_u(str + 1); if (position >= num_crashinfos) error_msg_and_die("There are only %u crash infos", num_crashinfos); - map_crash_data_t& info = ci[position]; - return xstrdup(get_crash_data_item_content(info, CD_DUMPDIR).c_str()); + crash_data_t *info = get_crash_data(ci, position); + char *res = xstrdup(get_crash_item_content_or_die(info, CD_DUMPDIR)); + free_vector_of_crash_data(ci); + return res; } unsigned len = strlen(str); @@ -175,8 +179,8 @@ static char *guess_crash_id(const char *str) char *result = NULL; for (ii = 0; ii < num_crashinfos; ii++) { - map_crash_data_t& info = ci[ii]; - const char *this_dir = get_crash_data_item_content(info, CD_DUMPDIR).c_str(); + crash_data_t *info = get_crash_data(ci, ii); + const char *this_dir = get_crash_item_content_or_die(info, CD_DUMPDIR); if (strncmp(str, this_dir, len) == 0) { if (result) @@ -184,6 +188,7 @@ static char *guess_crash_id(const char *str) result = xstrdup(this_dir); } } + free_vector_of_crash_data(ci); if (!result) error_msg_and_die("Crash dump directory '%s' not found", str); return result; @@ -353,8 +358,9 @@ int main(int argc, char** argv) { case OPT_GET_LIST: { - vector_map_crash_data_t ci = call_GetCrashInfos(); + vector_of_crash_data_t *ci = call_GetCrashInfos(); print_crash_list(ci, full); + free_vector_of_crash_data(ci); break; } case OPT_REPORT: @@ -403,12 +409,12 @@ int main(int argc, char** argv) int old_logmode = logmode; logmode = 0; - map_crash_data_t crashData = call_CreateReport(crash_id); - if (crashData.empty()) /* no such crash_id */ + crash_data_t *crash_data = call_CreateReport(crash_id); + if (!crash_data) /* no such crash_id */ { crash_id = guess_crash_id(crash_id); - crashData = call_CreateReport(crash_id); - if (crashData.empty()) + crash_data = call_CreateReport(crash_id); + if (!crash_data) { error_msg("Crash '%s' not found", crash_id); free((void *)crash_id); @@ -420,7 +426,8 @@ int main(int argc, char** argv) logmode = old_logmode; - print_crash_info(crashData, backtrace); + print_crash_info(crash_data, backtrace); + free_crash_data(crash_data); break; } diff --git a/src/cli/dbus.cpp b/src/cli/dbus.cpp index f9271b85..6c98ec4e 100644 --- a/src/cli/dbus.cpp +++ b/src/cli/dbus.cpp @@ -121,7 +121,7 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) } } -vector_map_crash_data_t call_GetCrashInfos() +vector_of_crash_data_t *call_GetCrashInfos() { DBusMessage* msg = new_call_msg(__func__ + 5); DBusMessage *reply = send_get_reply_and_unref(msg); @@ -129,8 +129,8 @@ vector_map_crash_data_t call_GetCrashInfos() DBusMessageIter in_iter; dbus_message_iter_init(reply, &in_iter); - vector_map_crash_data_t argout; - int r = load_val(&in_iter, argout); + vector_of_crash_data_t *argout = NULL; + int r = load_vector_of_crash_data(&in_iter, &argout); if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); @@ -138,7 +138,7 @@ vector_map_crash_data_t call_GetCrashInfos() return argout; } -map_crash_data_t call_CreateReport(const char* crash_id) +crash_data_t *call_CreateReport(const char* crash_id) { DBusMessage* msg = new_call_msg(__func__ + 5); dbus_message_append_args(msg, @@ -150,8 +150,8 @@ map_crash_data_t call_CreateReport(const char* crash_id) DBusMessageIter in_iter; dbus_message_iter_init(reply, &in_iter); - map_crash_data_t argout; - int r = load_val(&in_iter, argout); + crash_data_t *argout = NULL; + int r = load_crash_data(&in_iter, &argout); if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); @@ -159,7 +159,7 @@ map_crash_data_t call_CreateReport(const char* crash_id) return argout; } -report_status_t call_Report(const map_crash_data_t& report, +report_status_t call_Report(crash_data_t *report, const vector_string_t& reporters, GHashTable *plugins) { @@ -168,7 +168,7 @@ report_status_t call_Report(const map_crash_data_t& report, dbus_message_iter_init_append(msg, &out_iter); /* parameter #1: report data */ - store_val(&out_iter, report); + store_crash_data(&out_iter, report); /* parameter #2: reporters to use */ store_val(&out_iter, reporters); /* parameter #3 (opt): plugin config */ diff --git a/src/cli/dbus.h b/src/cli/dbus.h index b837869d..0d338d27 100644 --- a/src/cli/dbus.h +++ b/src/cli/dbus.h @@ -24,9 +24,9 @@ extern DBusConnection* s_dbus_conn; -vector_map_crash_data_t call_GetCrashInfos(); +vector_of_crash_data_t *call_GetCrashInfos(); -map_crash_data_t call_CreateReport(const char *crash_id); +crash_data_t *call_CreateReport(const char *crash_id); /** Sends report using enabled Reporter plugins. * @param report @@ -40,7 +40,7 @@ map_crash_data_t call_CreateReport(const char *crash_id); * obtained by call_GetPluginSettings, otherwise the plugin might ignore * the settings. */ -report_status_t call_Report(const map_crash_data_t& report, +report_status_t call_Report(crash_data_t *report, const vector_string_t& reporters, GHashTable *plugins); 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') 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/CLI.cpp | 1 - src/cli/report.cpp | 39 ++++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index fd8ec4f0..cdce6b8a 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -19,7 +19,6 @@ # include #endif #include -#include "abrt_exception.h" #include "abrtlib.h" #include "abrt_dbus.h" #include "dbus_common.h" 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 dc3c5b79ba1ee6fd7a98842fde43d072e004f93b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 16:07:31 +0100 Subject: add abrt_ prefixes to abrt-internal functions in libabrt.so Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index cdce6b8a..aeb1d461 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -164,7 +164,7 @@ static char *guess_crash_id(const char *str) unsigned num_crashinfos = ci->len; if (str[0] == '@') /* "--report @N" syntax */ { - unsigned position = xatoi_u(str + 1); + unsigned position = xatoi_positive(str + 1); if (position >= num_crashinfos) error_msg_and_die("There are only %u crash infos", num_crashinfos); crash_data_t *info = get_crash_data(ci, position); -- 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/Makefile.am | 5 +++-- src/cli/report.cpp | 19 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/cli') diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 3584fd6c..9346dd16 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -7,12 +7,13 @@ abrt_cli_SOURCES = \ dbus.h dbus.cpp abrt_cli_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DVAR_RUN=\"$(VAR_RUN)\" \ $(ENABLE_SOCKET_OR_DBUS) \ $(DBUS_CFLAGS) $(GLIB_CFLAGS) \ - -D_GNU_SOURCE + -D_GNU_SOURCE \ + -Wall -Werror # $(GTK_CFLAGS) abrt_cli_LDADD = \ 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 6afce866d57432a53938479455ec7bbcb89bab8d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Dec 2010 13:07:10 +0100 Subject: rename libabrt.so to libreport.so Signed-off-by: Denys Vlasenko --- src/cli/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cli') diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 9346dd16..5c1d7848 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -17,7 +17,7 @@ abrt_cli_CPPFLAGS = \ # $(GTK_CFLAGS) abrt_cli_LDADD = \ - ../lib/libabrt.la \ + ../lib/libreport.la \ ../lib/libabrt_dbus.la \ $(GLIB_LIBS) -- 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') 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 df1b1d501106687fcf0039dc9771c4455c346df5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 22 Dec 2010 13:57:14 +0100 Subject: *: rename *crash_dump.* -> *crash_data.* Signed-off-by: Denys Vlasenko --- src/cli/dbus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cli') diff --git a/src/cli/dbus.h b/src/cli/dbus.h index 0d338d27..62ce6fca 100644 --- a/src/cli/dbus.h +++ b/src/cli/dbus.h @@ -20,7 +20,7 @@ #include #include "abrt_dbus.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" extern DBusConnection* s_dbus_conn; -- 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/dbus.h | 1 - src/cli/report.cpp | 2 -- 2 files changed, 3 deletions(-) (limited to 'src/cli') diff --git a/src/cli/dbus.h b/src/cli/dbus.h index 62ce6fca..e2e763c2 100644 --- a/src/cli/dbus.h +++ b/src/cli/dbus.h @@ -18,7 +18,6 @@ #ifndef ABRT_CLI_DBUS_H #define ABRT_CLI_DBUS_H -#include #include "abrt_dbus.h" #include "abrt_crash_data.h" 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/CLI.cpp | 144 ++++++++++++---------------------------------------- src/cli/Makefile.am | 4 +- src/cli/report.cpp | 54 +++++++------------- src/cli/report.h | 5 +- 4 files changed, 55 insertions(+), 152 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index aeb1d461..5f95c4f7 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -30,10 +30,10 @@ static char *localize_crash_time(const char *timestr) { long time = xatou(timestr); char timeloc[256]; - int success = strftime(timeloc, 128, "%c", localtime(&time)); + int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time)); if (!success) - error_msg_and_die("Error while converting time to string"); - return xasprintf("%s", timeloc); + error_msg_and_die("Error while converting time '%s' to string", timestr); + return xstrdup(timeloc); } /** Prints basic information about a crash to stdout. */ @@ -41,7 +41,7 @@ static void print_crash(crash_data_t *crash_data) { /* Create a localized string from crash time. */ const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME); - const char *timeloc = localize_crash_time(timestr); + char *timeloc = localize_crash_time(timestr); printf(_("\tCrash dump : %s\n" "\tUID : %s\n" @@ -57,7 +57,7 @@ static void print_crash(crash_data_t *crash_data) get_crash_item_content_or_NULL(crash_data, FILENAME_COUNT) ); - free((void *)timeloc); + free(timeloc); /* Print the hostname if it's available. */ const char *hostname = get_crash_item_content_or_NULL(crash_data, FILENAME_HOSTNAME); @@ -93,7 +93,7 @@ static void print_crash_list(vector_of_crash_data_t *crash_list, bool include_re static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) { const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME); - const char *timeloc = localize_crash_time(timestr); + char *timeloc = localize_crash_time(timestr); printf(_("Dump directory: %s\n" "Last crash: %s\n" @@ -116,7 +116,7 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) get_crash_item_content_or_die(crash_data, FILENAME_REASON) ); - free((void *)timeloc); + free(timeloc); /* Print optional fields only if they are available */ @@ -154,45 +154,6 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) } } -/** - * Converts crash reference from user's input to crash dump dir name. - * The returned string must be released by caller. - */ -static char *guess_crash_id(const char *str) -{ - vector_of_crash_data_t *ci = call_GetCrashInfos(); - unsigned num_crashinfos = ci->len; - if (str[0] == '@') /* "--report @N" syntax */ - { - unsigned position = xatoi_positive(str + 1); - if (position >= num_crashinfos) - error_msg_and_die("There are only %u crash infos", num_crashinfos); - crash_data_t *info = get_crash_data(ci, position); - char *res = xstrdup(get_crash_item_content_or_die(info, CD_DUMPDIR)); - free_vector_of_crash_data(ci); - return res; - } - - unsigned len = strlen(str); - unsigned ii; - char *result = NULL; - for (ii = 0; ii < num_crashinfos; ii++) - { - crash_data_t *info = get_crash_data(ci, ii); - const char *this_dir = get_crash_item_content_or_die(info, CD_DUMPDIR); - if (strncmp(str, this_dir, len) == 0) - { - if (result) - error_msg_and_die("Crash prefix '%s' is not unique", str); - result = xstrdup(this_dir); - } - } - free_vector_of_crash_data(ci); - if (!result) - error_msg_and_die("Crash dump directory '%s' not found", str); - return result; -} - /* Program options */ enum { @@ -247,9 +208,8 @@ static void usage(char *argv0) /* Message has embedded tabs. */ printf(_("Usage: %s [OPTION]\n\n" "Startup:\n" - " -V, --version display the version of %s and exit\n" + " -V, --version display the version and exit\n" " -v, --verbose increase verbosity\n" - " -?, --help print this help\n\n" "Actions:\n" " -l, --list print a list of all crashes which are not yet reported\n" " -f, --full print a list of all crashes, including the already reported ones\n" @@ -262,14 +222,14 @@ static void usage(char *argv0) " a name of dump directory, or\n" " @N - N'th crash (as displayed by --list --full) will be acted upon\n" ), - name, name); + name); exit(1); } int main(int argc, char** argv) { - const char* crash_id = NULL; + char *dump_dir_name = NULL; int op = -1; bool full = false; bool always = false; @@ -286,16 +246,16 @@ int main(int argc, char** argv) /* Do not use colons, arguments are handled after parsing all options. */ int c = getopt_long(argc, argv, "?Vvrdlfyib", longopts, NULL); -#define SET_OP(newop) \ - if (op != -1 && op != newop) \ - { \ - error_msg(_("You must specify exactly one operation")); \ - return 1; \ - } \ - op = newop; +#define SET_OP(newop) \ + do { \ + if (op != -1 && op != newop) \ + error_msg_and_die(_("You must specify exactly one operation")); \ + op = newop; \ + } while (0) switch (c) { + case -1: goto end_of_arg_parsing; case 'r': SET_OP(OPT_REPORT); break; case 'd': SET_OP(OPT_DELETE); break; case 'l': SET_OP(OPT_GET_LIST); break; @@ -304,22 +264,20 @@ int main(int argc, char** argv) case 'y': always = true; break; case 'b': backtrace = true; break; case 'v': g_verbose++; break; - case -1: /* end of options */ break; - default: /* some error */ - case '?': - usage(argv[0]); /* exits app */ case 'V': printf("%s "VERSION"\n", progname(argv[0])); return 0; + case '?': + default: /* some error */ + usage(argv[0]); /* exits app */ } #undef SET_OP - if (c == -1) - break; } + end_of_arg_parsing: ; /* Handle option arguments. */ - int arg_count = argc - optind; - switch (arg_count) + argc -= optind; + switch (argc) { case 0: if (op == OPT_REPORT || op == OPT_DELETE || op == OPT_INFO) @@ -328,7 +286,7 @@ int main(int argc, char** argv) case 1: if (op != OPT_REPORT && op != OPT_DELETE && op != OPT_INFO) usage(argv[0]); - crash_id = argv[optind]; + dump_dir_name = argv[optind]; break; default: usage(argv[0]); @@ -364,43 +322,18 @@ int main(int argc, char** argv) } case OPT_REPORT: { - int flags = CLI_REPORT_SILENT_IF_NOT_FOUND; - if (always) - flags |= CLI_REPORT_BATCH; - exitcode = report(crash_id, flags); - if (exitcode == -1) /* no such crash_id */ - { - crash_id = guess_crash_id(crash_id); - exitcode = report(crash_id, always ? CLI_REPORT_BATCH : 0); - if (exitcode == -1) - { - error_msg("Crash '%s' not found", crash_id); - free((void *)crash_id); - xfunc_die(); - } - - free((void *)crash_id); - } + exitcode = report(dump_dir_name, (always ? CLI_REPORT_BATCH : 0)); + if (exitcode == -1) + error_msg_and_die("Crash '%s' not found", dump_dir_name); break; } case OPT_DELETE: { - exitcode = call_DeleteDebugDump(crash_id); + exitcode = call_DeleteDebugDump(dump_dir_name); if (exitcode == ENOENT) - { - crash_id = guess_crash_id(crash_id); - exitcode = call_DeleteDebugDump(crash_id); - if (exitcode == ENOENT) - { - error_msg("Crash '%s' not found", crash_id); - free((void *)crash_id); - xfunc_die(); - } - - free((void *)crash_id); - } + error_msg_and_die("Crash '%s' not found", dump_dir_name); if (exitcode != 0) - error_msg_and_die("Can't delete debug dump '%s'", crash_id); + error_msg_and_die("Can't delete debug dump '%s'", dump_dir_name); break; } case OPT_INFO: @@ -408,20 +341,9 @@ int main(int argc, char** argv) int old_logmode = logmode; logmode = 0; - crash_data_t *crash_data = call_CreateReport(crash_id); - if (!crash_data) /* no such crash_id */ - { - crash_id = guess_crash_id(crash_id); - crash_data = call_CreateReport(crash_id); - if (!crash_data) - { - error_msg("Crash '%s' not found", crash_id); - free((void *)crash_id); - xfunc_die(); - } - - free((void *)crash_id); - } + crash_data_t *crash_data = call_CreateReport(dump_dir_name); + if (!crash_data) + error_msg_and_die("Crash '%s' not found", dump_dir_name); logmode = old_logmode; diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 5c1d7848..41a600c6 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -5,17 +5,17 @@ abrt_cli_SOURCES = \ run-command.h run-command.c \ report.h report.cpp \ dbus.h dbus.cpp - abrt_cli_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DVAR_RUN=\"$(VAR_RUN)\" \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ $(ENABLE_SOCKET_OR_DBUS) \ $(DBUS_CFLAGS) $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror # $(GTK_CFLAGS) - abrt_cli_LDADD = \ ../lib/libreport.la \ ../lib/libabrt_dbus.la \ 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()); diff --git a/src/cli/report.h b/src/cli/report.h index 8a851b8e..d947b6b2 100644 --- a/src/cli/report.h +++ b/src/cli/report.h @@ -18,11 +18,10 @@ #ifndef ABRT_CLI_REPORT_H #define ABRT_CLI_REPORT_H -/* Reports the crash with corresponding uuid over DBus. */ +/* Report the crash */ enum { CLI_REPORT_BATCH = 1 << 0, - CLI_REPORT_SILENT_IF_NOT_FOUND = 1 << 1, }; -int report(const char *uuid, int flags); +int report(const char *dump_dir_name, int flags); #endif -- 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/CLI.cpp | 134 +++++++++++++++----- src/cli/dbus.cpp | 150 +++-------------------- src/cli/dbus.h | 38 ------ src/cli/report.cpp | 350 ++++++++++++++++++++++++++++++++++++++--------------- src/cli/report.h | 2 + 5 files changed, 370 insertions(+), 304 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 5f95c4f7..9af1cbc7 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -36,6 +36,51 @@ static char *localize_crash_time(const char *timestr) return xstrdup(timeloc); } +static crash_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); +// char *events = list_possible_events(dd, NULL, ""); + dd_close(dd); +// add_to_crash_data_ext(crash_data, CD_EVENTS, events, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); +// free(events); + add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); + + return crash_data; +} + +static void GetCrashInfos(vector_of_crash_data_t *retval, const char *dir_name) +{ + VERB1 log("Loading dumps from '%s'", dir_name); + + DIR *dir = opendir(dir_name); + if (dir != NULL) + { + struct dirent *dent; + while ((dent = readdir(dir)) != NULL) + { + if (dot_or_dotdot(dent->d_name)) + continue; /* skip "." and ".." */ + + char *dump_dir_name = concat_path_file(dir_name, dent->d_name); + + struct stat statbuf; + 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); + } + free(dump_dir_name); + } + closedir(dir); + } +} + /** Prints basic information about a crash to stdout. */ static void print_crash(crash_data_t *crash_data) { @@ -200,35 +245,41 @@ static const char *progname(const char *argv0) * Prints abrt-cli version and some help text. * Then exits the program with return value 1. */ -static void usage(char *argv0) +static void print_usage_and_die(char *argv0) { const char *name = progname(argv0); printf("%s "VERSION"\n\n", name); /* Message has embedded tabs. */ - printf(_("Usage: %s [OPTION]\n\n" - "Startup:\n" - " -V, --version display the version and exit\n" - " -v, --verbose increase verbosity\n" - "Actions:\n" - " -l, --list print a list of all crashes which are not yet reported\n" - " -f, --full print a list of all crashes, including the already reported ones\n" - " -r, --report CRASH_ID create and send a report\n" - " -y, --always create and send a report without asking\n" - " -d, --delete CRASH_ID remove a crash\n" - " -i, --info CRASH_ID print detailed information about a crash\n" - " -b, --backtrace print detailed information about a crash including backtrace\n" - "CRASH_ID can be:\n" - " a name of dump directory, or\n" - " @N - N'th crash (as displayed by --list --full) will be acted upon\n" + printf(_( + "Usage: %s -l[f] [-D BASE_DIR]...]\n" + " or: %s -r[y] CRASH_DIR\n" + " or: %s -i[b] CRASH_DIR\n" + " or: %s -d CRASH_DIR\n" + "\n" + " -l, --list List not yet reported crashes\n" + " -f, --full List all crashes\n" + " -D BASE_DIR Directory to list crashes from\n" + " (default: -D $HOME/abrt/spool -D %s)\n" + "\n" + " -r, --report Send a report about CRASH_DIR\n" + " -y, --always ...without editing and asking\n" + " -i, --info Print detailed information about CRASH_DIR\n" + " -b, --backtrace ...including backtrace\n" + " -d, --delete Remove CRASH_DIR\n" + "\n" + " -V, --version Display version and exit\n" + " -v, --verbose Be verbose\n" ), - name); - + name, name, name, name, + DEBUG_DUMPS_DIR + ); exit(1); } int main(int argc, char** argv) { + GList *D_list = NULL; char *dump_dir_name = NULL; int op = -1; bool full = false; @@ -264,12 +315,15 @@ int main(int argc, char** argv) case 'y': always = true; break; case 'b': backtrace = true; break; case 'v': g_verbose++; break; + case 'D': + D_list = g_list_append(D_list, optarg); + break; case 'V': printf("%s "VERSION"\n", progname(argv[0])); return 0; case '?': default: /* some error */ - usage(argv[0]); /* exits app */ + print_usage_and_die(argv[0]); /* exits app */ } #undef SET_OP } @@ -281,15 +335,15 @@ int main(int argc, char** argv) { case 0: if (op == OPT_REPORT || op == OPT_DELETE || op == OPT_INFO) - usage(argv[0]); + print_usage_and_die(argv[0]); break; case 1: if (op != OPT_REPORT && op != OPT_DELETE && op != OPT_INFO) - usage(argv[0]); + print_usage_and_die(argv[0]); dump_dir_name = argv[optind]; break; default: - usage(argv[0]); + print_usage_and_die(argv[0]); } /* Check if we have an operation. @@ -300,8 +354,7 @@ int main(int argc, char** argv) (backtrace && op != OPT_INFO) || op == -1) { - usage(argv[0]); - return 1; + print_usage_and_die(argv[0]); } DBusError err; @@ -315,7 +368,20 @@ int main(int argc, char** argv) { case OPT_GET_LIST: { - vector_of_crash_data_t *ci = call_GetCrashInfos(); + if (!D_list) + { + char *home = getenv("HOME"); + if (home) + D_list = g_list_append(D_list, concat_path_file(home, "abrt/spool")); + D_list = g_list_append(D_list, (void*)DEBUG_DUMPS_DIR); + } + vector_of_crash_data_t *ci = new_vector_of_crash_data(); + while (D_list) + { + char *dir = (char *)D_list->data; + GetCrashInfos(ci, dir); + D_list = g_list_remove(D_list, dir); + } print_crash_list(ci, full); free_vector_of_crash_data(ci); break; @@ -338,14 +404,16 @@ int main(int argc, char** argv) } case OPT_INFO: { - int old_logmode = logmode; - logmode = 0; - - crash_data_t *crash_data = call_CreateReport(dump_dir_name); - if (!crash_data) - error_msg_and_die("Crash '%s' not found", dump_dir_name); - - logmode = old_logmode; + if (run_analyze_event(dump_dir_name) != 0) + return 1; + + /* 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); + dd_close(dd); + add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); print_crash_info(crash_data, backtrace); free_crash_data(crash_data); diff --git a/src/cli/dbus.cpp b/src/cli/dbus.cpp index 6c98ec4e..9c2bfbd6 100644 --- a/src/cli/dbus.cpp +++ b/src/cli/dbus.cpp @@ -121,72 +121,21 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) } } -vector_of_crash_data_t *call_GetCrashInfos() -{ - DBusMessage* msg = new_call_msg(__func__ + 5); - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - vector_of_crash_data_t *argout = NULL; - int r = load_vector_of_crash_data(&in_iter, &argout); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return argout; -} - -crash_data_t *call_CreateReport(const char* crash_id) -{ - DBusMessage* msg = new_call_msg(__func__ + 5); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &crash_id, - DBUS_TYPE_INVALID); - - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - crash_data_t *argout = NULL; - int r = load_crash_data(&in_iter, &argout); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return argout; -} - -report_status_t call_Report(crash_data_t *report, - const vector_string_t& reporters, - GHashTable *plugins) +void handle_dbus_err(bool error_flag, DBusError *err) { - DBusMessage* msg = new_call_msg(__func__ + 5); - DBusMessageIter out_iter; - dbus_message_iter_init_append(msg, &out_iter); - - /* parameter #1: report data */ - store_crash_data(&out_iter, report); - /* parameter #2: reporters to use */ - store_val(&out_iter, reporters); - /* parameter #3 (opt): plugin config */ - if (g_hash_table_size(plugins)) - store_hash_table_map_string_t(&out_iter, plugins); - - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - report_status_t result; - int r = load_val(&in_iter, result); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return result; + if (dbus_error_is_set(err)) + { + error_msg("dbus error: %s", err->message); + /* dbus_error_free(&err); */ + error_flag = true; + } + if (!error_flag) + return; + error_msg_and_die( + "error requesting DBus name %s, possible reasons: " + "abrt run by non-root; dbus config is incorrect; " + "or dbus daemon needs to be restarted to reload dbus config", + ABRTD_DBUS_NAME); } int32_t call_DeleteDebugDump(const char* crash_id) @@ -209,74 +158,3 @@ int32_t call_DeleteDebugDump(const char* crash_id) dbus_message_unref(reply); return result; } - -map_map_string_t call_GetPluginsInfo() -{ - DBusMessage *msg = new_call_msg(__func__ + 5); - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - map_map_string_t argout; - int r = load_val(&in_iter, argout); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return argout; -} - -map_plugin_settings_t call_GetPluginSettings(const char *name) -{ - DBusMessage *msg = new_call_msg(__func__ + 5); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_INVALID); - - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - map_string_t argout; - int r = load_val(&in_iter, argout); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return argout; -} - -map_map_string_t call_GetSettings() -{ - DBusMessage *msg = new_call_msg(__func__ + 5); - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - map_map_string_t argout; - int r = load_val(&in_iter, argout); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return argout; -} - -void handle_dbus_err(bool error_flag, DBusError *err) -{ - if (dbus_error_is_set(err)) - { - error_msg("dbus error: %s", err->message); - /* dbus_error_free(&err); */ - error_flag = true; - } - if (!error_flag) - return; - error_msg_and_die( - "error requesting DBus name %s, possible reasons: " - "abrt run by non-root; dbus config is incorrect; " - "or dbus daemon needs to be restarted to reload dbus config", - ABRTD_DBUS_NAME); -} diff --git a/src/cli/dbus.h b/src/cli/dbus.h index e2e763c2..efaceca8 100644 --- a/src/cli/dbus.h +++ b/src/cli/dbus.h @@ -23,46 +23,8 @@ extern DBusConnection* s_dbus_conn; -vector_of_crash_data_t *call_GetCrashInfos(); - -crash_data_t *call_CreateReport(const char *crash_id); - -/** Sends report using enabled Reporter plugins. - * @param report - * The report sent to Reporter plugins. - * @param reporters - * List of names of Reporters which should be called. - * @param plugins - * Optional settings for Reporter plugins, can be empty. - * Format: plugins["PluginName"]["SettingsKey"] = "SettingsValue" - * If it contains settings for some plugin, it must contain _all fields_ - * obtained by call_GetPluginSettings, otherwise the plugin might ignore - * the settings. - */ -report_status_t call_Report(crash_data_t *report, - const vector_string_t& reporters, - GHashTable *plugins); - int32_t call_DeleteDebugDump(const char* crash_id); -/* Gets basic data about all installed plugins. - * @todo - * Return more semantically structured output - maybe a struct instead of a map. - */ -map_map_string_t call_GetPluginsInfo(); - -/** Gets default plugin settings. - * @param name - * Corresponds to name obtained from call_GetPluginsInfo. - */ -map_plugin_settings_t call_GetPluginSettings(const char *name); - -/** Gets global daemon settings. - * @todo - * Return more semantically structured output - maybe a struct instead of a map. - */ -map_map_string_t call_GetSettings(); - void handle_dbus_err(bool error_flag, DBusError *err); #endif 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; } diff --git a/src/cli/report.h b/src/cli/report.h index d947b6b2..80c0b9f2 100644 --- a/src/cli/report.h +++ b/src/cli/report.h @@ -18,6 +18,8 @@ #ifndef ABRT_CLI_REPORT_H #define ABRT_CLI_REPORT_H +int run_analyze_event(const char *dump_dir_name); + /* Report the crash */ enum { CLI_REPORT_BATCH = 1 << 0, -- 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') 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 55ae0eaea8684aa78089bbd0c2116e0c8cb25585 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Feb 2011 16:04:30 +0100 Subject: abrt-cli -r DIR: copy non-writable DIR into $HOME/abrt/spool Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 8 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 9af1cbc7..af85a9e9 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -38,7 +38,7 @@ static char *localize_crash_time(const char *timestr) static crash_data_t *FillCrashInfo(const char *dump_dir_name) { - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY); if (!dd) return NULL; @@ -199,6 +199,46 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) } } +static struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name) +{ + const char *base_name = strrchr(dump_dir_name, '/'); + if (base_name) + base_name++; + else + base_name = dump_dir_name; + + struct dump_dir *dd_dst; + unsigned count = 100; + char *dst_dir_name = concat_path_file(base_dir, base_name); + while (1) + { + dd_dst = dd_create(dst_dir_name, (uid_t)-1); + free(dst_dir_name); + if (dd_dst) + break; + if (--count == 0) + { + error_msg("Can't create new dump dir in '%s'", base_dir); + goto ret; + } + struct timeval tv; + gettimeofday(&tv, NULL); + dst_dir_name = xasprintf("%s/%s.%u", base_dir, base_name, (int)tv.tv_usec); + } + + log("Creating copy in '%s'", dd_dst->dd_dir); + if (copy_file_recursive(dump_dir_name, dd_dst->dd_dir) < 0) + { + /* error. copy_file_recursive already emitted error message */ + dd_close(dd_dst); + xfunc_die(); + } + + ret: + return dd_dst; +} + + /* Program options */ enum { @@ -329,6 +369,14 @@ int main(int argc, char** argv) } end_of_arg_parsing: ; + if (!D_list) + { + char *home = getenv("HOME"); + if (home) + D_list = g_list_append(D_list, concat_path_file(home, "abrt/spool")); + D_list = g_list_append(D_list, (void*)DEBUG_DUMPS_DIR); + } + /* Handle option arguments. */ argc -= optind; switch (argc) @@ -368,13 +416,6 @@ int main(int argc, char** argv) { case OPT_GET_LIST: { - if (!D_list) - { - char *home = getenv("HOME"); - if (home) - D_list = g_list_append(D_list, concat_path_file(home, "abrt/spool")); - D_list = g_list_append(D_list, (void*)DEBUG_DUMPS_DIR); - } vector_of_crash_data_t *ci = new_vector_of_crash_data(); while (D_list) { @@ -388,6 +429,23 @@ int main(int argc, char** argv) } case OPT_REPORT: { + struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); + if (!dd) + break; + int readonly = !dd->locked; + dd_close(dd); + if (readonly) + { + log("'%s' is not writable", dump_dir_name); + /* D_list can't be NULL here */ + struct dump_dir *dd_copy = steal_directory((char *)D_list->data, dump_dir_name); + if (dd_copy) + { + dump_dir_name = xstrdup(dd_copy->dd_dir); + dd_close(dd_copy); + } + } + exitcode = report(dump_dir_name, (always ? CLI_REPORT_BATCH : 0)); if (exitcode == -1) error_msg_and_die("Crash '%s' not found", dump_dir_name); -- cgit From aa588deee9b47db4ddc1070581f5c3690139095d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Feb 2011 14:32:33 +0100 Subject: cli: change user's abrt dir from $HOME/abrt to $HOME/.abrt Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index af85a9e9..2ac63422 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -300,7 +300,7 @@ static void print_usage_and_die(char *argv0) " -l, --list List not yet reported crashes\n" " -f, --full List all crashes\n" " -D BASE_DIR Directory to list crashes from\n" - " (default: -D $HOME/abrt/spool -D %s)\n" + " (default: -D $HOME/.abrt/spool -D %s)\n" "\n" " -r, --report Send a report about CRASH_DIR\n" " -y, --always ...without editing and asking\n" @@ -373,7 +373,7 @@ int main(int argc, char** argv) { char *home = getenv("HOME"); if (home) - D_list = g_list_append(D_list, concat_path_file(home, "abrt/spool")); + D_list = g_list_append(D_list, concat_path_file(home, ".abrt/spool")); D_list = g_list_append(D_list, (void*)DEBUG_DUMPS_DIR); } -- cgit From 6eb815b57676f75ed5205590409f384244b2580a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Feb 2011 15:35:35 +0100 Subject: abrt-cli: delete half-copied dir on dir copy error Also, make -d DIR to try deletion itself before resorting to abrtd Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 2ac63422..59c145f5 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -230,7 +230,8 @@ static struct dump_dir *steal_directory(const char *base_dir, const char *dump_d if (copy_file_recursive(dump_dir_name, dd_dst->dd_dir) < 0) { /* error. copy_file_recursive already emitted error message */ - dd_close(dd_dst); + /* Don't leave half-copied dir lying around */ + dd_delete(dd_dst); xfunc_die(); } @@ -453,6 +454,18 @@ int main(int argc, char** argv) } case OPT_DELETE: { + /* Try to delete it ourselves */ + struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); + if (dd) + { + if (dd->locked) /* it is not readonly */ + { + dd_delete(dd); + break; + } + dd_close(dd); + } + /* Ask abrtd to do it for us */ exitcode = call_DeleteDebugDump(dump_dir_name); if (exitcode == ENOENT) error_msg_and_die("Crash '%s' not found", dump_dir_name); -- cgit From 0df5e344cdf94ffb1d3ef471cc7be5d6a9699732 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Feb 2011 15:37:47 +0100 Subject: abrt-cli: suppress errors when we try to read dump dirs which aren't ours $ abrt-cli -lf Can't create lock file '/var/spool/abrt/ccpp-1296609283-15129/.lock': Permission denied Can't access '/var/spool/abrt/ccpp-1296609283-15129': Permission denied Can't create lock file '/var/spool/abrt/ccpp-1294848465-26639/.lock': Permission denied Can't access '/var/spool/abrt/ccpp-1294848465-26639': Permission denied Can't create lock file '/var/spool/abrt/ccpp-1294848466-26657/.lock': Permission denied Can't access '/var/spool/abrt/ccpp-1294848466-26657': Permission denied ^^^^^^^^^^^^^^^^^^^^ these messages 0. Crash dump : /home/test/.abrt/spool/ccpp-1296609283-15129.868047 UID : 0 Package : coreutils-8.4-10.fc13 Executable : /bin/sleep Crash Time : Wed 02 Feb 2011 02:14:43 AM CET Crash Count: 1 Hostname : dhcp-25-227.brq.redhat.com 1. Crash dump : /home/test/.abrt/spool/ccpp-1296609283-15129 UID : 0 Package : coreutils-8.4-10.fc13 Executable : /bin/sleep Crash Time : Wed 02 Feb 2011 02:14:43 AM CET Crash Count: 1 Hostname : dhcp-25-227.brq.redhat.com Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 59c145f5..527d5de9 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -38,7 +38,11 @@ static char *localize_crash_time(const char *timestr) static crash_data_t *FillCrashInfo(const char *dump_dir_name) { + int sv_logmode = logmode; + logmode = 0; /* suppress EPERM/EACCES errors in opendir */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY); + logmode = sv_logmode; + if (!dd) return NULL; -- 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/CLI.cpp | 2 +- src/cli/report.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 527d5de9..e322e7cd 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -160,7 +160,7 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) get_crash_item_content_or_die(crash_data, FILENAME_PACKAGE), get_crash_item_content_or_die(crash_data, FILENAME_CMDLINE), get_crash_item_content_or_die(crash_data, FILENAME_EXECUTABLE), - get_crash_item_content_or_die(crash_data, FILENAME_RELEASE), + get_crash_item_content_or_die(crash_data, FILENAME_OS_RELEASE), get_crash_item_content_or_die(crash_data, FILENAME_KERNEL), get_crash_item_content_or_die(crash_data, FILENAME_REASON) ); 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/CLI.cpp | 15 +---- src/cli/Makefile.am | 3 +- src/cli/dbus.cpp | 160 ---------------------------------------------------- src/cli/dbus.h | 30 ---------- src/cli/report.cpp | 1 - 5 files changed, 4 insertions(+), 205 deletions(-) delete mode 100644 src/cli/dbus.cpp delete mode 100644 src/cli/dbus.h (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index e322e7cd..0e902b9e 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -21,9 +21,7 @@ #include #include "abrtlib.h" #include "abrt_dbus.h" -#include "dbus_common.h" #include "report.h" -#include "dbus.h" /** Creates a localized string from crash time. */ static char *localize_crash_time(const char *timestr) @@ -410,11 +408,6 @@ int main(int argc, char** argv) print_usage_and_die(argv[0]); } - DBusError err; - dbus_error_init(&err); - s_dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); - handle_dbus_err(s_dbus_conn == NULL, &err); - /* Do the selected operation. */ int exitcode = 0; switch (op) @@ -469,12 +462,10 @@ int main(int argc, char** argv) } dd_close(dd); } + /* Ask abrtd to do it for us */ - exitcode = call_DeleteDebugDump(dump_dir_name); - if (exitcode == ENOENT) - error_msg_and_die("Crash '%s' not found", dump_dir_name); - if (exitcode != 0) - error_msg_and_die("Can't delete debug dump '%s'", dump_dir_name); + exitcode = connect_to_abrtd_and_call_DeleteDebugDump(dump_dir_name); + break; } case OPT_INFO: diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 41a600c6..0a5c6e1a 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -3,8 +3,7 @@ bin_PROGRAMS = abrt-cli abrt_cli_SOURCES = \ CLI.cpp \ run-command.h run-command.c \ - report.h report.cpp \ - dbus.h dbus.cpp + report.h report.cpp abrt_cli_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ diff --git a/src/cli/dbus.cpp b/src/cli/dbus.cpp deleted file mode 100644 index 9c2bfbd6..00000000 --- a/src/cli/dbus.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - 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. -*/ -#include "dbus.h" -#include "dbus_common.h" - -DBusConnection* s_dbus_conn; - -/* - * DBus member calls - */ - -/* helpers */ -static DBusMessage* new_call_msg(const char* method) -{ - DBusMessage* msg = dbus_message_new_method_call(ABRTD_DBUS_NAME, ABRTD_DBUS_PATH, ABRTD_DBUS_IFACE, method); - if (!msg) - die_out_of_memory(); - return msg; -} - -static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) -{ - dbus_uint32_t serial; - if (TRUE != dbus_connection_send(s_dbus_conn, msg, &serial)) - error_msg_and_die("Error sending DBus message"); - dbus_message_unref(msg); - - while (true) - { - DBusMessage *received = dbus_connection_pop_message(s_dbus_conn); - if (!received) - { - if (FALSE == dbus_connection_read_write(s_dbus_conn, -1)) - error_msg_and_die("dbus connection closed"); - continue; - } - - int tp = dbus_message_get_type(received); - const char *error_str = dbus_message_get_error_name(received); -#if 0 - /* Debugging */ - printf("type:%u (CALL:%u, RETURN:%u, ERROR:%u, SIGNAL:%u)\n", tp, - DBUS_MESSAGE_TYPE_METHOD_CALL, - DBUS_MESSAGE_TYPE_METHOD_RETURN, - DBUS_MESSAGE_TYPE_ERROR, - DBUS_MESSAGE_TYPE_SIGNAL - ); - const char *sender = dbus_message_get_sender(received); - if (sender) - printf("sender: %s\n", sender); - const char *path = dbus_message_get_path(received); - if (path) - printf("path: %s\n", path); - const char *member = dbus_message_get_member(received); - if (member) - printf("member: %s\n", member); - const char *interface = dbus_message_get_interface(received); - if (interface) - printf("interface: %s\n", interface); - const char *destination = dbus_message_get_destination(received); - if (destination) - printf("destination: %s\n", destination); - if (error_str) - printf("error: '%s'\n", error_str); -#endif - - DBusError err; - dbus_error_init(&err); - - if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Update")) - { - const char *update_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &update_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Update message: arguments mismatch"); - } - printf(">> %s\n", update_msg); - } - else if (dbus_message_is_signal(received, ABRTD_DBUS_IFACE, "Warning")) - { - const char *warning_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &warning_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Warning message: arguments mismatch"); - } - log(">! %s\n", warning_msg); - } - else - if (tp == DBUS_MESSAGE_TYPE_METHOD_RETURN - && dbus_message_get_reply_serial(received) == serial - ) { - return received; - } - else - if (tp == DBUS_MESSAGE_TYPE_ERROR - && dbus_message_get_reply_serial(received) == serial - ) { - error_msg_and_die("dbus call returned error: '%s'", error_str); - } - - dbus_message_unref(received); - } -} - -void handle_dbus_err(bool error_flag, DBusError *err) -{ - if (dbus_error_is_set(err)) - { - error_msg("dbus error: %s", err->message); - /* dbus_error_free(&err); */ - error_flag = true; - } - if (!error_flag) - return; - error_msg_and_die( - "error requesting DBus name %s, possible reasons: " - "abrt run by non-root; dbus config is incorrect; " - "or dbus daemon needs to be restarted to reload dbus config", - ABRTD_DBUS_NAME); -} - -int32_t call_DeleteDebugDump(const char* crash_id) -{ - DBusMessage* msg = new_call_msg(__func__ + 5); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &crash_id, - DBUS_TYPE_INVALID); - - DBusMessage *reply = send_get_reply_and_unref(msg); - - DBusMessageIter in_iter; - dbus_message_iter_init(reply, &in_iter); - - int32_t result; - int r = load_val(&in_iter, result); - if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ - error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); - - dbus_message_unref(reply); - return result; -} diff --git a/src/cli/dbus.h b/src/cli/dbus.h deleted file mode 100644 index efaceca8..00000000 --- a/src/cli/dbus.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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_CLI_DBUS_H -#define ABRT_CLI_DBUS_H - -#include "abrt_dbus.h" -#include "abrt_crash_data.h" - -extern DBusConnection* s_dbus_conn; - -int32_t call_DeleteDebugDump(const char* crash_id); - -void handle_dbus_err(bool error_flag, DBusError *err); - -#endif 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/CLI.cpp | 8 +++----- src/cli/report.cpp | 12 ------------ 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 0e902b9e..2d236e5c 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -45,11 +45,8 @@ static crash_data_t *FillCrashInfo(const char *dump_dir_name) return NULL; crash_data_t *crash_data = create_crash_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, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); -// free(events); - add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); + add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); return crash_data; } @@ -479,7 +476,8 @@ int main(int argc, char** argv) return -1; crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); - add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_SYS + CD_FLAG_ISNOTEDITABLE); + add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, + CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE); print_crash_info(crash_data, backtrace); free_crash_data(crash_data); 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 From 406b2cffd5e9120bea74ab01479039714ce9e2d5 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Thu, 17 Feb 2011 15:44:20 +0100 Subject: move steal_directory() into libreport --- src/cli/CLI.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 2d236e5c..b0d6bdf6 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -198,47 +198,6 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace) } } -static struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name) -{ - const char *base_name = strrchr(dump_dir_name, '/'); - if (base_name) - base_name++; - else - base_name = dump_dir_name; - - struct dump_dir *dd_dst; - unsigned count = 100; - char *dst_dir_name = concat_path_file(base_dir, base_name); - while (1) - { - dd_dst = dd_create(dst_dir_name, (uid_t)-1); - free(dst_dir_name); - if (dd_dst) - break; - if (--count == 0) - { - error_msg("Can't create new dump dir in '%s'", base_dir); - goto ret; - } - struct timeval tv; - gettimeofday(&tv, NULL); - dst_dir_name = xasprintf("%s/%s.%u", base_dir, base_name, (int)tv.tv_usec); - } - - log("Creating copy in '%s'", dd_dst->dd_dir); - if (copy_file_recursive(dump_dir_name, dd_dst->dd_dir) < 0) - { - /* error. copy_file_recursive already emitted error message */ - /* Don't leave half-copied dir lying around */ - dd_delete(dd_dst); - xfunc_die(); - } - - ret: - return dd_dst; -} - - /* Program options */ enum { -- cgit From c00b15ff52f89ada9770453580e5828fd466e9c5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Feb 2011 15:55:44 +0100 Subject: change stealing semantics from copy to move Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index b0d6bdf6..593ed6ee 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -395,6 +395,7 @@ int main(int argc, char** argv) struct dump_dir *dd_copy = steal_directory((char *)D_list->data, dump_dir_name); if (dd_copy) { + delete_dump_dir_possibly_using_abrtd(dump_dir_name); dump_dir_name = xstrdup(dd_copy->dd_dir); dd_close(dd_copy); } @@ -407,21 +408,7 @@ int main(int argc, char** argv) } case OPT_DELETE: { - /* Try to delete it ourselves */ - struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY); - if (dd) - { - if (dd->locked) /* it is not readonly */ - { - dd_delete(dd); - break; - } - dd_close(dd); - } - - /* Ask abrtd to do it for us */ - exitcode = connect_to_abrtd_and_call_DeleteDebugDump(dump_dir_name); - + exitcode = delete_dump_dir_possibly_using_abrtd(dump_dir_name); break; } case OPT_INFO: -- cgit From 3a6d12fcd182c0de13800fe463482d6a4408f885 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 17:23:50 +0100 Subject: dump_dir API: rename dd_dir field to dd_dirname Signed-off-by: Denys Vlasenko --- src/cli/CLI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cli') diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 593ed6ee..5ece3171 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -396,7 +396,7 @@ int main(int argc, char** argv) if (dd_copy) { delete_dump_dir_possibly_using_abrtd(dump_dir_name); - dump_dir_name = xstrdup(dd_copy->dd_dir); + dump_dir_name = xstrdup(dd_copy->dd_dirname); dd_close(dd_copy); } } -- cgit