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/plugins/Makefile.am | 7 +++- src/plugins/abrt-action-bugzilla.cpp | 71 +++++++++++++++++----------------- src/plugins/abrt-action-kerneloops.cpp | 7 ++-- src/plugins/abrt-action-mailx.cpp | 20 ++++++---- src/plugins/abrt-action-print.cpp | 6 +-- src/plugins/abrt-action-rhtsupport.cpp | 41 +++++++++++--------- 6 files changed, 83 insertions(+), 69 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index a7790e71..fb91fc1e 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -56,7 +56,8 @@ libCCpp_la_CPPFLAGS = -Wall -Werror \ -I$(UTILS_PATH) \ -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DLOCALSTATEDIR='"$(localstatedir)"' + -DLOCALSTATEDIR='"$(localstatedir)"' \ + $(GLIB_CFLAGS) # -DHOSTILE_KERNEL # KerneloopsScanner @@ -89,6 +90,7 @@ abrt_action_analyze_c_CPPFLAGS = \ -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_c_LDADD = \ @@ -107,6 +109,7 @@ abrt_action_analyze_python_CPPFLAGS = \ -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_python_LDADD = \ @@ -125,6 +128,7 @@ abrt_action_analyze_oops_CPPFLAGS = \ -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_oops_LDADD = \ @@ -143,6 +147,7 @@ abrt_action_generate_backtrace_CPPFLAGS = \ -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_generate_backtrace_LDADD = \ diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index b396e453..b215735b 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -112,8 +112,8 @@ struct ctx: public abrt_xmlrpc_conn { xmlrpc_int32 get_bug_dup_id(xmlrpc_value* result_xml); void get_bug_cc(xmlrpc_value* result_xml, struct bug_info* bz); int add_plus_one_cc(xmlrpc_int32 bug_id, const char* login); - xmlrpc_int32 new_bug(const map_crash_data_t& pCrashData, int depend_on_bugno); - int add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData); + xmlrpc_int32 new_bug(crash_data_t *crash_data, int depend_on_bugno); + int add_attachments(const char* bug_id_str, crash_data_t *crash_data); int get_bug_info(struct bug_info* bz, xmlrpc_int32 bug_id); int add_comment(xmlrpc_int32 bug_id, const char* comment, bool is_private); @@ -442,17 +442,17 @@ static const char *tainted_string(unsigned tainted) return taint_warnings[idx]; } -xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugno) +xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) { - const char *package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); - const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT); - const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); - const char *arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE); - const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_DUPHASH); - const char *reason = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_REASON); - const char *function = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_CRASH_FUNCTION); - const char *analyzer = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ANALYZER); - const char *tainted_str = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_TAINTED); + const char *package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); + const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); + const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); + const char *arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); + const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); + const char *reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); + const char *function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); + const char *analyzer = get_crash_item_content_or_NULL(crash_data, FILENAME_ANALYZER); + const char *tainted_str = get_crash_item_content_or_NULL(crash_data, FILENAME_TAINTED); struct strbuf *buf_summary = strbuf_new(); strbuf_append_strf(buf_summary, "[abrt] %s", package); @@ -474,7 +474,7 @@ xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugn char *status_whiteboard = xasprintf("abrt_hash:%s", duphash); - char *bz_dsc = make_description_bz(pCrashData); + char *bz_dsc = make_description_bz(crash_data); char *full_dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); free(bz_dsc); @@ -534,23 +534,24 @@ xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugn return bug_id; } -int ctx::add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData) +int ctx::add_attachments(const char* bug_id_str, crash_data_t *crash_data) { - map_crash_data_t::const_iterator it = pCrashData.begin(); - for (; it != pCrashData.end(); it++) + GHashTableIter iter; + char *name; + struct crash_item *value; + g_hash_table_iter_init(&iter, crash_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { - const char *itemname = it->first.c_str(); - const char *type = it->second[CD_TYPE].c_str(); - const char *content = it->second[CD_CONTENT].c_str(); + const char *content = value->content; - if ((strcmp(type, CD_TXT) == 0) - && (strlen(content) > CD_TEXT_ATT_SIZE || (strcmp(itemname, FILENAME_BACKTRACE) == 0)) + if ((value->flags & CD_FLAG_TXT) + && (strlen(content) > CD_TEXT_ATT_SIZE || (strcmp(name, FILENAME_BACKTRACE) == 0)) ) { char *encoded64 = encode_base64(content, strlen(content)); - char *filename = xasprintf("File: %s", itemname); + char *filename = xasprintf("File: %s", name); xmlrpc_value* result = call("bugzilla.addAttachment", "(s{s:s,s:s,s:s,s:s})", bug_id_str, "description", filename, - "filename", itemname, + "filename", name, "contenttype", "text/plain", "data", encoded64 ); @@ -644,8 +645,7 @@ static void report_to_bugzilla( { throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name); } - map_crash_data_t pCrashData; - load_crash_data_from_crash_dump_dir(dd, pCrashData); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); const char *env; @@ -674,9 +674,9 @@ static void report_to_bugzilla( env = getenv("Bugzilla_SSLVerify"); ssl_verify = string_to_bool(env ? env : settings["SSLVerify"].c_str()); - const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT); - const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_DUPHASH); - const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); + const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); + const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); + const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); ctx bz_server(bugzilla_xmlrpc, ssl_verify); @@ -773,7 +773,7 @@ static void report_to_bugzilla( else if (all_bugs_size == 0) // Create new bug { log(_("Creating a new bug...")); - bug_id = bz_server.new_bug(pCrashData, depend_on_bugno); + bug_id = bz_server.new_bug(crash_data, depend_on_bugno); if (bug_id < 0) { throw_if_xml_fault_occurred(&bz_server.env); @@ -781,7 +781,7 @@ static void report_to_bugzilla( } log("Adding attachments to bug %d...", bug_id); - int ret = bz_server.add_attachments(to_string(bug_id).c_str(), pCrashData); + int ret = bz_server.add_attachments(to_string(bug_id).c_str(), crash_data); if (ret == -1) { throw_if_xml_fault_occurred(&bz_server.env); @@ -855,13 +855,13 @@ static void report_to_bugzilla( throw_if_xml_fault_occurred(&bz_server.env); } - char *dsc = make_description_reproduce_comment(pCrashData); + char *dsc = make_description_reproduce_comment(crash_data); if (dsc) { - const char* package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); - const char* release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); - const char* arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE); - const char* is_private = get_crash_data_item_content_or_NULL(pCrashData, "is_private"); + const char* package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); + const char* release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); + const char* arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); + const char* is_private = get_crash_item_content_or_NULL(crash_data, "is_private"); char *full_dsc = xasprintf("Package: %s\n" "Architecture: %s\n" @@ -895,6 +895,7 @@ static void report_to_bugzilla( (int)bug_id ); + free_crash_data(crash_data); bug_info_destroy(&bz); } diff --git a/src/plugins/abrt-action-kerneloops.cpp b/src/plugins/abrt-action-kerneloops.cpp index dea6df17..ac90abd7 100644 --- a/src/plugins/abrt-action-kerneloops.cpp +++ b/src/plugins/abrt-action-kerneloops.cpp @@ -91,11 +91,10 @@ static void report_to_kerneloops( if (!dd) exit(1); /* error msg is already logged */ - map_crash_data_t pCrashData; - load_crash_data_from_crash_dump_dir(dd, pCrashData); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); - const char *backtrace = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_BACKTRACE); + const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); if (!backtrace) error_msg_and_die("Error sending kernel oops due to missing backtrace"); @@ -114,6 +113,8 @@ static void report_to_kerneloops( if (ret != CURLE_OK) error_msg_and_die("Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); + free_crash_data(crash_data); + /* Server replies with: * 200 thank you for submitting the kernel oops information * RemoteIP: 34192fd15e34bf60fac6a5f01bba04ddbd3f0558 diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp index fa7fd8a0..824791fa 100644 --- a/src/plugins/abrt-action-mailx.cpp +++ b/src/plugins/abrt-action-mailx.cpp @@ -66,8 +66,7 @@ static void create_and_send_email( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - map_crash_data_t pCrashData; - load_crash_data_from_crash_dump_dir(dd, pCrashData); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); char* env; @@ -90,17 +89,20 @@ static void create_and_send_email( unsigned arg_size = 0; args = append_str_to_vector(args, arg_size, "/bin/mailx"); - char *dsc = make_description_mailx(pCrashData); + char *dsc = make_description_mailx(crash_data); if (send_binary_data) { - map_crash_data_t::const_iterator it_cd; - for (it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) + GHashTableIter iter; + char *name; + struct crash_item *value; + g_hash_table_iter_init(&iter, crash_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { - if (it_cd->second[CD_TYPE] == CD_BIN) + if (value->flags & CD_FLAG_BIN) { args = append_str_to_vector(args, arg_size, "-a"); - args = append_str_to_vector(args, arg_size, it_cd->second[CD_CONTENT].c_str()); + args = append_str_to_vector(args, arg_size, value->content); } } } @@ -112,7 +114,7 @@ static void create_and_send_email( args = append_str_to_vector(args, arg_size, email_to); log(_("Sending an email...")); - const char *uid_str = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_UID); + const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); exec_and_feed_input(xatoi_u(uid_str), dsc, args); free(dsc); @@ -122,6 +124,8 @@ static void create_and_send_email( args -= arg_size; free(args); + free_crash_data(crash_data); + log("Email was sent to: %s", email_to); } diff --git a/src/plugins/abrt-action-print.cpp b/src/plugins/abrt-action-print.cpp index 303c05f7..04d01de3 100644 --- a/src/plugins/abrt-action-print.cpp +++ b/src/plugins/abrt-action-print.cpp @@ -81,13 +81,13 @@ int main(int argc, char **argv) if (!dd) return 1; /* error message is already logged */ - map_crash_data_t pCrashData; - load_crash_data_from_crash_dump_dir(dd, pCrashData); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); - char *dsc = make_description_logger(pCrashData); + char *dsc = make_description_logger(crash_data); fputs(dsc, stdout); free(dsc); + free_crash_data(crash_data); } catch (CABRTException& e) { diff --git a/src/plugins/abrt-action-rhtsupport.cpp b/src/plugins/abrt-action-rhtsupport.cpp index eb69489d..994c84f3 100644 --- a/src/plugins/abrt-action-rhtsupport.cpp +++ b/src/plugins/abrt-action-rhtsupport.cpp @@ -35,8 +35,7 @@ static void report_to_rhtsupport( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - map_crash_data_t pCrashData; - load_crash_data_from_crash_dump_dir(dd, pCrashData); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ @@ -79,9 +78,9 @@ static void report_to_rhtsupport( goto ret; } - package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); - reason = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_REASON); - function = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_CRASH_FUNCTION); + package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); + reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); + function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); { struct strbuf *buf_summary = strbuf_new(); @@ -92,7 +91,7 @@ static void report_to_rhtsupport( strbuf_append_strf(buf_summary, ": %s", reason); summary = strbuf_free_nobuf(buf_summary); - char *bz_dsc = make_description_bz(pCrashData); + char *bz_dsc = make_description_bz(crash_data); dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); free(bz_dsc); } @@ -124,21 +123,24 @@ static void report_to_rhtsupport( } { - map_crash_data_t::const_iterator it = pCrashData.begin(); - for (; it != pCrashData.end(); it++) + GHashTableIter iter; + char *name; + struct crash_item *value; + g_hash_table_iter_init(&iter, crash_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) { - if (it->first == FILENAME_COUNT) continue; - if (it->first == CD_DUMPDIR) continue; - if (it->first == FILENAME_INFORMALL) continue; - if (it->first == FILENAME_MESSAGE) continue; // plugin's status message (if we already reported it yesterday) - if (it->first == FILENAME_DESCRIPTION) continue; // package description - - const char *content = it->second[CD_CONTENT].c_str(); - if (it->second[CD_TYPE] == CD_TXT) + if (strcmp(name, FILENAME_COUNT) == 0) continue; + if (strcmp(name, CD_DUMPDIR) == 0) continue; + if (strcmp(name, FILENAME_INFORMALL) == 0) continue; + if (strcmp(name, FILENAME_MESSAGE) == 0) continue; // plugin's status message (if we already reported it yesterday) + if (strcmp(name, FILENAME_DESCRIPTION) == 0) continue; // package description + + const char *content = value->content; + if (value->flags & CD_FLAG_TXT) { - reportfile_add_binding_from_string(file, it->first.c_str(), content); + reportfile_add_binding_from_string(file, name, content); } - else if (it->second[CD_TYPE] == CD_BIN) + else if (value->flags & CD_FLAG_BIN) { const char *basename = strrchr(content, '/'); if (basename) @@ -148,7 +150,7 @@ static void report_to_rhtsupport( char *xml_name = concat_path_file("content", basename); reportfile_add_binding_from_namedfile(file, /*on_disk_filename */ content, - /*binding_name */ it->first.c_str(), + /*binding_name */ name, /*recorded_filename*/ xml_name, /*binary */ 1); if (tar_append_file(tar, (char*)content, xml_name) != 0) @@ -248,6 +250,7 @@ static void report_to_rhtsupport( free(url); free(login); free(password); + free_crash_data(crash_data); if (errmsg) error_msg_and_die("%s", errmsg); -- 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/plugins/Makefile.am | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index fb91fc1e..9ace1b3f 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -218,7 +218,6 @@ abrt_action_upload_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_upload_LDFLAGS = -ltar -# Needs libABRTdUtils only for LoadPluginSettings abrt_action_upload_LDADD = \ $(GLIB_LIBS) \ $(CURL_LIBS) \ @@ -240,7 +239,6 @@ abrt_action_kerneloops_CPPFLAGS = \ $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror -# libABRTdUtils is used only because of LoadPluginSettings: abrt_action_kerneloops_LDADD = \ ../lib/libabrt_web.la \ ../lib/libabrt.la @@ -280,7 +278,6 @@ abrt_action_print_CPPFLAGS = \ $(GLIB_CFLAGS) \ -D_GNU_SOURCE \ -Wall -Werror -# libABRTdUtils is used only because of make_description_logger: abrt_action_print_LDADD = \ ../lib/libabrt.la -- 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/plugins/CCpp.cpp | 1 - src/plugins/KerneloopsScanner.cpp | 1 - src/plugins/abrt-action-bugzilla.cpp | 57 +++++++++++++--------------------- src/plugins/abrt-action-kerneloops.cpp | 24 ++++---------- src/plugins/abrt-action-mailx.cpp | 31 ++++++------------ src/plugins/abrt-action-print.cpp | 27 ++++++---------- src/plugins/abrt-action-rhtsupport.cpp | 33 ++++++-------------- src/plugins/abrt-action-upload.cpp | 26 +++++----------- 8 files changed, 61 insertions(+), 139 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index e6807ea7..11968349 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -21,7 +21,6 @@ #include #include "abrtlib.h" #include "CCpp.h" -#include "abrt_exception.h" #include "comm_layer_inner.h" using namespace std; diff --git a/src/plugins/KerneloopsScanner.cpp b/src/plugins/KerneloopsScanner.cpp index 93f37e07..f4a637eb 100644 --- a/src/plugins/KerneloopsScanner.cpp +++ b/src/plugins/KerneloopsScanner.cpp @@ -24,7 +24,6 @@ #include /* __NR_syslog */ #include #include "abrtlib.h" -#include "abrt_exception.h" #include "comm_layer_inner.h" #include "KerneloopsSysLog.h" #include "KerneloopsScanner.h" diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index b215735b..8486662d 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -19,7 +19,6 @@ #include "abrtlib.h" #include "abrt_xmlrpc.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define XML_RPC_SUFFIX "/xmlrpc.cgi" #define MAX_HOPS 5 @@ -612,15 +611,10 @@ int ctx::get_bug_info(struct bug_info* bz, xmlrpc_int32 bug_id) void ctx::login(const char* login, const char* passwd) { xmlrpc_value* result = call("User.login", "({s:s,s:s})", "login", login, "password", passwd); - if (!result) - { - char *errmsg = xasprintf("Can't login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", env.fault_string); - error_msg("%s", errmsg); // show error in daemon log - CABRTException e(EXCEP_PLUGIN, errmsg); - free(errmsg); - throw e; - } + error_msg_and_die("Can't login. Check Edit->Plugins->Bugzilla " + "and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", + env.fault_string); xmlrpc_DECREF(result); } @@ -638,13 +632,11 @@ void ctx::logout() static void report_to_bugzilla( const char *dump_dir_name, - /*const*/ map_plugin_settings_t& settings) + map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) - { - throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name); - } + xfunc_die(); /* dd_opendir already emitted error msg */ crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); dd_close(dd); @@ -656,23 +648,23 @@ static void report_to_bugzilla( bool ssl_verify; env = getenv("Bugzilla_Login"); - login = env ? env : settings["Login"].c_str(); + login = env ? env : get_map_string_item_or_empty(settings, "Login"); env = getenv("Bugzilla_Password"); - password = env ? env : settings["Password"].c_str(); + password = env ? env : get_map_string_item_or_empty(settings, "Password"); if (!login[0] || !password[0]) { VERB3 log("Empty login and password"); - throw CABRTException(EXCEP_PLUGIN, _("Empty login or password, please check %s"), PLUGINS_CONF_DIR"/Bugzilla.conf"); + error_msg_and_die(_("Empty login or password, please check %s"), PLUGINS_CONF_DIR"/Bugzilla.conf"); } env = getenv("Bugzilla_BugzillaURL"); - bugzilla_url = env ? env : settings["BugzillaURL"].c_str(); + bugzilla_url = env ? env : get_map_string_item_or_empty(settings, "BugzillaURL"); if (!bugzilla_url[0]) bugzilla_url = "https://bugzilla.redhat.com"; bugzilla_xmlrpc = xasprintf("%s"XML_RPC_SUFFIX, bugzilla_url); env = getenv("Bugzilla_SSLVerify"); - ssl_verify = string_to_bool(env ? env : settings["SSLVerify"].c_str()); + ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); @@ -704,7 +696,7 @@ static void report_to_bugzilla( if (!all_bugs) { throw_if_xml_fault_occurred(&bz_server.env); - throw CABRTException(EXCEP_PLUGIN, _("Missing mandatory member 'bugs'")); + error_msg_and_die(_("Missing mandatory member 'bugs'")); } xmlrpc_int32 bug_id = -1; @@ -723,7 +715,7 @@ static void report_to_bugzilla( { bug_info_destroy(&bz); throw_if_xml_fault_occurred(&bz_server.env); - throw CABRTException(EXCEP_PLUGIN, _("get_bug_info() failed. Could not collect all mandatory information")); + error_msg_and_die(_("get_bug_info() failed. Could not collect all mandatory information")); } if (strcmp(bz.bug_product, product) != 0) @@ -740,7 +732,7 @@ static void report_to_bugzilla( if (!all_bugs) { throw_if_xml_fault_occurred(&bz_server.env); - throw CABRTException(EXCEP_PLUGIN, _("Missing mandatory member 'bugs'")); + error_msg_and_die(_("Missing mandatory member 'bugs'")); } all_bugs_size = bz_server.get_array_size(all_bugs); @@ -756,7 +748,7 @@ static void report_to_bugzilla( { bug_info_destroy(&bz); throw_if_xml_fault_occurred(&bz_server.env); - throw CABRTException(EXCEP_PLUGIN, _("get_bug_info() failed. Could not collect all mandatory information")); + error_msg_and_die(_("get_bug_info() failed. Could not collect all mandatory information")); } } else @@ -777,7 +769,7 @@ static void report_to_bugzilla( if (bug_id < 0) { throw_if_xml_fault_occurred(&bz_server.env); - throw CABRTException(EXCEP_PLUGIN, _("Bugzilla entry creation failed")); + error_msg_and_die(_("Bugzilla entry creation failed")); } log("Adding attachments to bug %d...", bug_id); @@ -816,7 +808,7 @@ static void report_to_bugzilla( { VERB3 log("Bugzilla could not find a parent of bug %d", (int)original_bug_id); bug_info_destroy(&bz); - throw CABRTException(EXCEP_PLUGIN, _("Bugzilla couldn't find parent of bug %d"), (int)original_bug_id); + error_msg_and_die(_("Bugzilla couldn't find parent of bug %d"), (int)original_bug_id); } log("Bug %d is a duplicate, using parent bug %d", bug_id, (int)bz.bug_dup_id); @@ -831,7 +823,7 @@ static void report_to_bugzilla( { throw_if_xml_fault_occurred(&bz_server.env); } - throw CABRTException(EXCEP_PLUGIN, _("get_bug_info() failed. Could not collect all mandatory information")); + error_msg_and_die(_("get_bug_info() failed. Could not collect all mandatory information")); } // found a bug which is not CLOSED as DUPLICATE @@ -905,8 +897,7 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); - map_plugin_settings_t settings; - + map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; enum { OPT_s = (1 << 0), @@ -919,7 +910,7 @@ int main(int argc, char **argv) { case 'c': VERB1 log("Loading settings from '%s'", optarg); - LoadPluginSettings(optarg, settings); + load_conf_file(optarg, settings, /*skip key w/o values:*/ true); VERB3 log("Loaded '%s'", optarg); break; case 'd': @@ -966,14 +957,8 @@ int main(int argc, char **argv) error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); xmlrpc_env_clean(&env); - try - { - report_to_bugzilla(dump_dir_name, settings); - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); - } + report_to_bugzilla(dump_dir_name, settings); + free_map_string(settings); return 0; } diff --git a/src/plugins/abrt-action-kerneloops.cpp b/src/plugins/abrt-action-kerneloops.cpp index ac90abd7..f3351ccd 100644 --- a/src/plugins/abrt-action-kerneloops.cpp +++ b/src/plugins/abrt-action-kerneloops.cpp @@ -20,7 +20,6 @@ #include #include "abrtlib.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define PROGNAME "abrt-action-kerneloops" @@ -85,7 +84,7 @@ static CURLcode http_post_to_kerneloops_site(const char *url, const char *oopsda static void report_to_kerneloops( const char *dump_dir_name, - const map_plugin_settings_t& settings) + map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) @@ -98,12 +97,8 @@ static void report_to_kerneloops( if (!backtrace) error_msg_and_die("Error sending kernel oops due to missing backtrace"); - map_plugin_settings_t::const_iterator end = settings.end(); - map_plugin_settings_t::const_iterator it; - const char *env = getenv("KerneloopsReporter_SubmitURL"); - it = settings.find("SubmitURL"); - const char *submitURL = (env ? env : it == end ? "" : it->second.c_str()); + const char *submitURL = (env ? env : get_map_string_item_or_empty(settings, "SubmitURL")); if (!submitURL[0]) submitURL = "http://submit.kerneloops.org/submitoops.php"; @@ -129,8 +124,7 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); - map_plugin_settings_t settings; - + map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; enum { OPT_s = (1 << 0), @@ -143,7 +137,7 @@ int main(int argc, char **argv) { case 'c': VERB1 log("Loading settings from '%s'", optarg); - LoadPluginSettings(optarg, settings); + load_conf_file(optarg, settings, /*skip key w/o values:*/ true); VERB3 log("Loaded '%s'", optarg); break; case 'd': @@ -182,14 +176,8 @@ int main(int argc, char **argv) logmode = LOGMODE_SYSLOG; } - try - { - report_to_kerneloops(dump_dir_name, settings); - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); - } + report_to_kerneloops(dump_dir_name, settings); + free_map_string(settings); return 0; } diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp index 824791fa..6c53c504 100644 --- a/src/plugins/abrt-action-mailx.cpp +++ b/src/plugins/abrt-action-mailx.cpp @@ -22,7 +22,6 @@ #include "abrtlib.h" #include "parse_options.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define PROGNAME "abrt-action-mailx" @@ -60,7 +59,7 @@ static char** append_str_to_vector(char **vec, unsigned &size, const char *str) static void create_and_send_email( const char *dump_dir_name, - const map_plugin_settings_t& settings) + map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) @@ -70,20 +69,14 @@ static void create_and_send_email( dd_close(dd); char* env; - map_plugin_settings_t::const_iterator end = settings.end(); - map_plugin_settings_t::const_iterator it; env = getenv("Mailx_Subject"); - it = settings.find("Subject"); - const char *subject = xstrdup(env ? env : (it != end ? it->second.c_str() : "[abrt] full crash report")); + const char *subject = (env ? env : get_map_string_item_or_NULL(settings, "Subject") ? : "[abrt] full crash report"); env = getenv("Mailx_EmailFrom"); - it = settings.find("EmailFrom"); - const char *email_from = (env ? env : (it != end ? it->second.c_str() : "user@localhost")); + const char *email_from = (env ? env : get_map_string_item_or_NULL(settings, "EmailFrom") ? : "user@localhost"); env = getenv("Mailx_EmailTo"); - it = settings.find("EmailTo"); - const char *email_to = (env ? env : (it != end ? it->second.c_str() : "root@localhost")); + const char *email_to = (env ? env : get_map_string_item_or_NULL(settings, "EmailTo") ? : "root@localhost"); env = getenv("Mailx_SendBinaryData"); - it = settings.find("SendBinaryData"); - bool send_binary_data = string_to_bool(env ? env : (it != end ? it->second.c_str() : "0")); + bool send_binary_data = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SendBinaryData")); char **args = NULL; unsigned arg_size = 0; @@ -166,18 +159,12 @@ int main(int argc, char **argv) // logmode = LOGMODE_SYSLOG; //} - map_plugin_settings_t settings; + map_string_h *settings = new_map_string(); if (conf_file) - LoadPluginSettings(conf_file, settings); + load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); - try - { - create_and_send_email(dump_dir_name, settings); - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); - } + create_and_send_email(dump_dir_name, settings); + free_map_string(settings); return 0; } diff --git a/src/plugins/abrt-action-print.cpp b/src/plugins/abrt-action-print.cpp index 04d01de3..55631c96 100644 --- a/src/plugins/abrt-action-print.cpp +++ b/src/plugins/abrt-action-print.cpp @@ -21,7 +21,6 @@ #include "abrtlib.h" #include "parse_options.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define PROGNAME "abrt-action-print" @@ -75,25 +74,17 @@ int main(int argc, char **argv) } } - try - { - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - return 1; /* error message is already logged */ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + return 1; /* error message is already logged */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); - dd_close(dd); + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + dd_close(dd); - char *dsc = make_description_logger(crash_data); - fputs(dsc, stdout); - free(dsc); - free_crash_data(crash_data); - } - catch (CABRTException& e) - { - log("%s", e.what()); - return 1; - } + char *dsc = make_description_logger(crash_data); + fputs(dsc, stdout); + free(dsc); + free_crash_data(crash_data); if (output_file) { diff --git a/src/plugins/abrt-action-rhtsupport.cpp b/src/plugins/abrt-action-rhtsupport.cpp index 994c84f3..024b1efc 100644 --- a/src/plugins/abrt-action-rhtsupport.cpp +++ b/src/plugins/abrt-action-rhtsupport.cpp @@ -23,13 +23,12 @@ #include "abrt_xmlrpc.h" #include "abrt_rh_support.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define PROGNAME "abrt-action-rhtsupport" static void report_to_rhtsupport( const char *dump_dir_name, - const map_plugin_settings_t& settings) + map_string_h *settings) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) @@ -53,24 +52,17 @@ static void report_to_rhtsupport( const char* package; char* env; - map_plugin_settings_t::const_iterator end = settings.end(); - map_plugin_settings_t::const_iterator it; - env = getenv("RHTSupport_URL"); - it = settings.find("URL"); - char *url = xstrdup(env ? env : it == end ? "https://api.access.redhat.com/rs" : it->second.c_str()); + char *url = xstrdup(env ? env : (get_map_string_item_or_NULL(settings, "URL") ? : "https://api.access.redhat.com/rs")); env = getenv("RHTSupport_Login"); - it = settings.find("Login"); - char *login = xstrdup(env ? env : it == end ? "" : it->second.c_str()); + char *login = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Login")); env = getenv("RHTSupport_Password"); - it = settings.find("Password"); - char *password = xstrdup(env ? env : it == end ? "" : it->second.c_str()); + char *password = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Password")); env = getenv("RHTSupport_SSLVerify"); - it = settings.find("SSLVerify"); - bool ssl_verify = string_to_bool(env ? env : it == end ? "1" : it->second.c_str()); + bool ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); if (!login[0] || !password[0]) { @@ -262,8 +254,7 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); - map_plugin_settings_t settings; - + map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; enum { OPT_s = (1 << 0), @@ -276,7 +267,7 @@ int main(int argc, char **argv) { case 'c': VERB1 log("Loading settings from '%s'", optarg); - LoadPluginSettings(optarg, settings); + load_conf_file(optarg, settings, /*skip key w/o values:*/ true); VERB3 log("Loaded '%s'", optarg); break; case 'd': @@ -323,14 +314,8 @@ int main(int argc, char **argv) error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); xmlrpc_env_clean(&env); - try - { - report_to_rhtsupport(dump_dir_name, settings); - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); - } + report_to_rhtsupport(dump_dir_name, settings); + free_map_string(settings); return 0; } diff --git a/src/plugins/abrt-action-upload.cpp b/src/plugins/abrt-action-upload.cpp index 9741f543..8789f0e7 100644 --- a/src/plugins/abrt-action-upload.cpp +++ b/src/plugins/abrt-action-upload.cpp @@ -22,7 +22,6 @@ #include "abrtlib.h" #include "parse_options.h" #include "abrt_crash_dump.h" -#include "abrt_exception.h" #define PROGNAME "abrt-action-upload" @@ -104,7 +103,7 @@ static int send_file(const char *url, const char *filename) static int create_and_upload_archive( const char *dump_dir_name, - const map_plugin_settings_t& settings) + map_string_h *settings) { int result = 0; @@ -125,12 +124,8 @@ static int create_and_upload_archive( //ArchiveType = .tar.bz2 //ExcludeFiles = foo,bar*,b*z char* env; - map_plugin_settings_t::const_iterator end = settings.end(); - map_plugin_settings_t::const_iterator it; - env = getenv("Upload_URL"); - it = settings.find("URL"); - const char *url = (env ? env : (it == end ? NULL : it->second.c_str())); + const char *url = (env ? env : get_map_string_item_or_empty(settings, "URL")); /* Create a child gzip which will compress the data */ /* SELinux guys are not happy with /tmp, using /var/run/abrt */ @@ -279,21 +274,14 @@ int main(int argc, char **argv) // logmode = LOGMODE_SYSLOG; //} - map_plugin_settings_t settings; + map_string_h *settings = new_map_string(); if (url) - settings["URL"] = url; + g_hash_table_replace(settings, xstrdup("URL"), xstrdup(url)); if (conf_file) - LoadPluginSettings(conf_file, settings); + load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); - int result = 0; - try - { - result = create_and_upload_archive(dump_dir_name, settings); - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); - } + int result = create_and_upload_archive(dump_dir_name, settings); + free_map_string(settings); return result; } -- cgit From def39238640489b41da5cdc8fd4a83d16d49fcc7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 15:03:24 +0100 Subject: removal of C++isms from libabrt, part 2 This patch rewrites a few places where we use C++ strings Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 11 ----------- src/plugins/abrt-action-bugzilla.cpp | 10 +++++++--- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index 11968349..19860290 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -258,17 +258,6 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) } } -//ok to delete? -//const map_plugin_settings_t& CAnalyzerCCpp::GetSettings() -//{ -// m_pSettings["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; -// m_pSettings["DebugInfo"] = m_sDebugInfo; -// m_pSettings["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); -// m_pSettings["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; -// -// return m_pSettings; -//} - PLUGIN_INFO(ANALYZER, CAnalyzerCCpp, "CCpp", diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 8486662d..d1bd271a 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -567,7 +567,9 @@ int ctx::add_attachments(const char* bug_id_str, crash_data_t *crash_data) int ctx::get_bug_info(struct bug_info* bz, xmlrpc_int32 bug_id) { - xmlrpc_value* result = call("bugzilla.getBug", "(s)", to_string(bug_id).c_str()); + char bug_id_str[sizeof(long)*3 + 2]; + sprintf(bug_id_str, "%lu", (long)bug_id); + xmlrpc_value* result = call("bugzilla.getBug", "(s)", bug_id_str); if (!result) return -1; @@ -772,8 +774,10 @@ static void report_to_bugzilla( error_msg_and_die(_("Bugzilla entry creation failed")); } - log("Adding attachments to bug %d...", bug_id); - int ret = bz_server.add_attachments(to_string(bug_id).c_str(), crash_data); + log("Adding attachments to bug %ld...", (long)bug_id); + char bug_id_str[sizeof(long)*3 + 2]; + sprintf(bug_id_str, "%ld", (long) bug_id); + int ret = bz_server.add_attachments(bug_id_str, crash_data); if (ret == -1) { throw_if_xml_fault_occurred(&bz_server.env); -- 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/plugins/CCpp.cpp | 2 +- src/plugins/abrt-action-analyze-c.c | 2 +- src/plugins/abrt-action-bugzilla.cpp | 2 +- src/plugins/abrt-action-generate-backtrace.c | 2 +- src/plugins/abrt-action-mailx.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index 19860290..d88a593d 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -240,7 +240,7 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) it = pSettings.find("GdbTimeoutSec"); if (it != end) { - m_nGdbTimeoutSec = xatoi_u(it->second.c_str()); + m_nGdbTimeoutSec = xatoi_positive(it->second.c_str()); } it = pSettings.find("InstallDebugInfo"); if (it == end) //compat, remove after 0.0.11 diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c index 6d8ac1b4..e45e39cf 100644 --- a/src/plugins/abrt-action-analyze-c.c +++ b/src/plugins/abrt-action-analyze-c.c @@ -52,7 +52,7 @@ static char *run_unstrip_n(const char *dump_dir_name, unsigned timeout_sec) return NULL; char *uid_str = dd_load_text(dd, FILENAME_UID); dd_close(dd); - unsigned uid = xatoi_u(uid_str); + unsigned uid = xatoi_positive(uid_str); free(uid_str); int flags = EXECFLG_INPUT_NUL | EXECFLG_OUTPUT | EXECFLG_SETGUID | EXECFLG_SETSID | EXECFLG_QUIET; diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index d1bd271a..db492051 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -465,7 +465,7 @@ xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) if (tainted_str && analyzer && (strcmp(analyzer, "Kerneloops") == 0) ) { - unsigned long tainted = xatoi_u(tainted_str); + unsigned long tainted = xatoi_positive(tainted_str); const char *tainted_warning = tainted_string(tainted); if (tainted_warning) strbuf_append_strf(buf_summary, ": TAINTED %s", tainted_warning); diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 64ce4082..a575a191 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -131,7 +131,7 @@ static char* exec_vp(char **args, uid_t uid, int redirect_stderr, int *status) static char *get_backtrace(struct dump_dir *dd) { char *uid_str = dd_load_text(dd, FILENAME_UID); - uid_t uid = xatoi_u(uid_str); + uid_t uid = xatoi_positive(uid_str); free(uid_str); char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); dd_close(dd); diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp index 6c53c504..8f613047 100644 --- a/src/plugins/abrt-action-mailx.cpp +++ b/src/plugins/abrt-action-mailx.cpp @@ -108,7 +108,7 @@ static void create_and_send_email( log(_("Sending an email...")); const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); - exec_and_feed_input(xatoi_u(uid_str), dsc, args); + exec_and_feed_input(xatoi_positive(uid_str), dsc, args); free(dsc); -- 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/plugins/Makefile.am | 56 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 9ace1b3f..8ee69759 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -1,7 +1,5 @@ -INC_PATH=$(srcdir)/../include -UTILS_PATH=$(srcdir)/../lib -AM_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -pluginslibdir=$(PLUGINS_LIB_DIR) +pluginslibdir = $(PLUGINS_LIB_DIR) + libexec_SCRIPTS = \ abrt-action-install-debuginfo.py @@ -18,6 +16,7 @@ dist_pluginslib_DATA = \ KerneloopsReporter.glade pluginsconfdir = $(PLUGINS_CONF_DIR) + dist_pluginsconf_DATA = \ CCpp.conf \ Python.conf \ @@ -49,21 +48,32 @@ install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf # CCpp -libCCpp_la_SOURCES = CCpp.cpp CCpp.h -libCCpp_la_LDFLAGS = -avoid-version -libCCpp_la_CPPFLAGS = -Wall -Werror \ - -I$(INC_PATH) \ - -I$(UTILS_PATH) \ +libCCpp_la_SOURCES = \ + CCpp.cpp CCpp.h +libCCpp_la_CPPFLAGS = \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -I$(srcdir)/../lib \ -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - $(GLIB_CFLAGS) + $(GLIB_CFLAGS) \ + -Wall -Werror # -DHOSTILE_KERNEL +libCCpp_la_LDFLAGS = \ + -avoid-version # KerneloopsScanner -libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h -libKerneloopsScanner_la_LDFLAGS = -avoid-version $(GLIB_LIBS) -libKerneloopsScanner_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(GLIB_CFLAGS) +libKerneloopsScanner_la_SOURCES = \ + KerneloopsScanner.cpp KerneloopsScanner.h \ + KerneloopsSysLog.cpp KerneloopsSysLog.h +libKerneloopsScanner_la_CPPFLAGS = \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -I$(srcdir)/../lib \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + $(GLIB_CFLAGS) +libKerneloopsScanner_la_LDFLAGS = \ + -avoid-version \ + $(GLIB_LIBS) libexec_PROGRAMS = \ abrt-action-analyze-c \ @@ -80,7 +90,7 @@ libexec_PROGRAMS = \ abrt_action_analyze_c_SOURCES = \ abrt-action-analyze-c.c abrt_action_analyze_c_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -99,7 +109,7 @@ abrt_action_analyze_c_LDADD = \ abrt_action_analyze_python_SOURCES = \ abrt-action-analyze-python.c abrt_action_analyze_python_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -118,7 +128,7 @@ abrt_action_analyze_python_LDADD = \ abrt_action_analyze_oops_SOURCES = \ abrt-action-analyze-oops.c abrt_action_analyze_oops_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -137,7 +147,7 @@ abrt_action_analyze_oops_LDADD = \ abrt_action_generate_backtrace_SOURCES = \ abrt-action-generate-backtrace.c abrt_action_generate_backtrace_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -157,7 +167,7 @@ abrt_action_generate_backtrace_LDADD = \ abrt_action_bugzilla_SOURCES = \ abrt-action-bugzilla.cpp abrt_action_bugzilla_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -179,7 +189,7 @@ abrt_action_rhtsupport_SOURCES = \ abrt_rh_support.h abrt_rh_support.c \ abrt-action-rhtsupport.cpp abrt_action_rhtsupport_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -203,7 +213,7 @@ abrt_action_rhtsupport_LDADD = \ abrt_action_upload_SOURCES = \ abrt-action-upload.cpp abrt_action_upload_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -226,7 +236,7 @@ abrt_action_upload_LDADD = \ abrt_action_kerneloops_SOURCES = \ abrt-action-kerneloops.cpp abrt_action_kerneloops_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -246,7 +256,7 @@ abrt_action_kerneloops_LDADD = \ abrt_action_mailx_SOURCES = \ abrt-action-mailx.cpp abrt_action_mailx_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -265,7 +275,7 @@ abrt_action_mailx_LDADD = \ abrt_action_print_SOURCES = \ abrt-action-print.cpp abrt_action_print_CPPFLAGS = \ - -I$(srcdir)/../include \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DBIN_DIR=\"$(bindir)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ -- 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/plugins/Makefile.am | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 8ee69759..52f3e4d1 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -104,7 +104,7 @@ abrt_action_analyze_c_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_c_LDADD = \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_analyze_python_SOURCES = \ abrt-action-analyze-python.c @@ -123,7 +123,7 @@ abrt_action_analyze_python_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_python_LDADD = \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_analyze_oops_SOURCES = \ abrt-action-analyze-oops.c @@ -142,7 +142,7 @@ abrt_action_analyze_oops_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_oops_LDADD = \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_generate_backtrace_SOURCES = \ abrt-action-generate-backtrace.c @@ -161,7 +161,7 @@ abrt_action_generate_backtrace_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_generate_backtrace_LDADD = \ - ../lib/libabrt.la \ + ../lib/libreport.la \ ../btparser/libbtparser.la abrt_action_bugzilla_SOURCES = \ @@ -183,7 +183,7 @@ abrt_action_bugzilla_CPPFLAGS = \ abrt_action_bugzilla_LDADD = \ $(GLIB_LIBS) \ ../lib/libabrt_web.la \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_rhtsupport_SOURCES = \ abrt_rh_support.h abrt_rh_support.c \ @@ -208,7 +208,7 @@ abrt_action_rhtsupport_LDADD = \ $(GLIB_LIBS) \ $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) \ ../lib/libabrt_web.la \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_upload_SOURCES = \ abrt-action-upload.cpp @@ -231,7 +231,7 @@ abrt_action_upload_LDFLAGS = -ltar abrt_action_upload_LDADD = \ $(GLIB_LIBS) \ $(CURL_LIBS) \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_kerneloops_SOURCES = \ abrt-action-kerneloops.cpp @@ -251,7 +251,7 @@ abrt_action_kerneloops_CPPFLAGS = \ -Wall -Werror abrt_action_kerneloops_LDADD = \ ../lib/libabrt_web.la \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_mailx_SOURCES = \ abrt-action-mailx.cpp @@ -270,7 +270,7 @@ abrt_action_mailx_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_mailx_LDADD = \ - ../lib/libabrt.la + ../lib/libreport.la abrt_action_print_SOURCES = \ abrt-action-print.cpp @@ -289,6 +289,6 @@ abrt_action_print_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_print_LDADD = \ - ../lib/libabrt.la + ../lib/libreport.la DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -- cgit From deabb987d709ef8512d61d41e44bcb77c3f5bff6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Dec 2010 14:17:52 +0100 Subject: rename a few more files from .cpp to .c Renamed files: KerneloopsSysLog.c abrt-action-rhtsupport.c abrt-action-upload.c abrt-action-kerneloops.c abrt-action-mailx.c abrt-action-print.c Signed-off-by: Denys Vlasenko --- src/plugins/KerneloopsSysLog.c | 383 +++++++++++++++++++++++++++++++++ src/plugins/KerneloopsSysLog.cpp | 383 --------------------------------- src/plugins/Makefile.am | 17 +- src/plugins/abrt-action-kerneloops.c | 183 ++++++++++++++++ src/plugins/abrt-action-kerneloops.cpp | 183 ---------------- src/plugins/abrt-action-mailx.c | 172 +++++++++++++++ src/plugins/abrt-action-mailx.cpp | 170 --------------- src/plugins/abrt-action-print.c | 96 +++++++++ src/plugins/abrt-action-print.cpp | 96 --------- src/plugins/abrt-action-rhtsupport.c | 321 +++++++++++++++++++++++++++ src/plugins/abrt-action-rhtsupport.cpp | 321 --------------------------- src/plugins/abrt-action-upload.c | 287 ++++++++++++++++++++++++ src/plugins/abrt-action-upload.cpp | 287 ------------------------ 13 files changed, 1452 insertions(+), 1447 deletions(-) create mode 100644 src/plugins/KerneloopsSysLog.c delete mode 100644 src/plugins/KerneloopsSysLog.cpp create mode 100644 src/plugins/abrt-action-kerneloops.c delete mode 100644 src/plugins/abrt-action-kerneloops.cpp create mode 100644 src/plugins/abrt-action-mailx.c delete mode 100644 src/plugins/abrt-action-mailx.cpp create mode 100644 src/plugins/abrt-action-print.c delete mode 100644 src/plugins/abrt-action-print.cpp create mode 100644 src/plugins/abrt-action-rhtsupport.c delete mode 100644 src/plugins/abrt-action-rhtsupport.cpp create mode 100644 src/plugins/abrt-action-upload.c delete mode 100644 src/plugins/abrt-action-upload.cpp (limited to 'src/plugins') diff --git a/src/plugins/KerneloopsSysLog.c b/src/plugins/KerneloopsSysLog.c new file mode 100644 index 00000000..f69503af --- /dev/null +++ b/src/plugins/KerneloopsSysLog.c @@ -0,0 +1,383 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + Authors: + Anton Arapov + Arjan van de Ven + */ +#include "abrtlib.h" +#include "KerneloopsSysLog.h" +#include + +static void queue_oops(GList **vec, const char *data, const char *version) +{ + char *ver_data = xasprintf("%s\n%s", version, data); + *vec = g_list_append(*vec, ver_data); +} + +/* + * extract_version tries to find the kernel version in given data + */ +static char *extract_version(const char *linepointer) +{ + if (strstr(linepointer, "Pid") + || strstr(linepointer, "comm") + || strstr(linepointer, "CPU") + || strstr(linepointer, "REGS") + || strstr(linepointer, "EFLAGS") + ) { + char* start; + char* end; + + start = strstr((char*)linepointer, "2.6."); + if (start) + { + end = strchr(start, ')'); + if (!end) + end = strchrnul(start, ' '); + return xstrndup(start, end-start); + } + } + + return NULL; +} + +/* + * extract_oops tries to find oops signatures in a log + */ +struct line_info { + char *ptr; + char level; +}; + +static int record_oops(GList **oopses, struct line_info* lines_info, int oopsstart, int oopsend) +{ + int q; + int len; + char *oops; + char *version; + + len = 2; + for (q = oopsstart; q <= oopsend; q++) + len += strlen(lines_info[q].ptr) + 1; + + oops = (char*)xzalloc(len); + + version = NULL; + for (q = oopsstart; q <= oopsend; q++) + { + if (!version) + version = extract_version(lines_info[q].ptr); + + if (lines_info[q].ptr[0]) + { + strcat(oops, lines_info[q].ptr); + strcat(oops, "\n"); + } + } + int rv = 1; + /* too short oopses are invalid */ + if (strlen(oops) > 100) + queue_oops(oopses, oops, version ? version : "undefined"); + else + { + VERB3 log("Dropped oops: too short"); + rv = 0; + } + free(oops); + free(version); + return rv; +} +#define REALLOC_CHUNK 1000 +int extract_oopses(GList **oopses, char *buffer, size_t buflen) +{ + char *c; + int linecount = 0; + int lines_info_alloc = 0; + struct line_info *lines_info = NULL; + + /* Split buffer into lines */ + + if (buflen != 0) + buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ + c = buffer; + while (c < buffer + buflen) + { + char linelevel; + char *c9; + char *colon; + + c9 = (char*)memchr(c, '\n', buffer + buflen - c); /* a \n will always be found */ + assert(c9); + *c9 = '\0'; /* turn the \n into a string termination */ + if (c9 == c) + goto next_line; + + /* Is it a syslog file (/var/log/messages or similar)? + * Even though _usually_ it looks like "Nov 19 12:34:38 localhost kernel: xxx", + * some users run syslog in non-C locale: + * "2010-02-22T09:24:08.156534-08:00 gnu-4 gnome-session[2048]: blah blah" + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !!! + * We detect it by checking for N:NN:NN pattern in first 15 chars + * (and this still is not good enough... false positive: "pci 0000:15:00.0: PME# disabled") + */ + colon = strchr(c, ':'); + if (colon && colon > c && colon < c + 15 + && isdigit(colon[-1]) /* N:... */ + && isdigit(colon[1]) /* ...N:NN:... */ + && isdigit(colon[2]) + && colon[3] == ':' + && isdigit(colon[4]) /* ...N:NN:NN... */ + && isdigit(colon[5]) + ) { + /* It's syslog file, not a bare dmesg */ + + /* Skip non-kernel lines */ + char *kernel_str = strstr(c, "kernel: "); + if (kernel_str == NULL) + { + /* if we see our own marker: + * "hostname abrt: Kerneloops: Reported 1 kernel oopses to Abrt" + * we know we submitted everything upto here already */ + if (strstr(c, "abrt:") && strstr(c, "Abrt")) + { + VERB3 log("Found our marker at line %d, restarting line count from 0", linecount); + linecount = 0; + lines_info_alloc = 0; + free(lines_info); + lines_info = NULL; + } + goto next_line; + } + c = kernel_str + sizeof("kernel: ")-1; + } + + linelevel = 0; + /* store and remove kernel log level */ + if (*c == '<' && c[1] && c[2] == '>') + { + linelevel = c[1]; + c += 3; + } + /* remove jiffies time stamp counter if present */ + if (*c == '[') + { + char *c2 = strchr(c, '.'); + char *c3 = strchr(c, ']'); + if (c2 && c3 && (c2 < c3) && (c3-c) < 14 && (c2-c) < 8) + { + c = c3 + 1; + if (*c == ' ') + c++; + } + } + if (linecount >= lines_info_alloc) + { + lines_info_alloc += REALLOC_CHUNK; + lines_info = (struct line_info*)xrealloc(lines_info, + lines_info_alloc * sizeof(lines_info[0])); + } + lines_info[linecount].ptr = c; + lines_info[linecount].level = linelevel; + linecount++; +next_line: + c = c9 + 1; + } + + /* Analyze lines */ + + int i; + char prevlevel = 0; + int oopsstart = -1; + int inbacktrace = 0; + int oopsesfound = 0; + + i = 0; + while (i < linecount) + { + char *curline = lines_info[i].ptr; + + if (curline == NULL) + { + i++; + continue; + } + while (*curline == ' ') + curline++; + + if (oopsstart < 0) + { + /* find start-of-oops markers */ + if (strstr(curline, "general protection fault:")) + oopsstart = i; + else if (strstr(curline, "BUG:")) + oopsstart = i; + else if (strstr(curline, "kernel BUG at")) + oopsstart = i; + else if (strstr(curline, "do_IRQ: stack overflow:")) + oopsstart = i; + else if (strstr(curline, "RTNL: assertion failed")) + oopsstart = i; + else if (strstr(curline, "Eeek! page_mapcount(page) went negative!")) + oopsstart = i; + else if (strstr(curline, "near stack overflow (cur:")) + oopsstart = i; + else if (strstr(curline, "double fault:")) + oopsstart = i; + else if (strstr(curline, "Badness at")) + oopsstart = i; + else if (strstr(curline, "NETDEV WATCHDOG")) + oopsstart = i; + else if (strstr(curline, "WARNING: at ")) /* WARN_ON() generated message */ + oopsstart = i; + else if (strstr(curline, "Unable to handle kernel")) + oopsstart = i; + else if (strstr(curline, "sysctl table check failed")) + oopsstart = i; + else if (strstr(curline, "INFO: possible recursive locking detected")) + oopsstart = i; + // Not needed: "--[ cut here ]--" is always followed + // by "Badness at", "kernel BUG at", or "WARNING: at" string + //else if (strstr(curline, "------------[ cut here ]------------")) + // oopsstart = i; + else if (strstr(curline, "list_del corruption.")) + oopsstart = i; + else if (strstr(curline, "list_add corruption.")) + oopsstart = i; + if (strstr(curline, "Oops:") && i >= 3) + oopsstart = i-3; + + if (oopsstart >= 0) + { + /* debug information */ + VERB3 { + log("Found oops at line %d: '%s'", oopsstart, lines_info[oopsstart].ptr); + if (oopsstart != i) + log("Trigger line is %d: '%s'", i, c); + } + /* try to find the end marker */ + int i2 = i + 1; + while (i2 < linecount && i2 < (i+50)) + { + if (strstr(lines_info[i2].ptr, "---[ end trace")) + { + inbacktrace = 1; + i = i2; + break; + } + i2++; + } + } + } + + /* Are we entering a call trace part? */ + /* a call trace starts with "Call Trace:" or with the " [<.......>] function+0xFF/0xAA" pattern */ + if (oopsstart >= 0 && !inbacktrace) + { + if (strstr(curline, "Call Trace:")) + inbacktrace = 1; + else + if (strnlen(curline, 9) > 8 + && curline[0] == '[' && curline[1] == '<' + && strstr(curline, ">]") + && strstr(curline, "+0x") + && strstr(curline, "/0x") + ) { + inbacktrace = 1; + } + } + + /* Are we at the end of an oops? */ + else if (oopsstart >= 0 && inbacktrace) + { + int oopsend = INT_MAX; + + /* line needs to start with " [" or have "] [" if it is still a call trace */ + /* example: "[] radeon_get_ring_head+0x16/0x41 [radeon]" */ + if (curline[0] != '[' + && !strstr(curline, "] [") + && !strstr(curline, "--- Exception") + && !strstr(curline, "LR =") + && !strstr(curline, "<#DF>") + && !strstr(curline, "") + && !strstr(curline, "") + && !strstr(curline, "<>") + && strncmp(curline, "Code: ", 6) != 0 + && strncmp(curline, "RIP ", 4) != 0 + && strncmp(curline, "RSP ", 4) != 0 + ) { + oopsend = i-1; /* not a call trace line */ + } + /* oops lines are always more than 8 chars long */ + else if (strnlen(curline, 8) < 8) + oopsend = i-1; + /* single oopses are of the same loglevel */ + else if (lines_info[i].level != prevlevel) + oopsend = i-1; + else if (strstr(curline, "Instruction dump:")) + oopsend = i; + /* if a new oops starts, this one has ended */ + else if (strstr(curline, "WARNING: at ") && oopsstart != i) /* WARN_ON() generated message */ + oopsend = i-1; + else if (strstr(curline, "Unable to handle") && oopsstart != i) + oopsend = i-1; + /* kernel end-of-oops marker (not including marker itself) */ + else if (strstr(curline, "---[ end trace")) + oopsend = i-1; + + if (oopsend <= i) + { + VERB3 log("End of oops at line %d (%d): '%s'", oopsend, i, lines_info[oopsend].ptr); + if (record_oops(oopses, lines_info, oopsstart, oopsend)) + oopsesfound++; + oopsstart = -1; + inbacktrace = 0; + } + } + + prevlevel = lines_info[i].level; + i++; + + if (oopsstart >= 0) + { + /* Do we have a suspiciously long oops? Cancel it */ + if (i-oopsstart > 60) + { + inbacktrace = 0; + oopsstart = -1; + VERB3 log("Dropped oops, too long"); + continue; + } + if (!inbacktrace && i-oopsstart > 40) + { + /*inbacktrace = 0; - already is */ + oopsstart = -1; + VERB3 log("Dropped oops, too long"); + continue; + } + } + } /* while (i < linecount) */ + + /* process last oops if we have one */ + if (oopsstart >= 0 && inbacktrace) + { + int oopsend = i-1; + VERB3 log("End of oops at line %d (end of file): '%s'", oopsend, lines_info[oopsend].ptr); + if (record_oops(oopses, lines_info, oopsstart, oopsend)) + oopsesfound++; + } + + free(lines_info); + return oopsesfound; +} diff --git a/src/plugins/KerneloopsSysLog.cpp b/src/plugins/KerneloopsSysLog.cpp deleted file mode 100644 index 68f309bc..00000000 --- a/src/plugins/KerneloopsSysLog.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - Authors: - Anton Arapov - Arjan van de Ven - */ -#include "abrtlib.h" -#include "KerneloopsSysLog.h" -#include - -static void queue_oops(GList **vec, const char *data, const char *version) -{ - char *ver_data = xasprintf("%s\n%s", version, data); - *vec = g_list_append(*vec, ver_data); -} - -/* - * extract_version tries to find the kernel version in given data - */ -static char *extract_version(const char *linepointer) -{ - if (strstr(linepointer, "Pid") - || strstr(linepointer, "comm") - || strstr(linepointer, "CPU") - || strstr(linepointer, "REGS") - || strstr(linepointer, "EFLAGS") - ) { - char* start; - char* end; - - start = strstr((char*)linepointer, "2.6."); - if (start) - { - end = strchr(start, ')'); - if (!end) - end = strchrnul(start, ' '); - return xstrndup(start, end-start); - } - } - - return NULL; -} - -/* - * extract_oops tries to find oops signatures in a log - */ -struct line_info { - char *ptr; - char level; -}; - -static int record_oops(GList **oopses, struct line_info* lines_info, int oopsstart, int oopsend) -{ - int q; - int len; - char *oops; - char *version; - - len = 2; - for (q = oopsstart; q <= oopsend; q++) - len += strlen(lines_info[q].ptr) + 1; - - oops = (char*)xzalloc(len); - - version = NULL; - for (q = oopsstart; q <= oopsend; q++) - { - if (!version) - version = extract_version(lines_info[q].ptr); - - if (lines_info[q].ptr[0]) - { - strcat(oops, lines_info[q].ptr); - strcat(oops, "\n"); - } - } - int rv = 1; - /* too short oopses are invalid */ - if (strlen(oops) > 100) - queue_oops(oopses, oops, version ? version : "undefined"); - else - { - VERB3 log("Dropped oops: too short"); - rv = 0; - } - free(oops); - free(version); - return rv; -} -#define REALLOC_CHUNK 1000 -int extract_oopses(GList **oopses, char *buffer, size_t buflen) -{ - char *c; - int linecount = 0; - int lines_info_alloc = 0; - struct line_info *lines_info = NULL; - - /* Split buffer into lines */ - - if (buflen != 0) - buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ - c = buffer; - while (c < buffer + buflen) - { - char linelevel; - char *c9; - char *colon; - - c9 = (char*)memchr(c, '\n', buffer + buflen - c); /* a \n will always be found */ - assert(c9); - *c9 = '\0'; /* turn the \n into a string termination */ - if (c9 == c) - goto next_line; - - /* Is it a syslog file (/var/log/messages or similar)? - * Even though _usually_ it looks like "Nov 19 12:34:38 localhost kernel: xxx", - * some users run syslog in non-C locale: - * "2010-02-22T09:24:08.156534-08:00 gnu-4 gnome-session[2048]: blah blah" - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !!! - * We detect it by checking for N:NN:NN pattern in first 15 chars - * (and this still is not good enough... false positive: "pci 0000:15:00.0: PME# disabled") - */ - colon = strchr(c, ':'); - if (colon && colon > c && colon < c + 15 - && isdigit(colon[-1]) /* N:... */ - && isdigit(colon[1]) /* ...N:NN:... */ - && isdigit(colon[2]) - && colon[3] == ':' - && isdigit(colon[4]) /* ...N:NN:NN... */ - && isdigit(colon[5]) - ) { - /* It's syslog file, not a bare dmesg */ - - /* Skip non-kernel lines */ - char *kernel_str = strstr(c, "kernel: "); - if (kernel_str == NULL) - { - /* if we see our own marker: - * "hostname abrt: Kerneloops: Reported 1 kernel oopses to Abrt" - * we know we submitted everything upto here already */ - if (strstr(c, "abrt:") && strstr(c, "Abrt")) - { - VERB3 log("Found our marker at line %d, restarting line count from 0", linecount); - linecount = 0; - lines_info_alloc = 0; - free(lines_info); - lines_info = NULL; - } - goto next_line; - } - c = kernel_str + sizeof("kernel: ")-1; - } - - linelevel = 0; - /* store and remove kernel log level */ - if (*c == '<' && c[1] && c[2] == '>') - { - linelevel = c[1]; - c += 3; - } - /* remove jiffies time stamp counter if present */ - if (*c == '[') - { - char *c2 = strchr(c, '.'); - char *c3 = strchr(c, ']'); - if (c2 && c3 && (c2 < c3) && (c3-c) < 14 && (c2-c) < 8) - { - c = c3 + 1; - if (*c == ' ') - c++; - } - } - if (linecount >= lines_info_alloc) - { - lines_info_alloc += REALLOC_CHUNK; - lines_info = (line_info*)xrealloc(lines_info, - lines_info_alloc * sizeof(struct line_info)); - } - lines_info[linecount].ptr = c; - lines_info[linecount].level = linelevel; - linecount++; -next_line: - c = c9 + 1; - } - - /* Analyze lines */ - - int i; - char prevlevel = 0; - int oopsstart = -1; - int inbacktrace = 0; - int oopsesfound = 0; - - i = 0; - while (i < linecount) - { - char *curline = lines_info[i].ptr; - - if (curline == NULL) - { - i++; - continue; - } - while (*curline == ' ') - curline++; - - if (oopsstart < 0) - { - /* find start-of-oops markers */ - if (strstr(curline, "general protection fault:")) - oopsstart = i; - else if (strstr(curline, "BUG:")) - oopsstart = i; - else if (strstr(curline, "kernel BUG at")) - oopsstart = i; - else if (strstr(curline, "do_IRQ: stack overflow:")) - oopsstart = i; - else if (strstr(curline, "RTNL: assertion failed")) - oopsstart = i; - else if (strstr(curline, "Eeek! page_mapcount(page) went negative!")) - oopsstart = i; - else if (strstr(curline, "near stack overflow (cur:")) - oopsstart = i; - else if (strstr(curline, "double fault:")) - oopsstart = i; - else if (strstr(curline, "Badness at")) - oopsstart = i; - else if (strstr(curline, "NETDEV WATCHDOG")) - oopsstart = i; - else if (strstr(curline, "WARNING: at ")) /* WARN_ON() generated message */ - oopsstart = i; - else if (strstr(curline, "Unable to handle kernel")) - oopsstart = i; - else if (strstr(curline, "sysctl table check failed")) - oopsstart = i; - else if (strstr(curline, "INFO: possible recursive locking detected")) - oopsstart = i; - // Not needed: "--[ cut here ]--" is always followed - // by "Badness at", "kernel BUG at", or "WARNING: at" string - //else if (strstr(curline, "------------[ cut here ]------------")) - // oopsstart = i; - else if (strstr(curline, "list_del corruption.")) - oopsstart = i; - else if (strstr(curline, "list_add corruption.")) - oopsstart = i; - if (strstr(curline, "Oops:") && i >= 3) - oopsstart = i-3; - - if (oopsstart >= 0) - { - /* debug information */ - VERB3 { - log("Found oops at line %d: '%s'", oopsstart, lines_info[oopsstart].ptr); - if (oopsstart != i) - log("Trigger line is %d: '%s'", i, c); - } - /* try to find the end marker */ - int i2 = i + 1; - while (i2 < linecount && i2 < (i+50)) - { - if (strstr(lines_info[i2].ptr, "---[ end trace")) - { - inbacktrace = 1; - i = i2; - break; - } - i2++; - } - } - } - - /* Are we entering a call trace part? */ - /* a call trace starts with "Call Trace:" or with the " [<.......>] function+0xFF/0xAA" pattern */ - if (oopsstart >= 0 && !inbacktrace) - { - if (strstr(curline, "Call Trace:")) - inbacktrace = 1; - else - if (strnlen(curline, 9) > 8 - && curline[0] == '[' && curline[1] == '<' - && strstr(curline, ">]") - && strstr(curline, "+0x") - && strstr(curline, "/0x") - ) { - inbacktrace = 1; - } - } - - /* Are we at the end of an oops? */ - else if (oopsstart >= 0 && inbacktrace) - { - int oopsend = INT_MAX; - - /* line needs to start with " [" or have "] [" if it is still a call trace */ - /* example: "[] radeon_get_ring_head+0x16/0x41 [radeon]" */ - if (curline[0] != '[' - && !strstr(curline, "] [") - && !strstr(curline, "--- Exception") - && !strstr(curline, "LR =") - && !strstr(curline, "<#DF>") - && !strstr(curline, "") - && !strstr(curline, "") - && !strstr(curline, "<>") - && strncmp(curline, "Code: ", 6) != 0 - && strncmp(curline, "RIP ", 4) != 0 - && strncmp(curline, "RSP ", 4) != 0 - ) { - oopsend = i-1; /* not a call trace line */ - } - /* oops lines are always more than 8 chars long */ - else if (strnlen(curline, 8) < 8) - oopsend = i-1; - /* single oopses are of the same loglevel */ - else if (lines_info[i].level != prevlevel) - oopsend = i-1; - else if (strstr(curline, "Instruction dump:")) - oopsend = i; - /* if a new oops starts, this one has ended */ - else if (strstr(curline, "WARNING: at ") && oopsstart != i) /* WARN_ON() generated message */ - oopsend = i-1; - else if (strstr(curline, "Unable to handle") && oopsstart != i) - oopsend = i-1; - /* kernel end-of-oops marker (not including marker itself) */ - else if (strstr(curline, "---[ end trace")) - oopsend = i-1; - - if (oopsend <= i) - { - VERB3 log("End of oops at line %d (%d): '%s'", oopsend, i, lines_info[oopsend].ptr); - if (record_oops(oopses, lines_info, oopsstart, oopsend)) - oopsesfound++; - oopsstart = -1; - inbacktrace = 0; - } - } - - prevlevel = lines_info[i].level; - i++; - - if (oopsstart >= 0) - { - /* Do we have a suspiciously long oops? Cancel it */ - if (i-oopsstart > 60) - { - inbacktrace = 0; - oopsstart = -1; - VERB3 log("Dropped oops, too long"); - continue; - } - if (!inbacktrace && i-oopsstart > 40) - { - /*inbacktrace = 0; - already is */ - oopsstart = -1; - VERB3 log("Dropped oops, too long"); - continue; - } - } - } /* while (i < linecount) */ - - /* process last oops if we have one */ - if (oopsstart >= 0 && inbacktrace) - { - int oopsend = i-1; - VERB3 log("End of oops at line %d (end of file): '%s'", oopsend, lines_info[oopsend].ptr); - if (record_oops(oopses, lines_info, oopsstart, oopsend)) - oopsesfound++; - } - - free(lines_info); - return oopsesfound; -} diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 52f3e4d1..eee328e0 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -57,6 +57,7 @@ libCCpp_la_CPPFLAGS = \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ $(GLIB_CFLAGS) \ + -D_GNU_SOURCE \ -Wall -Werror # -DHOSTILE_KERNEL libCCpp_la_LDFLAGS = \ @@ -65,12 +66,14 @@ libCCpp_la_LDFLAGS = \ # KerneloopsScanner libKerneloopsScanner_la_SOURCES = \ KerneloopsScanner.cpp KerneloopsScanner.h \ - KerneloopsSysLog.cpp KerneloopsSysLog.h + KerneloopsSysLog.c KerneloopsSysLog.h libKerneloopsScanner_la_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - $(GLIB_CFLAGS) + $(GLIB_CFLAGS) \ + -D_GNU_SOURCE \ + -Wall -Werror libKerneloopsScanner_la_LDFLAGS = \ -avoid-version \ $(GLIB_LIBS) @@ -187,7 +190,7 @@ abrt_action_bugzilla_LDADD = \ abrt_action_rhtsupport_SOURCES = \ abrt_rh_support.h abrt_rh_support.c \ - abrt-action-rhtsupport.cpp + abrt-action-rhtsupport.c abrt_action_rhtsupport_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ @@ -211,7 +214,7 @@ abrt_action_rhtsupport_LDADD = \ ../lib/libreport.la abrt_action_upload_SOURCES = \ - abrt-action-upload.cpp + abrt-action-upload.c abrt_action_upload_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ @@ -234,7 +237,7 @@ abrt_action_upload_LDADD = \ ../lib/libreport.la abrt_action_kerneloops_SOURCES = \ - abrt-action-kerneloops.cpp + abrt-action-kerneloops.c abrt_action_kerneloops_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ @@ -254,7 +257,7 @@ abrt_action_kerneloops_LDADD = \ ../lib/libreport.la abrt_action_mailx_SOURCES = \ - abrt-action-mailx.cpp + abrt-action-mailx.c abrt_action_mailx_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ @@ -273,7 +276,7 @@ abrt_action_mailx_LDADD = \ ../lib/libreport.la abrt_action_print_SOURCES = \ - abrt-action-print.cpp + abrt-action-print.c abrt_action_print_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c new file mode 100644 index 00000000..f3351ccd --- /dev/null +++ b/src/plugins/abrt-action-kerneloops.c @@ -0,0 +1,183 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + Authors: + Anton Arapov + Arjan van de Ven + */ + +#include +#include "abrtlib.h" +#include "abrt_crash_dump.h" + +#define PROGNAME "abrt-action-kerneloops" + +/* helpers */ +static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) +{ + size *= nmemb; +/* + char *c, *c1, *c2; + + log("received: '%*.*s'\n", (int)size, (int)size, (char*)ptr); + c = (char*)xzalloc(size + 1); + memcpy(c, ptr, size); + c1 = strstr(c, "201 "); + if (c1) + { + c1 += 4; + c2 = strchr(c1, '\n'); + if (c2) + *c2 = 0; + } + free(c); +*/ + + return size; +} + +/* Send oops data to kerneloops.org-style site, using HTTP POST */ +/* Returns 0 on success */ +static CURLcode http_post_to_kerneloops_site(const char *url, const char *oopsdata) +{ + CURLcode ret; + CURL *handle; + struct curl_httppost *post = NULL; + struct curl_httppost *last = NULL; + + handle = curl_easy_init(); + if (!handle) + error_msg_and_die("Can't create curl handle"); + + curl_easy_setopt(handle, CURLOPT_URL, url); + + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "oopsdata", + CURLFORM_COPYCONTENTS, oopsdata, + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "pass_on_allowed", + CURLFORM_COPYCONTENTS, "yes", + CURLFORM_END); + + curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction); + + ret = curl_easy_perform(handle); + + curl_formfree(post); + curl_easy_cleanup(handle); + + return ret; +} + +static void report_to_kerneloops( + const char *dump_dir_name, + map_string_h *settings) +{ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + exit(1); /* error msg is already logged */ + + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + dd_close(dd); + + const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); + if (!backtrace) + error_msg_and_die("Error sending kernel oops due to missing backtrace"); + + const char *env = getenv("KerneloopsReporter_SubmitURL"); + const char *submitURL = (env ? env : get_map_string_item_or_empty(settings, "SubmitURL")); + if (!submitURL[0]) + submitURL = "http://submit.kerneloops.org/submitoops.php"; + + log(_("Submitting oops report to %s"), submitURL); + + CURLcode ret = http_post_to_kerneloops_site(submitURL, backtrace); + if (ret != CURLE_OK) + error_msg_and_die("Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); + + free_crash_data(crash_data); + + /* Server replies with: + * 200 thank you for submitting the kernel oops information + * RemoteIP: 34192fd15e34bf60fac6a5f01bba04ddbd3f0558 + * - no URL or bug ID apparently... + */ + log("Kernel oops report was uploaded"); +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + map_string_h *settings = new_map_string(); + const char *dump_dir_name = "."; + enum { + OPT_s = (1 << 0), + }; + int optflags = 0; + int opt; + while ((opt = getopt(argc, argv, "c:d:vs")) != -1) + { + switch (opt) + { + case 'c': + VERB1 log("Loading settings from '%s'", optarg); + load_conf_file(optarg, settings, /*skip key w/o values:*/ true); + VERB3 log("Loaded '%s'", optarg); + break; + case 'd': + dump_dir_name = optarg; + break; + case 'v': + g_verbose++; + break; + case 's': + optflags |= OPT_s; + break; + default: + /* Careful: the string below contains tabs, dont replace with spaces */ + error_msg_and_die( + "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" + "\n" + "\nReport a kernel oops to kerneloops.org (or similar) site" + "\n" + "\nOptions:" + "\n -c FILE Configuration file (may be given many times)" + "\n -d DIR Crash dump directory" + "\n -v Verbose" + "\n -s Log to syslog" + ); + } + } + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + +//DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. +// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); + + if (optflags & OPT_s) + { + openlog(msg_prefix, 0, LOG_DAEMON); + logmode = LOGMODE_SYSLOG; + } + + report_to_kerneloops(dump_dir_name, settings); + + free_map_string(settings); + return 0; +} diff --git a/src/plugins/abrt-action-kerneloops.cpp b/src/plugins/abrt-action-kerneloops.cpp deleted file mode 100644 index f3351ccd..00000000 --- a/src/plugins/abrt-action-kerneloops.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - Authors: - Anton Arapov - Arjan van de Ven - */ - -#include -#include "abrtlib.h" -#include "abrt_crash_dump.h" - -#define PROGNAME "abrt-action-kerneloops" - -/* helpers */ -static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) -{ - size *= nmemb; -/* - char *c, *c1, *c2; - - log("received: '%*.*s'\n", (int)size, (int)size, (char*)ptr); - c = (char*)xzalloc(size + 1); - memcpy(c, ptr, size); - c1 = strstr(c, "201 "); - if (c1) - { - c1 += 4; - c2 = strchr(c1, '\n'); - if (c2) - *c2 = 0; - } - free(c); -*/ - - return size; -} - -/* Send oops data to kerneloops.org-style site, using HTTP POST */ -/* Returns 0 on success */ -static CURLcode http_post_to_kerneloops_site(const char *url, const char *oopsdata) -{ - CURLcode ret; - CURL *handle; - struct curl_httppost *post = NULL; - struct curl_httppost *last = NULL; - - handle = curl_easy_init(); - if (!handle) - error_msg_and_die("Can't create curl handle"); - - curl_easy_setopt(handle, CURLOPT_URL, url); - - curl_formadd(&post, &last, - CURLFORM_COPYNAME, "oopsdata", - CURLFORM_COPYCONTENTS, oopsdata, - CURLFORM_END); - curl_formadd(&post, &last, - CURLFORM_COPYNAME, "pass_on_allowed", - CURLFORM_COPYCONTENTS, "yes", - CURLFORM_END); - - curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); - curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction); - - ret = curl_easy_perform(handle); - - curl_formfree(post); - curl_easy_cleanup(handle); - - return ret; -} - -static void report_to_kerneloops( - const char *dump_dir_name, - map_string_h *settings) -{ - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - exit(1); /* error msg is already logged */ - - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); - dd_close(dd); - - const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); - if (!backtrace) - error_msg_and_die("Error sending kernel oops due to missing backtrace"); - - const char *env = getenv("KerneloopsReporter_SubmitURL"); - const char *submitURL = (env ? env : get_map_string_item_or_empty(settings, "SubmitURL")); - if (!submitURL[0]) - submitURL = "http://submit.kerneloops.org/submitoops.php"; - - log(_("Submitting oops report to %s"), submitURL); - - CURLcode ret = http_post_to_kerneloops_site(submitURL, backtrace); - if (ret != CURLE_OK) - error_msg_and_die("Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); - - free_crash_data(crash_data); - - /* Server replies with: - * 200 thank you for submitting the kernel oops information - * RemoteIP: 34192fd15e34bf60fac6a5f01bba04ddbd3f0558 - * - no URL or bug ID apparently... - */ - log("Kernel oops report was uploaded"); -} - -int main(int argc, char **argv) -{ - char *env_verbose = getenv("ABRT_VERBOSE"); - if (env_verbose) - g_verbose = atoi(env_verbose); - - map_string_h *settings = new_map_string(); - const char *dump_dir_name = "."; - enum { - OPT_s = (1 << 0), - }; - int optflags = 0; - int opt; - while ((opt = getopt(argc, argv, "c:d:vs")) != -1) - { - switch (opt) - { - case 'c': - VERB1 log("Loading settings from '%s'", optarg); - load_conf_file(optarg, settings, /*skip key w/o values:*/ true); - VERB3 log("Loaded '%s'", optarg); - break; - case 'd': - dump_dir_name = optarg; - break; - case 'v': - g_verbose++; - break; - case 's': - optflags |= OPT_s; - break; - default: - /* Careful: the string below contains tabs, dont replace with spaces */ - error_msg_and_die( - "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" - "\n" - "\nReport a kernel oops to kerneloops.org (or similar) site" - "\n" - "\nOptions:" - "\n -c FILE Configuration file (may be given many times)" - "\n -d DIR Crash dump directory" - "\n -v Verbose" - "\n -s Log to syslog" - ); - } - } - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - -//DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. -// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); - - if (optflags & OPT_s) - { - openlog(msg_prefix, 0, LOG_DAEMON); - logmode = LOGMODE_SYSLOG; - } - - report_to_kerneloops(dump_dir_name, settings); - - free_map_string(settings); - return 0; -} diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c new file mode 100644 index 00000000..ea26b9cb --- /dev/null +++ b/src/plugins/abrt-action-mailx.c @@ -0,0 +1,172 @@ +/* + Mailx.cpp + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + 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 "abrtlib.h" +#include "parse_options.h" +#include "abrt_crash_dump.h" + +#define PROGNAME "abrt-action-mailx" + +static void exec_and_feed_input(uid_t uid, const char* text, char **args) +{ + int pipein[2]; + + pid_t child = fork_execv_on_steroids( + EXECFLG_INPUT | EXECFLG_QUIET | EXECFLG_SETGUID, + args, + pipein, + /*unsetenv_vec:*/ NULL, + /*dir:*/ NULL, + uid); + + full_write_str(pipein[1], text); + close(pipein[1]); + + int status; + waitpid(child, &status, 0); /* wait for command completion */ + if (status != 0) + error_msg_and_die("Error running '%s'", args[0]); +} + +static char** append_str_to_vector(char **vec, unsigned *size_p, const char *str) +{ + //log("old vec: %p", vec); + unsigned size = *size_p; + vec = (char**) xrealloc(vec, (size+2) * sizeof(vec[0])); + vec[size] = xstrdup(str); + //log("new vec: %p, added [%d] %p", vec, size, vec[size]); + size++; + vec[size] = NULL; + *size_p = size; + return vec; +} + +static void create_and_send_email( + const char *dump_dir_name, + map_string_h *settings) +{ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + exit(1); /* error msg is already logged by dd_opendir */ + + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + dd_close(dd); + + char* env; + env = getenv("Mailx_Subject"); + const char *subject = (env ? env : get_map_string_item_or_NULL(settings, "Subject") ? : "[abrt] full crash report"); + env = getenv("Mailx_EmailFrom"); + const char *email_from = (env ? env : get_map_string_item_or_NULL(settings, "EmailFrom") ? : "user@localhost"); + env = getenv("Mailx_EmailTo"); + const char *email_to = (env ? env : get_map_string_item_or_NULL(settings, "EmailTo") ? : "root@localhost"); + env = getenv("Mailx_SendBinaryData"); + bool send_binary_data = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SendBinaryData")); + + char **args = NULL; + unsigned arg_size = 0; + args = append_str_to_vector(args, &arg_size, "/bin/mailx"); + + char *dsc = make_description_mailx(crash_data); + + if (send_binary_data) + { + GHashTableIter iter; + char *name; + struct crash_item *value; + g_hash_table_iter_init(&iter, crash_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) + { + if (value->flags & CD_FLAG_BIN) + { + args = append_str_to_vector(args, &arg_size, "-a"); + args = append_str_to_vector(args, &arg_size, value->content); + } + } + } + + args = append_str_to_vector(args, &arg_size, "-s"); + args = append_str_to_vector(args, &arg_size, subject); + args = append_str_to_vector(args, &arg_size, "-r"); + args = append_str_to_vector(args, &arg_size, email_from); + args = append_str_to_vector(args, &arg_size, email_to); + + log(_("Sending an email...")); + const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); + exec_and_feed_input(xatoi_positive(uid_str), dsc, args); + + free(dsc); + + while (*args) + free(*args++); + args -= arg_size; + free(args); + + free_crash_data(crash_data); + + log("Email was sent to: %s", email_to); +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + const char *dump_dir_name = "."; + const char *conf_file = NULL; + + const char *program_usage = _( + PROGNAME" [-v] -d DIR [-c CONFFILE]\n" + "\n" + "Upload compressed tarball of crash dump" + ); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_c = 1 << 2, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), + OPT_END() + }; + + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + //msg_prefix = PROGNAME; + //if (optflags & OPT_s) + //{ + // openlog(msg_prefix, 0, LOG_DAEMON); + // logmode = LOGMODE_SYSLOG; + //} + + map_string_h *settings = new_map_string(); + if (conf_file) + load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); + + create_and_send_email(dump_dir_name, settings); + + free_map_string(settings); + return 0; +} diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp deleted file mode 100644 index 8f613047..00000000 --- a/src/plugins/abrt-action-mailx.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - Mailx.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - 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 "abrtlib.h" -#include "parse_options.h" -#include "abrt_crash_dump.h" - -#define PROGNAME "abrt-action-mailx" - -static void exec_and_feed_input(uid_t uid, const char* text, char **args) -{ - int pipein[2]; - - pid_t child = fork_execv_on_steroids( - EXECFLG_INPUT | EXECFLG_QUIET | EXECFLG_SETGUID, - args, - pipein, - /*unsetenv_vec:*/ NULL, - /*dir:*/ NULL, - uid); - - full_write_str(pipein[1], text); - close(pipein[1]); - - int status; - waitpid(child, &status, 0); /* wait for command completion */ - if (status != 0) - error_msg_and_die("Error running '%s'", args[0]); -} - -static char** append_str_to_vector(char **vec, unsigned &size, const char *str) -{ - //log("old vec: %p", vec); - vec = (char**) xrealloc(vec, (size+2) * sizeof(vec[0])); - vec[size] = xstrdup(str); - //log("new vec: %p, added [%d] %p", vec, size, vec[size]); - size++; - vec[size] = NULL; - return vec; -} - -static void create_and_send_email( - const char *dump_dir_name, - map_string_h *settings) -{ - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - exit(1); /* error msg is already logged by dd_opendir */ - - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); - dd_close(dd); - - char* env; - env = getenv("Mailx_Subject"); - const char *subject = (env ? env : get_map_string_item_or_NULL(settings, "Subject") ? : "[abrt] full crash report"); - env = getenv("Mailx_EmailFrom"); - const char *email_from = (env ? env : get_map_string_item_or_NULL(settings, "EmailFrom") ? : "user@localhost"); - env = getenv("Mailx_EmailTo"); - const char *email_to = (env ? env : get_map_string_item_or_NULL(settings, "EmailTo") ? : "root@localhost"); - env = getenv("Mailx_SendBinaryData"); - bool send_binary_data = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SendBinaryData")); - - char **args = NULL; - unsigned arg_size = 0; - args = append_str_to_vector(args, arg_size, "/bin/mailx"); - - char *dsc = make_description_mailx(crash_data); - - if (send_binary_data) - { - GHashTableIter iter; - char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); - while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) - { - if (value->flags & CD_FLAG_BIN) - { - args = append_str_to_vector(args, arg_size, "-a"); - args = append_str_to_vector(args, arg_size, value->content); - } - } - } - - args = append_str_to_vector(args, arg_size, "-s"); - args = append_str_to_vector(args, arg_size, subject); - args = append_str_to_vector(args, arg_size, "-r"); - args = append_str_to_vector(args, arg_size, email_from); - args = append_str_to_vector(args, arg_size, email_to); - - log(_("Sending an email...")); - const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); - exec_and_feed_input(xatoi_positive(uid_str), dsc, args); - - free(dsc); - - while (*args) - free(*args++); - args -= arg_size; - free(args); - - free_crash_data(crash_data); - - log("Email was sent to: %s", email_to); -} - -int main(int argc, char **argv) -{ - char *env_verbose = getenv("ABRT_VERBOSE"); - if (env_verbose) - g_verbose = atoi(env_verbose); - - const char *dump_dir_name = "."; - const char *conf_file = NULL; - - const char *program_usage = _( - PROGNAME" [-v] -d DIR [-c CONFFILE]\n" - "\n" - "Upload compressed tarball of crash dump" - ); - enum { - OPT_v = 1 << 0, - OPT_d = 1 << 1, - OPT_c = 1 << 2, - }; - /* Keep enum above and order of options below in sync! */ - struct options program_options[] = { - OPT__VERBOSE(&g_verbose), - OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), - OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), - OPT_END() - }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //msg_prefix = PROGNAME; - //if (optflags & OPT_s) - //{ - // openlog(msg_prefix, 0, LOG_DAEMON); - // logmode = LOGMODE_SYSLOG; - //} - - map_string_h *settings = new_map_string(); - if (conf_file) - load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); - - create_and_send_email(dump_dir_name, settings); - - free_map_string(settings); - return 0; -} diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c new file mode 100644 index 00000000..55631c96 --- /dev/null +++ b/src/plugins/abrt-action-print.c @@ -0,0 +1,96 @@ +/* + Write crash dump to stdout in text form. + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + 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 "abrtlib.h" +#include "parse_options.h" +#include "abrt_crash_dump.h" + +#define PROGNAME "abrt-action-print" + +static const char *dump_dir_name = "."; +static const char *output_file = NULL; +static const char *open_mode = "w"; + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + const char *program_usage = _( + PROGNAME" [-v] [-o FILE] -d DIR\n" + "\n" + "Print information about the crash to standard output"); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_o = 1 << 2, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_STRING('o', NULL, &output_file , "FILE", _("Output file")), + OPT_END() + }; + + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + //msg_prefix = PROGNAME; + + char *env = getenv("Logger_LogPath"); + VERB3 log("output_file:'%s' Logger_LogPath env:'%s'", output_file, env); + if (env) + output_file = env; + + env = getenv("Logger_AppendLogs"); + VERB3 log("Logger_AppendLogs env:'%s'", env); + if (env && string_to_bool(env)) + open_mode = "a"; + + if (output_file) + { + if (!freopen(output_file, open_mode, stdout)) + { + perror_msg_and_die("Can't open '%s'", output_file); + } + } + + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + return 1; /* error message is already logged */ + + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + dd_close(dd); + + char *dsc = make_description_logger(crash_data); + fputs(dsc, stdout); + free(dsc); + free_crash_data(crash_data); + + if (output_file) + { + const char *format = (open_mode[0] == 'a' ? _("The report was appended to %s") : _("The report was stored to %s")); + log(format, output_file); + } + + return 0; +} diff --git a/src/plugins/abrt-action-print.cpp b/src/plugins/abrt-action-print.cpp deleted file mode 100644 index 55631c96..00000000 --- a/src/plugins/abrt-action-print.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - Write crash dump to stdout in text form. - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - 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 "abrtlib.h" -#include "parse_options.h" -#include "abrt_crash_dump.h" - -#define PROGNAME "abrt-action-print" - -static const char *dump_dir_name = "."; -static const char *output_file = NULL; -static const char *open_mode = "w"; - -int main(int argc, char **argv) -{ - char *env_verbose = getenv("ABRT_VERBOSE"); - if (env_verbose) - g_verbose = atoi(env_verbose); - - const char *program_usage = _( - PROGNAME" [-v] [-o FILE] -d DIR\n" - "\n" - "Print information about the crash to standard output"); - enum { - OPT_v = 1 << 0, - OPT_d = 1 << 1, - OPT_o = 1 << 2, - }; - /* Keep enum above and order of options below in sync! */ - struct options program_options[] = { - OPT__VERBOSE(&g_verbose), - OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), - OPT_STRING('o', NULL, &output_file , "FILE", _("Output file")), - OPT_END() - }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //msg_prefix = PROGNAME; - - char *env = getenv("Logger_LogPath"); - VERB3 log("output_file:'%s' Logger_LogPath env:'%s'", output_file, env); - if (env) - output_file = env; - - env = getenv("Logger_AppendLogs"); - VERB3 log("Logger_AppendLogs env:'%s'", env); - if (env && string_to_bool(env)) - open_mode = "a"; - - if (output_file) - { - if (!freopen(output_file, open_mode, stdout)) - { - perror_msg_and_die("Can't open '%s'", output_file); - } - } - - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - return 1; /* error message is already logged */ - - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); - dd_close(dd); - - char *dsc = make_description_logger(crash_data); - fputs(dsc, stdout); - free(dsc); - free_crash_data(crash_data); - - if (output_file) - { - const char *format = (open_mode[0] == 'a' ? _("The report was appended to %s") : _("The report was stored to %s")); - log(format, output_file); - } - - return 0; -} diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c new file mode 100644 index 00000000..024b1efc --- /dev/null +++ b/src/plugins/abrt-action-rhtsupport.c @@ -0,0 +1,321 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include "abrtlib.h" +#include "abrt_curl.h" +#include "abrt_xmlrpc.h" +#include "abrt_rh_support.h" +#include "abrt_crash_dump.h" + +#define PROGNAME "abrt-action-rhtsupport" + +static void report_to_rhtsupport( + const char *dump_dir_name, + map_string_h *settings) +{ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + exit(1); /* error msg is already logged by dd_opendir */ + + crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + dd_close(dd); + + /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ + log(_("Compressing data")); + + const char* errmsg = NULL; + TAR* tar = NULL; + pid_t child; + char* tempfile = NULL; + reportfile_t* file = NULL; + char* dsc = NULL; + char* summary = NULL; + const char* function; + const char* reason; + const char* package; + + char* env; + env = getenv("RHTSupport_URL"); + char *url = xstrdup(env ? env : (get_map_string_item_or_NULL(settings, "URL") ? : "https://api.access.redhat.com/rs")); + + env = getenv("RHTSupport_Login"); + char *login = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Login")); + + env = getenv("RHTSupport_Password"); + char *password = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Password")); + + env = getenv("RHTSupport_SSLVerify"); + bool ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); + + if (!login[0] || !password[0]) + { + errmsg = _("Empty login or password, please check RHTSupport.conf"); + goto ret; + } + + package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); + reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); + function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); + + { + struct strbuf *buf_summary = strbuf_new(); + strbuf_append_strf(buf_summary, "[abrt] %s", package); + if (function && strlen(function) < 30) + strbuf_append_strf(buf_summary, ": %s", function); + if (reason) + strbuf_append_strf(buf_summary, ": %s", reason); + summary = strbuf_free_nobuf(buf_summary); + + char *bz_dsc = make_description_bz(crash_data); + dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); + free(bz_dsc); + } + + file = new_reportfile(); + + /* SELinux guys are not happy with /tmp, using /var/run/abrt */ + tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); + + int pipe_from_parent_to_child[2]; + xpipe(pipe_from_parent_to_child); + child = fork(); + if (child == 0) + { + /* child */ + close(pipe_from_parent_to_child[1]); + xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1); + xmove_fd(pipe_from_parent_to_child[0], 0); + execlp("gzip", "gzip", NULL); + perror_msg_and_die("can't execute '%s'", "gzip"); + } + close(pipe_from_parent_to_child[0]); + + if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile, + /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) + { + errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + goto ret; + } + + { + GHashTableIter iter; + char *name; + struct crash_item *value; + g_hash_table_iter_init(&iter, crash_data); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) + { + if (strcmp(name, FILENAME_COUNT) == 0) continue; + if (strcmp(name, CD_DUMPDIR) == 0) continue; + if (strcmp(name, FILENAME_INFORMALL) == 0) continue; + if (strcmp(name, FILENAME_MESSAGE) == 0) continue; // plugin's status message (if we already reported it yesterday) + if (strcmp(name, FILENAME_DESCRIPTION) == 0) continue; // package description + + const char *content = value->content; + if (value->flags & CD_FLAG_TXT) + { + reportfile_add_binding_from_string(file, name, content); + } + else if (value->flags & CD_FLAG_BIN) + { + const char *basename = strrchr(content, '/'); + if (basename) + basename++; + else + basename = content; + char *xml_name = concat_path_file("content", basename); + reportfile_add_binding_from_namedfile(file, + /*on_disk_filename */ content, + /*binding_name */ name, + /*recorded_filename*/ xml_name, + /*binary */ 1); + if (tar_append_file(tar, (char*)content, xml_name) != 0) + { + errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + free(xml_name); + goto ret; + } + free(xml_name); + } + } + } + + /* Write out content.xml in the tarball's root */ + { + const char *signature = reportfile_as_string(file); + unsigned len = strlen(signature); + unsigned len512 = (len + 511) & ~511; + char *block = (char*)memcpy(xzalloc(len512), signature, len); + th_set_type(tar, S_IFREG | 0644); + th_set_mode(tar, S_IFREG | 0644); + //th_set_link(tar, char *linkname); + //th_set_device(tar, dev_t device); + //th_set_user(tar, uid_t uid); + //th_set_group(tar, gid_t gid); + //th_set_mtime(tar, time_t fmtime); + th_set_path(tar, (char*)"content.xml"); + th_set_size(tar, len); + th_finish(tar); /* caclulate and store th xsum etc */ + if (th_write(tar) != 0 + || full_write(tar_fd(tar), block, len512) != len512 + || tar_close(tar) != 0 + ) { + free(block); + errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + goto ret; + } + tar = NULL; + free(block); + } + + { + log(_("Creating a new case...")); + char* result = send_report_to_new_case(url, + login, + password, + ssl_verify, + summary, + dsc, + package, + tempfile + ); + /* Temporary hackish detection of errors. Ideally, + * send_report_to_new_case needs to have better error reporting. + */ + if (strncasecmp(result, "error", 5) == 0) + { + /* + * result can contain "...server says: 'multi-line text'" + * Replace all '\n' with spaces: + * we want this message to be, logically, one log entry. + * IOW: one line, not many lines. + */ + char *src, *dst; + dst = src = result; + while (1) + { + unsigned char c = *src++; + if (c == '\n') + c = ' '; + *dst++ = c; + if (c == '\0') + break; + } + /* Use sanitized string as error message */ + error_msg_and_die("%s", result); + } + /* No error */ + log("%s", result); + free(result); + } + + ret: + // Damn, selinux does not allow SIGKILLing our own child! wtf?? + //kill(child, SIGKILL); /* just in case */ + waitpid(child, NULL, 0); + if (tar) + tar_close(tar); + //close(pipe_from_parent_to_child[1]); - tar_close() does it itself + unlink(tempfile); + free(tempfile); + reportfile_free(file); + + free(summary); + free(dsc); + + free(url); + free(login); + free(password); + free_crash_data(crash_data); + + if (errmsg) + error_msg_and_die("%s", errmsg); +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + map_string_h *settings = new_map_string(); + const char *dump_dir_name = "."; + enum { + OPT_s = (1 << 0), + }; + int optflags = 0; + int opt; + while ((opt = getopt(argc, argv, "c:d:vs")) != -1) + { + switch (opt) + { + case 'c': + VERB1 log("Loading settings from '%s'", optarg); + load_conf_file(optarg, settings, /*skip key w/o values:*/ true); + VERB3 log("Loaded '%s'", optarg); + break; + case 'd': + dump_dir_name = optarg; + break; + case 'v': + g_verbose++; + break; + case 's': + optflags |= OPT_s; + break; + default: + /* Careful: the string below contains tabs, dont replace with spaces */ + error_msg_and_die( + "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" + "\n" + "\nReport a crash to RHTSupport" + "\n" + "\nOptions:" + "\n -c FILE Configuration file (may be given many times)" + "\n -d DIR Crash dump directory" + "\n -v Verbose" + "\n -s Log to syslog" + ); + } + } + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + +//DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. +// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); + + if (optflags & OPT_s) + { + openlog(msg_prefix, 0, LOG_DAEMON); + logmode = LOGMODE_SYSLOG; + } + + VERB1 log("Initializing XML-RPC library"); + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_client_setup_global_const(&env); + if (env.fault_occurred) + error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); + xmlrpc_env_clean(&env); + + report_to_rhtsupport(dump_dir_name, settings); + + free_map_string(settings); + return 0; +} diff --git a/src/plugins/abrt-action-rhtsupport.cpp b/src/plugins/abrt-action-rhtsupport.cpp deleted file mode 100644 index 024b1efc..00000000 --- a/src/plugins/abrt-action-rhtsupport.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include -#include "abrtlib.h" -#include "abrt_curl.h" -#include "abrt_xmlrpc.h" -#include "abrt_rh_support.h" -#include "abrt_crash_dump.h" - -#define PROGNAME "abrt-action-rhtsupport" - -static void report_to_rhtsupport( - const char *dump_dir_name, - map_string_h *settings) -{ - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - exit(1); /* error msg is already logged by dd_opendir */ - - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); - dd_close(dd); - - /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ - log(_("Compressing data")); - - const char* errmsg = NULL; - TAR* tar = NULL; - pid_t child; - char* tempfile = NULL; - reportfile_t* file = NULL; - char* dsc = NULL; - char* summary = NULL; - const char* function; - const char* reason; - const char* package; - - char* env; - env = getenv("RHTSupport_URL"); - char *url = xstrdup(env ? env : (get_map_string_item_or_NULL(settings, "URL") ? : "https://api.access.redhat.com/rs")); - - env = getenv("RHTSupport_Login"); - char *login = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Login")); - - env = getenv("RHTSupport_Password"); - char *password = xstrdup(env ? env : get_map_string_item_or_empty(settings, "Password")); - - env = getenv("RHTSupport_SSLVerify"); - bool ssl_verify = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SSLVerify")); - - if (!login[0] || !password[0]) - { - errmsg = _("Empty login or password, please check RHTSupport.conf"); - goto ret; - } - - package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); - reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); - function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION); - - { - struct strbuf *buf_summary = strbuf_new(); - strbuf_append_strf(buf_summary, "[abrt] %s", package); - if (function && strlen(function) < 30) - strbuf_append_strf(buf_summary, ": %s", function); - if (reason) - strbuf_append_strf(buf_summary, ": %s", reason); - summary = strbuf_free_nobuf(buf_summary); - - char *bz_dsc = make_description_bz(crash_data); - dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); - free(bz_dsc); - } - - file = new_reportfile(); - - /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); - - int pipe_from_parent_to_child[2]; - xpipe(pipe_from_parent_to_child); - child = fork(); - if (child == 0) - { - /* child */ - close(pipe_from_parent_to_child[1]); - xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1); - xmove_fd(pipe_from_parent_to_child[0], 0); - execlp("gzip", "gzip", NULL); - perror_msg_and_die("can't execute '%s'", "gzip"); - } - close(pipe_from_parent_to_child[0]); - - if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile, - /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) - { - errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - goto ret; - } - - { - GHashTableIter iter; - char *name; - struct crash_item *value; - g_hash_table_iter_init(&iter, crash_data); - while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) - { - if (strcmp(name, FILENAME_COUNT) == 0) continue; - if (strcmp(name, CD_DUMPDIR) == 0) continue; - if (strcmp(name, FILENAME_INFORMALL) == 0) continue; - if (strcmp(name, FILENAME_MESSAGE) == 0) continue; // plugin's status message (if we already reported it yesterday) - if (strcmp(name, FILENAME_DESCRIPTION) == 0) continue; // package description - - const char *content = value->content; - if (value->flags & CD_FLAG_TXT) - { - reportfile_add_binding_from_string(file, name, content); - } - else if (value->flags & CD_FLAG_BIN) - { - const char *basename = strrchr(content, '/'); - if (basename) - basename++; - else - basename = content; - char *xml_name = concat_path_file("content", basename); - reportfile_add_binding_from_namedfile(file, - /*on_disk_filename */ content, - /*binding_name */ name, - /*recorded_filename*/ xml_name, - /*binary */ 1); - if (tar_append_file(tar, (char*)content, xml_name) != 0) - { - errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - free(xml_name); - goto ret; - } - free(xml_name); - } - } - } - - /* Write out content.xml in the tarball's root */ - { - const char *signature = reportfile_as_string(file); - unsigned len = strlen(signature); - unsigned len512 = (len + 511) & ~511; - char *block = (char*)memcpy(xzalloc(len512), signature, len); - th_set_type(tar, S_IFREG | 0644); - th_set_mode(tar, S_IFREG | 0644); - //th_set_link(tar, char *linkname); - //th_set_device(tar, dev_t device); - //th_set_user(tar, uid_t uid); - //th_set_group(tar, gid_t gid); - //th_set_mtime(tar, time_t fmtime); - th_set_path(tar, (char*)"content.xml"); - th_set_size(tar, len); - th_finish(tar); /* caclulate and store th xsum etc */ - if (th_write(tar) != 0 - || full_write(tar_fd(tar), block, len512) != len512 - || tar_close(tar) != 0 - ) { - free(block); - errmsg = "can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - goto ret; - } - tar = NULL; - free(block); - } - - { - log(_("Creating a new case...")); - char* result = send_report_to_new_case(url, - login, - password, - ssl_verify, - summary, - dsc, - package, - tempfile - ); - /* Temporary hackish detection of errors. Ideally, - * send_report_to_new_case needs to have better error reporting. - */ - if (strncasecmp(result, "error", 5) == 0) - { - /* - * result can contain "...server says: 'multi-line text'" - * Replace all '\n' with spaces: - * we want this message to be, logically, one log entry. - * IOW: one line, not many lines. - */ - char *src, *dst; - dst = src = result; - while (1) - { - unsigned char c = *src++; - if (c == '\n') - c = ' '; - *dst++ = c; - if (c == '\0') - break; - } - /* Use sanitized string as error message */ - error_msg_and_die("%s", result); - } - /* No error */ - log("%s", result); - free(result); - } - - ret: - // Damn, selinux does not allow SIGKILLing our own child! wtf?? - //kill(child, SIGKILL); /* just in case */ - waitpid(child, NULL, 0); - if (tar) - tar_close(tar); - //close(pipe_from_parent_to_child[1]); - tar_close() does it itself - unlink(tempfile); - free(tempfile); - reportfile_free(file); - - free(summary); - free(dsc); - - free(url); - free(login); - free(password); - free_crash_data(crash_data); - - if (errmsg) - error_msg_and_die("%s", errmsg); -} - -int main(int argc, char **argv) -{ - char *env_verbose = getenv("ABRT_VERBOSE"); - if (env_verbose) - g_verbose = atoi(env_verbose); - - map_string_h *settings = new_map_string(); - const char *dump_dir_name = "."; - enum { - OPT_s = (1 << 0), - }; - int optflags = 0; - int opt; - while ((opt = getopt(argc, argv, "c:d:vs")) != -1) - { - switch (opt) - { - case 'c': - VERB1 log("Loading settings from '%s'", optarg); - load_conf_file(optarg, settings, /*skip key w/o values:*/ true); - VERB3 log("Loaded '%s'", optarg); - break; - case 'd': - dump_dir_name = optarg; - break; - case 'v': - g_verbose++; - break; - case 's': - optflags |= OPT_s; - break; - default: - /* Careful: the string below contains tabs, dont replace with spaces */ - error_msg_and_die( - "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" - "\n" - "\nReport a crash to RHTSupport" - "\n" - "\nOptions:" - "\n -c FILE Configuration file (may be given many times)" - "\n -d DIR Crash dump directory" - "\n -v Verbose" - "\n -s Log to syslog" - ); - } - } - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - -//DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. -// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); - - if (optflags & OPT_s) - { - openlog(msg_prefix, 0, LOG_DAEMON); - logmode = LOGMODE_SYSLOG; - } - - VERB1 log("Initializing XML-RPC library"); - xmlrpc_env env; - xmlrpc_env_init(&env); - xmlrpc_client_setup_global_const(&env); - if (env.fault_occurred) - error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); - xmlrpc_env_clean(&env); - - report_to_rhtsupport(dump_dir_name, settings); - - free_map_string(settings); - return 0; -} diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c new file mode 100644 index 00000000..8789f0e7 --- /dev/null +++ b/src/plugins/abrt-action-upload.c @@ -0,0 +1,287 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include +#include "abrtlib.h" +#include "parse_options.h" +#include "abrt_crash_dump.h" + +#define PROGNAME "abrt-action-upload" + +//TODO: use this for better logging +#if 0 +/* "read local data from a file" callback */ +static size_t fread_with_reporting(void *ptr, size_t size, size_t nmemb, void *userdata) +{ + static time_t last_t; // hack + + FILE *fp = (FILE*)userdata; + time_t t = time(NULL); + + // Report current file position every 16 seconds + if (!(t & 0xf) && last_t != t) + { + last_t = t; + off_t cur_pos = ftello(fp); + fseeko(fp, 0, SEEK_END); + off_t sz = ftello(fp); + fseeko(fp, cur_pos, SEEK_SET); + log(_("Uploaded: %llu of %llu kbytes"), + (unsigned long long)cur_pos / 1024, + (unsigned long long)sz / 1024); + } + + return fread(ptr, size, nmemb, fp); +} +#endif + +static int send_file(const char *url, const char *filename) +{ + FILE *fp = fopen(filename, "r"); + if (!fp) + { + perror_msg("Can't open '%s'", filename); + return 1; + } + + log(_("Sending %s to %s"), filename, url); + + struct stat stbuf; + fstat(fileno(fp), &stbuf); /* never fails */ + char *whole_url = concat_path_file(url, strrchr(filename, '/') ? : filename); + + CURL *curl = curl_easy_init(); + if (!curl) + { + error_msg_and_die("Can't create curl handle"); + } + /* Buffer[CURL_ERROR_SIZE] curl stores human readable error messages in. + * This may be more helpful than just return code from curl_easy_perform. + * curl will need it until curl_easy_cleanup. */ + char curl_err_msg[CURL_ERROR_SIZE]; + curl_err_msg[0] = '\0'; + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_msg); + /* enable uploading */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + /* specify target */ + curl_easy_setopt(curl, CURLOPT_URL, whole_url); + /* FILE handle: passed to the default callback, it will fread() it */ + curl_easy_setopt(curl, CURLOPT_READDATA, fp); + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)stbuf.st_size); + + /* everything is done here; result 0 means success */ + CURLcode result = curl_easy_perform(curl); + free(whole_url); + fclose(fp); + if (result != 0) + error_msg("Error while uploading: '%s'", curl_easy_strerror(result)); + else + /* This ends up a "reporting status message" in abrtd */ + log(_("Successfully sent %s to %s"), filename, url); + + curl_easy_cleanup(curl); + + return result; +} + +static int create_and_upload_archive( + const char *dump_dir_name, + map_string_h *settings) +{ + int result = 0; + + pid_t child; + TAR* tar = NULL; + const char* errmsg = NULL; + char* tempfile = NULL; + + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + exit(1); /* error msg is already logged by dd_opendir */ + + /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ + log(_("Compressing data")); + +//TODO: +//Encrypt = yes +//ArchiveType = .tar.bz2 +//ExcludeFiles = foo,bar*,b*z + char* env; + env = getenv("Upload_URL"); + const char *url = (env ? env : get_map_string_item_or_empty(settings, "URL")); + + /* Create a child gzip which will compress the data */ + /* SELinux guys are not happy with /tmp, using /var/run/abrt */ + tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); + int pipe_from_parent_to_child[2]; + xpipe(pipe_from_parent_to_child); + child = fork(); + if (child == 0) + { + /* child */ + close(pipe_from_parent_to_child[1]); + xmove_fd(pipe_from_parent_to_child[0], 0); + xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1); + execlp("gzip", "gzip", NULL); + perror_msg_and_die("can't execute '%s'", "gzip"); + } + close(pipe_from_parent_to_child[0]); + + /* Create tar writer object */ + if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile, + /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) + { + errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + goto ret; + } + + /* Write data to the tarball */ + { + dd_init_next_file(dd); + char *short_name, *full_name; + while (dd_get_next_file(dd, &short_name, &full_name)) + { + if (strcmp(short_name, FILENAME_COUNT) == 0) goto next; + if (strcmp(short_name, CD_DUMPDIR) == 0) goto next; + if (strcmp(short_name, FILENAME_INFORMALL) == 0) goto next; + if (strcmp(short_name, FILENAME_MESSAGE) == 0) goto next; // plugin's status message (if we already reported it yesterday) + if (strcmp(short_name, FILENAME_DESCRIPTION) == 0) goto next; // package description + // dd_get_next_file guarantees this: + //struct stat stbuf; + //if (stat(full_name, &stbuf) != 0) + // || !S_ISREG(stbuf.st_mode) + //) { + // goto next; + //} + if (tar_append_file(tar, full_name, short_name) != 0) + { + errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + free(short_name); + free(full_name); + goto ret; + } + next: + free(short_name); + free(full_name); + } + } + dd_close(dd); + dd = NULL; + + /* Close tar writer... */ + if (tar_append_eof(tar) != 0 || tar_close(tar) != 0) + { + errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + goto ret; + } + tar = NULL; + /* ...and check that gzip child finished successfully */ + int status; + waitpid(child, &status, 0); + child = -1; + if (status != 0) + { + /* We assume the error was out-of-disk-space or out-of-quota */ + errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; + goto ret; + } + + /* Upload the tarball */ + if (url && url[0]) + { + result = send_file(url, tempfile); + /* cleanup code will delete tempfile */ + } + else + { + log(_("Archive is created: '%s'"), tempfile); + free(tempfile); + tempfile = NULL; + } + + ret: + dd_close(dd); + if (tar) + tar_close(tar); + /* close(pipe_from_parent_to_child[1]); - tar_close() does it itself */ + if (child > 0) + waitpid(child, NULL, 0); + if (tempfile) + { + unlink(tempfile); + free(tempfile); + } + if (errmsg) + error_msg_and_die("%s", errmsg); + + return result; +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + const char *dump_dir_name = "."; + const char *conf_file = NULL; + const char *url = NULL; + + const char *program_usage = _( + PROGNAME" [-v] -d DIR [-c CONFFILE] [-u URL]\n" + "\n" + "Upload compressed tarball of crash dump" + ); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_c = 1 << 2, + OPT_u = 1 << 3, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), + OPT_STRING('u', NULL, &url , "URL" , _("Base URL to upload to")), + OPT_END() + }; + + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + //msg_prefix = PROGNAME; + //if (optflags & OPT_s) + //{ + // openlog(msg_prefix, 0, LOG_DAEMON); + // logmode = LOGMODE_SYSLOG; + //} + + map_string_h *settings = new_map_string(); + if (url) + g_hash_table_replace(settings, xstrdup("URL"), xstrdup(url)); + if (conf_file) + load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); + + int result = create_and_upload_archive(dump_dir_name, settings); + + free_map_string(settings); + return result; +} diff --git a/src/plugins/abrt-action-upload.cpp b/src/plugins/abrt-action-upload.cpp deleted file mode 100644 index 8789f0e7..00000000 --- a/src/plugins/abrt-action-upload.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include -#include -#include "abrtlib.h" -#include "parse_options.h" -#include "abrt_crash_dump.h" - -#define PROGNAME "abrt-action-upload" - -//TODO: use this for better logging -#if 0 -/* "read local data from a file" callback */ -static size_t fread_with_reporting(void *ptr, size_t size, size_t nmemb, void *userdata) -{ - static time_t last_t; // hack - - FILE *fp = (FILE*)userdata; - time_t t = time(NULL); - - // Report current file position every 16 seconds - if (!(t & 0xf) && last_t != t) - { - last_t = t; - off_t cur_pos = ftello(fp); - fseeko(fp, 0, SEEK_END); - off_t sz = ftello(fp); - fseeko(fp, cur_pos, SEEK_SET); - log(_("Uploaded: %llu of %llu kbytes"), - (unsigned long long)cur_pos / 1024, - (unsigned long long)sz / 1024); - } - - return fread(ptr, size, nmemb, fp); -} -#endif - -static int send_file(const char *url, const char *filename) -{ - FILE *fp = fopen(filename, "r"); - if (!fp) - { - perror_msg("Can't open '%s'", filename); - return 1; - } - - log(_("Sending %s to %s"), filename, url); - - struct stat stbuf; - fstat(fileno(fp), &stbuf); /* never fails */ - char *whole_url = concat_path_file(url, strrchr(filename, '/') ? : filename); - - CURL *curl = curl_easy_init(); - if (!curl) - { - error_msg_and_die("Can't create curl handle"); - } - /* Buffer[CURL_ERROR_SIZE] curl stores human readable error messages in. - * This may be more helpful than just return code from curl_easy_perform. - * curl will need it until curl_easy_cleanup. */ - char curl_err_msg[CURL_ERROR_SIZE]; - curl_err_msg[0] = '\0'; - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_msg); - /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - /* specify target */ - curl_easy_setopt(curl, CURLOPT_URL, whole_url); - /* FILE handle: passed to the default callback, it will fread() it */ - curl_easy_setopt(curl, CURLOPT_READDATA, fp); - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)stbuf.st_size); - - /* everything is done here; result 0 means success */ - CURLcode result = curl_easy_perform(curl); - free(whole_url); - fclose(fp); - if (result != 0) - error_msg("Error while uploading: '%s'", curl_easy_strerror(result)); - else - /* This ends up a "reporting status message" in abrtd */ - log(_("Successfully sent %s to %s"), filename, url); - - curl_easy_cleanup(curl); - - return result; -} - -static int create_and_upload_archive( - const char *dump_dir_name, - map_string_h *settings) -{ - int result = 0; - - pid_t child; - TAR* tar = NULL; - const char* errmsg = NULL; - char* tempfile = NULL; - - struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); - if (!dd) - exit(1); /* error msg is already logged by dd_opendir */ - - /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ - log(_("Compressing data")); - -//TODO: -//Encrypt = yes -//ArchiveType = .tar.bz2 -//ExcludeFiles = foo,bar*,b*z - char* env; - env = getenv("Upload_URL"); - const char *url = (env ? env : get_map_string_item_or_empty(settings, "URL")); - - /* Create a child gzip which will compress the data */ - /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); - int pipe_from_parent_to_child[2]; - xpipe(pipe_from_parent_to_child); - child = fork(); - if (child == 0) - { - /* child */ - close(pipe_from_parent_to_child[1]); - xmove_fd(pipe_from_parent_to_child[0], 0); - xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1); - execlp("gzip", "gzip", NULL); - perror_msg_and_die("can't execute '%s'", "gzip"); - } - close(pipe_from_parent_to_child[0]); - - /* Create tar writer object */ - if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile, - /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) - { - errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - goto ret; - } - - /* Write data to the tarball */ - { - dd_init_next_file(dd); - char *short_name, *full_name; - while (dd_get_next_file(dd, &short_name, &full_name)) - { - if (strcmp(short_name, FILENAME_COUNT) == 0) goto next; - if (strcmp(short_name, CD_DUMPDIR) == 0) goto next; - if (strcmp(short_name, FILENAME_INFORMALL) == 0) goto next; - if (strcmp(short_name, FILENAME_MESSAGE) == 0) goto next; // plugin's status message (if we already reported it yesterday) - if (strcmp(short_name, FILENAME_DESCRIPTION) == 0) goto next; // package description - // dd_get_next_file guarantees this: - //struct stat stbuf; - //if (stat(full_name, &stbuf) != 0) - // || !S_ISREG(stbuf.st_mode) - //) { - // goto next; - //} - if (tar_append_file(tar, full_name, short_name) != 0) - { - errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - free(short_name); - free(full_name); - goto ret; - } - next: - free(short_name); - free(full_name); - } - } - dd_close(dd); - dd = NULL; - - /* Close tar writer... */ - if (tar_append_eof(tar) != 0 || tar_close(tar) != 0) - { - errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - goto ret; - } - tar = NULL; - /* ...and check that gzip child finished successfully */ - int status; - waitpid(child, &status, 0); - child = -1; - if (status != 0) - { - /* We assume the error was out-of-disk-space or out-of-quota */ - errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt"; - goto ret; - } - - /* Upload the tarball */ - if (url && url[0]) - { - result = send_file(url, tempfile); - /* cleanup code will delete tempfile */ - } - else - { - log(_("Archive is created: '%s'"), tempfile); - free(tempfile); - tempfile = NULL; - } - - ret: - dd_close(dd); - if (tar) - tar_close(tar); - /* close(pipe_from_parent_to_child[1]); - tar_close() does it itself */ - if (child > 0) - waitpid(child, NULL, 0); - if (tempfile) - { - unlink(tempfile); - free(tempfile); - } - if (errmsg) - error_msg_and_die("%s", errmsg); - - return result; -} - -int main(int argc, char **argv) -{ - char *env_verbose = getenv("ABRT_VERBOSE"); - if (env_verbose) - g_verbose = atoi(env_verbose); - - const char *dump_dir_name = "."; - const char *conf_file = NULL; - const char *url = NULL; - - const char *program_usage = _( - PROGNAME" [-v] -d DIR [-c CONFFILE] [-u URL]\n" - "\n" - "Upload compressed tarball of crash dump" - ); - enum { - OPT_v = 1 << 0, - OPT_d = 1 << 1, - OPT_c = 1 << 2, - OPT_u = 1 << 3, - }; - /* Keep enum above and order of options below in sync! */ - struct options program_options[] = { - OPT__VERBOSE(&g_verbose), - OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), - OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), - OPT_STRING('u', NULL, &url , "URL" , _("Base URL to upload to")), - OPT_END() - }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //msg_prefix = PROGNAME; - //if (optflags & OPT_s) - //{ - // openlog(msg_prefix, 0, LOG_DAEMON); - // logmode = LOGMODE_SYSLOG; - //} - - map_string_h *settings = new_map_string(); - if (url) - g_hash_table_replace(settings, xstrdup("URL"), xstrdup(url)); - if (conf_file) - load_conf_file(conf_file, settings, /*skip key w/o values:*/ true); - - int result = create_and_upload_archive(dump_dir_name, settings); - - free_map_string(settings); - return result; -} -- cgit From 6a2b728d7525214402eff838bb37be175ddce6c3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 15 Dec 2010 18:44:55 +0100 Subject: Rename foo_crash_dump_dir -> foo_dump_dir To be exact, these three functions are renamed: load_crash_data_from_crash_dump_dir create_crash_dump_dir delete_crash_dump_dir Rationale: data structure is called "struct dump_dir", not "struct crash_dump_dir" Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 2 +- src/plugins/abrt-action-kerneloops.c | 2 +- src/plugins/abrt-action-mailx.c | 2 +- src/plugins/abrt-action-print.c | 2 +- src/plugins/abrt-action-rhtsupport.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index db492051..19acc4fe 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -639,7 +639,7 @@ static void report_to_bugzilla( struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) xfunc_die(); /* dd_opendir already emitted error msg */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); dd_close(dd); const char *env; diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index f3351ccd..ee4dce2f 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -90,7 +90,7 @@ static void report_to_kerneloops( if (!dd) exit(1); /* error msg is already logged */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); dd_close(dd); const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index ea26b9cb..4812e64f 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -67,7 +67,7 @@ static void create_and_send_email( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); dd_close(dd); char* env; diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 55631c96..4c28d3f3 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) if (!dd) return 1; /* error message is already logged */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); dd_close(dd); char *dsc = make_description_logger(crash_data); diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 024b1efc..7e950b0a 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -34,7 +34,7 @@ static void report_to_rhtsupport( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd); + crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); dd_close(dd); /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ -- 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/plugins/abrt-action-bugzilla.cpp | 2 +- src/plugins/abrt-action-kerneloops.c | 2 +- src/plugins/abrt-action-mailx.c | 2 +- src/plugins/abrt-action-print.c | 2 +- src/plugins/abrt-action-rhtsupport.c | 2 +- src/plugins/abrt-action-upload.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 19acc4fe..9174dbc3 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -18,7 +18,7 @@ */ #include "abrtlib.h" #include "abrt_xmlrpc.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define XML_RPC_SUFFIX "/xmlrpc.cgi" #define MAX_HOPS 5 diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index ee4dce2f..9cffab7d 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -19,7 +19,7 @@ #include #include "abrtlib.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define PROGNAME "abrt-action-kerneloops" diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index 4812e64f..6ade162e 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -21,7 +21,7 @@ #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define PROGNAME "abrt-action-mailx" diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 4c28d3f3..3e420768 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -20,7 +20,7 @@ */ #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define PROGNAME "abrt-action-print" diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 7e950b0a..77b6b1ff 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -22,7 +22,7 @@ #include "abrt_curl.h" #include "abrt_xmlrpc.h" #include "abrt_rh_support.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define PROGNAME "abrt-action-rhtsupport" diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index 8789f0e7..4bc5a458 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -21,7 +21,7 @@ #include #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #define PROGNAME "abrt-action-upload" -- cgit From dba326f60e159697a740f08959d098e19c200453 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 22 Dec 2010 16:28:39 +0100 Subject: extend run_event() to run_event_on_dir_name() and run_event_on_crash_data() Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 2 +- src/plugins/abrt-action-kerneloops.c | 2 +- src/plugins/abrt-action-mailx.c | 2 +- src/plugins/abrt-action-print.c | 2 +- src/plugins/abrt-action-rhtsupport.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 9174dbc3..00c3613c 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -639,7 +639,7 @@ static void report_to_bugzilla( struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) xfunc_die(); /* dd_opendir already emitted error msg */ - crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); const char *env; diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index 9cffab7d..5da54d13 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -90,7 +90,7 @@ static void report_to_kerneloops( if (!dd) exit(1); /* error msg is already logged */ - crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); const char *backtrace = get_crash_item_content_or_NULL(crash_data, FILENAME_BACKTRACE); diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index 6ade162e..00f73d03 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -67,7 +67,7 @@ static void create_and_send_email( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); char* env; diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 3e420768..86a9a1d0 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) if (!dd) return 1; /* error message is already logged */ - crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); char *dsc = make_description_logger(crash_data); diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 77b6b1ff..245a3ce0 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -34,7 +34,7 @@ static void report_to_rhtsupport( if (!dd) exit(1); /* error msg is already logged by dd_opendir */ - crash_data_t *crash_data = load_crash_data_from_dump_dir(dd); + crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ -- cgit From 5c62523ef0531243fbee0d58e19ecd808b431da6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 4 Jan 2011 11:57:38 +0100 Subject: koops: catch "kernel BUG at" with both small and capital K. Signed-off-by: Denys Vlasenko --- src/plugins/KerneloopsSysLog.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/KerneloopsSysLog.c b/src/plugins/KerneloopsSysLog.c index f69503af..162fd977 100644 --- a/src/plugins/KerneloopsSysLog.c +++ b/src/plugins/KerneloopsSysLog.c @@ -218,32 +218,39 @@ next_line: if (oopsstart < 0) { - /* find start-of-oops markers */ - if (strstr(curline, "general protection fault:")) + /* Find start-of-oops markers */ + /* In some comparisons, we skip 1st letter, to avoid dealing with + * changes in capitalization in kernel. For example, I see that + * current kernel git (at 2011-01-01) has both "kernel BUG at ..." + * and "Kernel BUG at ..." messages, and I don't want to change + * the code below whenever kernel is changed to use "K" (or "k") + * uniformly. + */ + if (strstr(curline, /*g*/ "eneral protection fault:")) oopsstart = i; else if (strstr(curline, "BUG:")) oopsstart = i; - else if (strstr(curline, "kernel BUG at")) + else if (strstr(curline, /*k*/ "ernel BUG at")) oopsstart = i; else if (strstr(curline, "do_IRQ: stack overflow:")) oopsstart = i; else if (strstr(curline, "RTNL: assertion failed")) oopsstart = i; - else if (strstr(curline, "Eeek! page_mapcount(page) went negative!")) + else if (strstr(curline, /*e*/ "eek! page_mapcount(page) went negative!")) oopsstart = i; - else if (strstr(curline, "near stack overflow (cur:")) + else if (strstr(curline, /*n*/ "ear stack overflow (cur:")) oopsstart = i; - else if (strstr(curline, "double fault:")) + else if (strstr(curline, /*d*/ "ouble fault:")) oopsstart = i; - else if (strstr(curline, "Badness at")) + else if (strstr(curline, /*b*/ "adness at")) oopsstart = i; else if (strstr(curline, "NETDEV WATCHDOG")) oopsstart = i; else if (strstr(curline, "WARNING: at ")) /* WARN_ON() generated message */ oopsstart = i; - else if (strstr(curline, "Unable to handle kernel")) + else if (strstr(curline, /*u*/ "nable to handle kernel")) oopsstart = i; - else if (strstr(curline, "sysctl table check failed")) + else if (strstr(curline, /*s*/ "ysctl table check failed")) oopsstart = i; else if (strstr(curline, "INFO: possible recursive locking detected")) oopsstart = i; @@ -251,11 +258,12 @@ next_line: // by "Badness at", "kernel BUG at", or "WARNING: at" string //else if (strstr(curline, "------------[ cut here ]------------")) // oopsstart = i; - else if (strstr(curline, "list_del corruption.")) + else if (strstr(curline, "list_del corruption")) oopsstart = i; - else if (strstr(curline, "list_add corruption.")) + else if (strstr(curline, "list_add corruption")) oopsstart = i; - if (strstr(curline, "Oops:") && i >= 3) + + if (i >= 3 && strstr(curline, "Oops:")) oopsstart = i-3; if (oopsstart >= 0) -- cgit From d108d7d2fbe0b178110295fd8335c258f699a5d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jan 2011 16:18:09 +0100 Subject: pass old pattern to ccpp hook and use it abrtd: instead of "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %p %s %u %c", sets coredump handler to "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %s %c %p %u %g %t %h %e OLD_PATTERN" abrt-ccpp-hook: expands OLD_PATTERN using values of %s %c %p %u %g %t %h %e and uses it as a name of "compat coredump". Patch has a feature which prevents usage of kernel-truncated OLD_PATTERN: it is passed as hex string *with terminating NUL* (encoded as 00). If ccpp hook doesn't see 00, it refuses to use OLD_PATTERN and uses string "core" instead. Run tested. On a new kernel, passes up to 27 char long old pattern. Longer patterns are still truncated. This may be improved in future kernels. Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 55 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index d88a593d..df2c4482 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -26,16 +26,28 @@ using namespace std; #define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u %c" +/* + * %s - signal number + * %c - ulimit -c value + * %p - pid + * %u - uid + * %g - gid + * %t - UNIX time of dump + * %h - hostname + * %e - executable filename + * %% - output one "%" + */ +#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %s %c %p %u %g %t %h %e" + #define CORE_PIPE_LIMIT_IFACE "/proc/sys/kernel/core_pipe_limit" /* core_pipe_limit specifies how many dump_helpers might run at the same time * 0 - means unlimited, but it's not guaranteed that /proc/ of crashing - * process will be available for dump_helper + * process will be available for dump_helper. * 4 - means that 4 dump_helpers can run at the same time (the rest will also - * run, but they will fail to read /proc/) - * This should be enough for ABRT, we can miss some crashes, but what are - * the odds that more processes crash at the same time? - * The value of 4 has been recommended by nhorman. + * run, but they will fail to read /proc/). + * This should be enough for ABRT, we can miss some crashes, but what are + * the odds that more processes crash at the same time? + * The value of 4 has been recommended by nhorman. */ #define CORE_PIPE_LIMIT "4" @@ -133,7 +145,7 @@ void CAnalyzerCCpp::Init() } if (m_sOldCorePattern[0] == '|') { - if (m_sOldCorePattern == CORE_PATTERN) + if (strncmp(m_sOldCorePattern.c_str(), CORE_PATTERN, strlen(CORE_PATTERN)) == 0) { log("warning: %s already contains %s, " "did abrt daemon crash recently?", @@ -157,14 +169,35 @@ void CAnalyzerCCpp::Init() fp = fopen(CORE_PATTERN_IFACE, "w"); if (fp) { - fputs(CORE_PATTERN, fp); + if (m_sOldCorePattern[0] != '|') + { + const char *old = m_sOldCorePattern.c_str(); + unsigned len = strchrnul(old, '\n') - old; + char *hex_old = (char*)xmalloc(len * 2 + 1); + bin2hex(hex_old, old, len)[0] = '\0'; + /* Trailing 00 is a sentinel. Decoder in the hook will check it. + * If it won't see it, then kernel has truncated the argument: + */ + char *pattern = xasprintf("%s %s00", CORE_PATTERN, hex_old); + //log("old:'%s'->'%s'", old, hex_old); + //log("pattern:'%s'", pattern); + + fputs(pattern, fp); + + free(pattern); + free(hex_old); + } + else + { + fputs(CORE_PATTERN, fp); + } fclose(fp); } /* read the core_pipe_limit and change it if it's == 0 - otherwise the abrt-hook-ccpp won't be able to read /proc/ - of the crashing process - */ + * otherwise the abrt-hook-ccpp won't be able to read /proc/ + * of the crashing process + */ fp = fopen(CORE_PIPE_LIMIT_IFACE, "r"); if (fp) { -- cgit From 489b91669a8767d87ea03110544134deb62c4355 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jan 2011 17:54:20 +0100 Subject: adding missing extern "C" {} This fixes the following problem: abrtd: Can't load '/usr/lib64/abrt/libKerneloopsScanner.so': /usr/lib64/abrt/libKerneloopsScanner.so: undefined symbol: _Z14extract_oopsesPP6_GListPcm Signed-off-by: Denys Vlasenko --- src/plugins/KerneloopsSysLog.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/KerneloopsSysLog.h b/src/plugins/KerneloopsSysLog.h index d8b4d32b..eeaaed6b 100644 --- a/src/plugins/KerneloopsSysLog.h +++ b/src/plugins/KerneloopsSysLog.h @@ -30,6 +30,14 @@ #include "abrt_types.h" #include +#ifdef __cplusplus +extern "C" { +#endif + int extract_oopses(GList **oopses, char *buffer, size_t buflen); +#ifdef __cplusplus +} +#endif + #endif -- cgit From c4bdeaeb27855878c6caadaa6b85fa566bc09677 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 Jan 2011 14:40:48 +0100 Subject: move abrt-action-FOO from /usr/libexec to /usr/bin Signed-off-by: Denys Vlasenko --- src/plugins/Makefile.am | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index eee328e0..c960e66e 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -1,8 +1,20 @@ pluginslibdir = $(PLUGINS_LIB_DIR) -libexec_SCRIPTS = \ +bin_SCRIPTS = \ abrt-action-install-debuginfo.py +bin_PROGRAMS = \ + abrt-action-analyze-c \ + abrt-action-analyze-python \ + abrt-action-analyze-oops \ + abrt-action-generate-backtrace \ + abrt-action-bugzilla \ + abrt-action-rhtsupport \ + abrt-action-kerneloops \ + abrt-action-upload \ + abrt-action-mailx \ + abrt-action-print + pluginslib_LTLIBRARIES = \ libCCpp.la \ libKerneloopsScanner.la @@ -78,18 +90,6 @@ libKerneloopsScanner_la_LDFLAGS = \ -avoid-version \ $(GLIB_LIBS) -libexec_PROGRAMS = \ - abrt-action-analyze-c \ - abrt-action-analyze-python \ - abrt-action-analyze-oops \ - abrt-action-generate-backtrace \ - abrt-action-bugzilla \ - abrt-action-rhtsupport \ - abrt-action-kerneloops \ - abrt-action-upload \ - abrt-action-mailx \ - abrt-action-print - abrt_action_analyze_c_SOURCES = \ abrt-action-analyze-c.c abrt_action_analyze_c_CPPFLAGS = \ -- cgit From dc4d0c9a4034769089776755f80c20159ed26653 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 13 Jan 2011 18:56:10 +0100 Subject: trivial: more uniform -v option help Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 2 +- src/plugins/abrt-action-kerneloops.c | 2 +- src/plugins/abrt-action-rhtsupport.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 00c3613c..19735452 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -936,7 +936,7 @@ int main(int argc, char **argv) "\nOptions:" "\n -c FILE Configuration file (may be given many times)" "\n -d DIR Crash dump directory" - "\n -v Verbose" + "\n -v Be verbose" "\n -s Log to syslog" ); } diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index 5da54d13..160b6412 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -159,7 +159,7 @@ int main(int argc, char **argv) "\nOptions:" "\n -c FILE Configuration file (may be given many times)" "\n -d DIR Crash dump directory" - "\n -v Verbose" + "\n -v Be verbose" "\n -s Log to syslog" ); } diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 245a3ce0..a596ac40 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -289,7 +289,7 @@ int main(int argc, char **argv) "\nOptions:" "\n -c FILE Configuration file (may be given many times)" "\n -d DIR Crash dump directory" - "\n -v Verbose" + "\n -v Be verbose" "\n -s Log to syslog" ); } -- cgit From e796e95a4efbfeb04223f61c600c7712da7b500f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jan 2011 16:39:11 +0100 Subject: replace KerneloopsScanner plugin and dumpoops with abrt-dump-oops, use it in abrtd Patch adds new tool: $ abrt-dump-oops Usage: abrt-dump-oops [-vsrdow] FILE Extract oops from syslog/dmesg file -v, --verbose Be verbose -s Log to syslog -r Parse kernel's message buffer before parsing FILE -d Create ABRT dump for every oops found -o Print found oopses on standard output -w Do not exit, watch the file for new oopses It extends dumpoops. Extensions: * it can watch the syslog using -w option (uses inotify) * it can scan dmesg buffer too In this way, it also becomes a replacement for KerneloopsScanner plugin: oops-detecting logic is taken verbatim from KerneloopsScanner source. abrtd is changed to start it if it sees this directive in abrt.conf: [ LogScanners ] abrt-dump-oops = abrt-dump-oops -drw /var/log/messages Default abrt.conf is changed to have such line. Patch doesn't remove KerneloopsScanner plugin and dumpoops binary yet, I will do it in a separate trivial patch. Signed-off-by: Denys Vlasenko --- src/plugins/Makefile.am | 20 ++ src/plugins/abrt-dump-oops.c | 712 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 732 insertions(+) create mode 100644 src/plugins/abrt-dump-oops.c (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index c960e66e..5d3b5890 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -4,6 +4,7 @@ bin_SCRIPTS = \ abrt-action-install-debuginfo.py bin_PROGRAMS = \ + abrt-dump-oops \ abrt-action-analyze-c \ abrt-action-analyze-python \ abrt-action-analyze-oops \ @@ -90,6 +91,25 @@ libKerneloopsScanner_la_LDFLAGS = \ -avoid-version \ $(GLIB_LIBS) +abrt_dump_oops_SOURCES = \ + abrt-dump-oops.c +abrt_dump_oops_CPPFLAGS = \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -I$(srcdir)/../lib \ + -DBIN_DIR=\"$(bindir)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ + -D_GNU_SOURCE \ + -Wall -Werror +abrt_dump_oops_LDADD = \ + ../lib/libreport.la + abrt_action_analyze_c_SOURCES = \ abrt-action-analyze-c.c abrt_action_analyze_c_CPPFLAGS = \ diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c new file mode 100644 index 00000000..ad222edd --- /dev/null +++ b/src/plugins/abrt-dump-oops.c @@ -0,0 +1,712 @@ +/* + Copyright (C) 2011 ABRT team + Copyright (C) 2011 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + Authors: + Anton Arapov + Arjan van de Ven + */ +#include +#include /* __NR_syslog */ +#include +#include /* ioctl(FIONREAD) */ +#include "abrtlib.h" +#include "parse_options.h" + +#define PROGNAME "abrt-dump-oops" + +static void queue_oops(GList **vec, const char *data, const char *version) +{ + char *ver_data = xasprintf("%s\n%s", version, data); + *vec = g_list_append(*vec, ver_data); +} + +/* + * extract_version tries to find the kernel version in given data + */ +static char *extract_version(const char *linepointer) +{ + if (strstr(linepointer, "Pid") + || strstr(linepointer, "comm") + || strstr(linepointer, "CPU") + || strstr(linepointer, "REGS") + || strstr(linepointer, "EFLAGS") + ) { + char* start; + char* end; + + start = strstr((char*)linepointer, "2.6."); + if (start) + { + end = strchr(start, ')'); + if (!end) + end = strchrnul(start, ' '); + return xstrndup(start, end-start); + } + } + + return NULL; +} + +/* + * extract_oops tries to find oops signatures in a log + */ +struct line_info { + char *ptr; + char level; +}; + +static int record_oops(GList **oopses, struct line_info* lines_info, int oopsstart, int oopsend) +{ + int q; + int len; + char *oops; + char *version; + + len = 2; + for (q = oopsstart; q <= oopsend; q++) + len += strlen(lines_info[q].ptr) + 1; + + oops = (char*)xzalloc(len); + + version = NULL; + for (q = oopsstart; q <= oopsend; q++) + { + if (!version) + version = extract_version(lines_info[q].ptr); + + if (lines_info[q].ptr[0]) + { + strcat(oops, lines_info[q].ptr); + strcat(oops, "\n"); + } + } + int rv = 1; + /* too short oopses are invalid */ + if (strlen(oops) > 100) + queue_oops(oopses, oops, version ? version : "undefined"); + else + { + VERB3 log("Dropped oops: too short"); + rv = 0; + } + free(oops); + free(version); + return rv; +} + +#define REALLOC_CHUNK 1000 +static int extract_oopses(GList **oopses, char *buffer, size_t buflen) +{ + char *c; + int linecount = 0; + int lines_info_alloc = 0; + struct line_info *lines_info = NULL; + + /* Split buffer into lines */ + + if (buflen != 0) + buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ + c = buffer; + while (c < buffer + buflen) + { + char linelevel; + char *c9; + char *colon; + + c9 = (char*)memchr(c, '\n', buffer + buflen - c); /* a \n will always be found */ + assert(c9); + *c9 = '\0'; /* turn the \n into a string termination */ + if (c9 == c) + goto next_line; + + /* Is it a syslog file (/var/log/messages or similar)? + * Even though _usually_ it looks like "Nov 19 12:34:38 localhost kernel: xxx", + * some users run syslog in non-C locale: + * "2010-02-22T09:24:08.156534-08:00 gnu-4 gnome-session[2048]: blah blah" + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !!! + * We detect it by checking for N:NN:NN pattern in first 15 chars + * (and this still is not good enough... false positive: "pci 0000:15:00.0: PME# disabled") + */ + colon = strchr(c, ':'); + if (colon && colon > c && colon < c + 15 + && isdigit(colon[-1]) /* N:... */ + && isdigit(colon[1]) /* ...N:NN:... */ + && isdigit(colon[2]) + && colon[3] == ':' + && isdigit(colon[4]) /* ...N:NN:NN... */ + && isdigit(colon[5]) + ) { + /* It's syslog file, not a bare dmesg */ + + /* Skip non-kernel lines */ + char *kernel_str = strstr(c, "kernel: "); + if (kernel_str == NULL) + { + /* if we see our own marker: + * "hostname abrt: Kerneloops: Reported 1 kernel oopses to Abrt" + * we know we submitted everything upto here already */ + if (strstr(c, "abrt:") && strstr(c, "Abrt")) + { + VERB3 log("Found our marker at line %d, restarting line count from 0", linecount); + linecount = 0; + lines_info_alloc = 0; + free(lines_info); + lines_info = NULL; + } + goto next_line; + } + c = kernel_str + sizeof("kernel: ")-1; + } + + linelevel = 0; + /* store and remove kernel log level */ + if (*c == '<' && c[1] && c[2] == '>') + { + linelevel = c[1]; + c += 3; + } + /* remove jiffies time stamp counter if present */ + if (*c == '[') + { + char *c2 = strchr(c, '.'); + char *c3 = strchr(c, ']'); + if (c2 && c3 && (c2 < c3) && (c3-c) < 14 && (c2-c) < 8) + { + c = c3 + 1; + if (*c == ' ') + c++; + } + } + if (linecount >= lines_info_alloc) + { + lines_info_alloc += REALLOC_CHUNK; + lines_info = (struct line_info*)xrealloc(lines_info, + lines_info_alloc * sizeof(lines_info[0])); + } + lines_info[linecount].ptr = c; + lines_info[linecount].level = linelevel; + linecount++; +next_line: + c = c9 + 1; + } + + /* Analyze lines */ + + int i; + char prevlevel = 0; + int oopsstart = -1; + int inbacktrace = 0; + int oopsesfound = 0; + + i = 0; + while (i < linecount) + { + char *curline = lines_info[i].ptr; + + if (curline == NULL) + { + i++; + continue; + } + while (*curline == ' ') + curline++; + + if (oopsstart < 0) + { + /* Find start-of-oops markers */ + /* In some comparisons, we skip 1st letter, to avoid dealing with + * changes in capitalization in kernel. For example, I see that + * current kernel git (at 2011-01-01) has both "kernel BUG at ..." + * and "Kernel BUG at ..." messages, and I don't want to change + * the code below whenever kernel is changed to use "K" (or "k") + * uniformly. + */ + if (strstr(curline, /*g*/ "eneral protection fault:")) + oopsstart = i; + else if (strstr(curline, "BUG:")) + oopsstart = i; + else if (strstr(curline, /*k*/ "ernel BUG at")) + oopsstart = i; + else if (strstr(curline, "do_IRQ: stack overflow:")) + oopsstart = i; + else if (strstr(curline, "RTNL: assertion failed")) + oopsstart = i; + else if (strstr(curline, /*e*/ "eek! page_mapcount(page) went negative!")) + oopsstart = i; + else if (strstr(curline, /*n*/ "ear stack overflow (cur:")) + oopsstart = i; + else if (strstr(curline, /*d*/ "ouble fault:")) + oopsstart = i; + else if (strstr(curline, /*b*/ "adness at")) + oopsstart = i; + else if (strstr(curline, "NETDEV WATCHDOG")) + oopsstart = i; + else if (strstr(curline, "WARNING: at ")) /* WARN_ON() generated message */ + oopsstart = i; + else if (strstr(curline, /*u*/ "nable to handle kernel")) + oopsstart = i; + else if (strstr(curline, /*s*/ "ysctl table check failed")) + oopsstart = i; + else if (strstr(curline, "INFO: possible recursive locking detected")) + oopsstart = i; + // Not needed: "--[ cut here ]--" is always followed + // by "Badness at", "kernel BUG at", or "WARNING: at" string + //else if (strstr(curline, "------------[ cut here ]------------")) + // oopsstart = i; + else if (strstr(curline, "list_del corruption")) + oopsstart = i; + else if (strstr(curline, "list_add corruption")) + oopsstart = i; + + if (i >= 3 && strstr(curline, "Oops:")) + oopsstart = i-3; + + if (oopsstart >= 0) + { + /* debug information */ + VERB3 { + log("Found oops at line %d: '%s'", oopsstart, lines_info[oopsstart].ptr); + if (oopsstart != i) + log("Trigger line is %d: '%s'", i, c); + } + /* try to find the end marker */ + int i2 = i + 1; + while (i2 < linecount && i2 < (i+50)) + { + if (strstr(lines_info[i2].ptr, "---[ end trace")) + { + inbacktrace = 1; + i = i2; + break; + } + i2++; + } + } + } + + /* Are we entering a call trace part? */ + /* a call trace starts with "Call Trace:" or with the " [<.......>] function+0xFF/0xAA" pattern */ + if (oopsstart >= 0 && !inbacktrace) + { + if (strstr(curline, "Call Trace:")) + inbacktrace = 1; + else + if (strnlen(curline, 9) > 8 + && curline[0] == '[' && curline[1] == '<' + && strstr(curline, ">]") + && strstr(curline, "+0x") + && strstr(curline, "/0x") + ) { + inbacktrace = 1; + } + } + + /* Are we at the end of an oops? */ + else if (oopsstart >= 0 && inbacktrace) + { + int oopsend = INT_MAX; + + /* line needs to start with " [" or have "] [" if it is still a call trace */ + /* example: "[] radeon_get_ring_head+0x16/0x41 [radeon]" */ + if (curline[0] != '[' + && !strstr(curline, "] [") + && !strstr(curline, "--- Exception") + && !strstr(curline, "LR =") + && !strstr(curline, "<#DF>") + && !strstr(curline, "") + && !strstr(curline, "") + && !strstr(curline, "<>") + && strncmp(curline, "Code: ", 6) != 0 + && strncmp(curline, "RIP ", 4) != 0 + && strncmp(curline, "RSP ", 4) != 0 + ) { + oopsend = i-1; /* not a call trace line */ + } + /* oops lines are always more than 8 chars long */ + else if (strnlen(curline, 8) < 8) + oopsend = i-1; + /* single oopses are of the same loglevel */ + else if (lines_info[i].level != prevlevel) + oopsend = i-1; + else if (strstr(curline, "Instruction dump:")) + oopsend = i; + /* if a new oops starts, this one has ended */ + else if (strstr(curline, "WARNING: at ") && oopsstart != i) /* WARN_ON() generated message */ + oopsend = i-1; + else if (strstr(curline, "Unable to handle") && oopsstart != i) + oopsend = i-1; + /* kernel end-of-oops marker (not including marker itself) */ + else if (strstr(curline, "---[ end trace")) + oopsend = i-1; + + if (oopsend <= i) + { + VERB3 log("End of oops at line %d (%d): '%s'", oopsend, i, lines_info[oopsend].ptr); + if (record_oops(oopses, lines_info, oopsstart, oopsend)) + oopsesfound++; + oopsstart = -1; + inbacktrace = 0; + } + } + + prevlevel = lines_info[i].level; + i++; + + if (oopsstart >= 0) + { + /* Do we have a suspiciously long oops? Cancel it */ + if (i-oopsstart > 60) + { + inbacktrace = 0; + oopsstart = -1; + VERB3 log("Dropped oops, too long"); + continue; + } + if (!inbacktrace && i-oopsstart > 40) + { + /*inbacktrace = 0; - already is */ + oopsstart = -1; + VERB3 log("Dropped oops, too long"); + continue; + } + } + } /* while (i < linecount) */ + + /* process last oops if we have one */ + if (oopsstart >= 0 && inbacktrace) + { + int oopsend = i-1; + VERB3 log("End of oops at line %d (end of file): '%s'", oopsend, lines_info[oopsend].ptr); + if (record_oops(oopses, lines_info, oopsstart, oopsend)) + oopsesfound++; + } + + free(lines_info); + return oopsesfound; +} + +#define MAX_SCAN_BLOCK (4*1024*1024) +#define READ_AHEAD (10*1024) + +static void scan_dmesg(GList **oops_list) +{ + VERB1 log("Scanning dmesg"); + + /* syslog(3) - read the last len bytes from the log buffer + * (non-destructively), but dont read more than was written + * into the buffer since the last "clear ring buffer" cmd. + * Returns the number of bytes read. + */ + char *buffer = xzalloc(16*1024); + syscall(__NR_syslog, 3, buffer, 16*1024 - 1); /* always NUL terminated */ + extract_oopses(oops_list, buffer, strlen(buffer)); + free(buffer); +} + +static int scan_syslog_file(GList **oops_list, int fd, struct stat *statbuf, int partial_line_len) +{ + /* fstat(fd, &statbuf) was just done by caller */ + + off_t cur_pos = lseek(fd, 0, SEEK_CUR); + if (statbuf->st_size <= cur_pos) + return partial_line_len; /* we are at EOF, nothing to do */ + + VERB3 log("File grew by %llu bytes, from %llu to %llu", + (long long)(statbuf->st_size - cur_pos), + (long long)(cur_pos), + (long long)(statbuf->st_size)); + + /* Do not try to allocate an absurd amount of memory. */ + int sz = MAX_SCAN_BLOCK - READ_AHEAD; + if (sz > statbuf->st_size - cur_pos) + sz = statbuf->st_size - cur_pos; + + /* Rewind to the beginning of the current line */ + if (partial_line_len > 0 && lseek(fd, -partial_line_len, SEEK_CUR) != (off_t)-1) + { + VERB3 log("Went back %u bytes", partial_line_len); + cur_pos -= partial_line_len; + sz += partial_line_len; + } + + /* + * In theory we have a race here, since someone can spew + * to /var/log/messages before we read it in... + * We try to deal with it by reading READ_AHEAD extra. + */ + sz += READ_AHEAD; + char *buffer = xzalloc(sz); + + partial_line_len = 0; + do { + int r = full_read(fd, buffer, sz-1); + if (r <= 0) + break; + VERB3 log("Read %u bytes", r); + + /* For future scans, try to find where last (incomplete) line starts */ + partial_line_len = 0; + char *last_newline = memrchr(buffer, '\n', r) ? : buffer-1; + partial_line_len = buffer+r - (last_newline+1); + if (partial_line_len > 500) /* cap it */ + partial_line_len = 500; + + extract_oopses(oops_list, buffer, r); + cur_pos += r; + } while (cur_pos < statbuf->st_size); + + free(buffer); + + return partial_line_len; +} + +/* returns number of errors */ +static int save_oops_to_dump_dir(GList *oops_list, unsigned oops_cnt) +{ + unsigned countdown = 16; /* do not report hundreds of oopses */ + unsigned idx = oops_cnt; + time_t t = time(NULL); + pid_t my_pid = getpid(); + + VERB1 log("Saving %u oopses as crash dump dirs", idx >= countdown ? countdown-1 : idx); + + char *tainted_str = NULL; + /* once tainted flag is set to 1, only restart can reset the flag to 0 */ + FILE *tainted_fp = fopen("/proc/sys/kernel/tainted", "r"); + if (tainted_fp) + { + tainted_str = xmalloc_fgetline(tainted_fp); + fclose(tainted_fp); + } + else + error_msg("/proc/sys/kernel/tainted does not exist"); + + int errors = 0; + + while (idx != 0 && --countdown != 0) + { + char path[sizeof(DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu-%lu") + 3 * sizeof(long)*3]; + sprintf(path, DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu-%lu", (long)t, (long)my_pid, (long)idx); + + char *first_line = (char*)g_list_nth_data(oops_list, --idx); + char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */ + *second_line++ = '\0'; + + struct dump_dir *dd = dd_create(path, /*uid:*/ 0); + if (dd) + { + dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops"); + dd_save_text(dd, FILENAME_EXECUTABLE, "kernel"); + dd_save_text(dd, FILENAME_KERNEL, first_line); + dd_save_text(dd, FILENAME_CMDLINE, "not_applicable"); + dd_save_text(dd, FILENAME_BACKTRACE, second_line); + /* Optional, makes generated bz more informative */ + strchrnul(second_line, '\n')[0] = '\0'; + dd_save_text(dd, FILENAME_REASON, second_line); + + if (tainted_str && tainted_str[0] != '0') + dd_save_text(dd, FILENAME_TAINTED, tainted_str); + + free(tainted_str); + dd_close(dd); + } + else + errors++; + } + + return errors; +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + const char *filename = "/var/log/messages"; + + const char *program_usage = _( + PROGNAME" [-vsrdow] FILE\n" + "\n" + "Extract oops from syslog/dmesg file" + ); + enum { + OPT_v = 1 << 0, + OPT_s = 1 << 1, + OPT_r = 1 << 2, + OPT_d = 1 << 3, + OPT_o = 1 << 4, + OPT_w = 1 << 5, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_BOOL('s', NULL, NULL, _("Log to syslog")), + OPT_BOOL('r', NULL, NULL, _("Parse kernel's message buffer before parsing FILE")), + OPT_BOOL('d', NULL, NULL, _("Create ABRT dump for every oops found")), + OPT_BOOL('o', NULL, NULL, _("Print found oopses on standard output")), + OPT_BOOL('w', NULL, NULL, _("Do not exit, watch the file for new oopses")), + OPT_END() + }; + + unsigned opts = parse_opts(argc, argv, program_options, program_usage); + argv += optind; + if (!argv[0]) + show_usage_and_die(program_usage, program_options); + filename = argv[0]; + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + msg_prefix = PROGNAME; + if ((opts & OPT_s) + || getenv("ABRT_SYSLOG") + ) { + openlog(msg_prefix, 0, LOG_DAEMON); + logmode = LOGMODE_SYSLOG; + } + + int inotify_fd = -1; + if (opts & OPT_w) + { + inotify_fd = inotify_init(); + if (inotify_fd == -1) + perror_msg_and_die("inotify_init failed"); + //close_on_exec_on(inotify_fd); + } + + GList *oops_list = NULL; + if (opts & OPT_r) + /* Scan dmesg (only once even with -w) */ + scan_dmesg(&oops_list); + + int partial_line_len = 0; + struct stat statbuf; + int file_fd = -1; + int wd = -1; + + while (1) /* loops only if -w */ + { + /* If file is already opened, parse oopses from current pos */ + if (file_fd >= 0) + { + memset(&statbuf, 0, sizeof(statbuf)); + fstat(file_fd, &statbuf); + partial_line_len = scan_syslog_file(&oops_list, file_fd, &statbuf, partial_line_len); + + /* Was file deleted or replaced? */ + ino_t fd_ino = statbuf.st_ino; + if (stat(filename, &statbuf) != 0 || statbuf.st_ino != fd_ino) /* yes */ + { + VERB2 log("Can't stat '%s', closing fd", filename); + close(file_fd); + if (wd >= 0) + inotify_rm_watch(inotify_fd, wd); + file_fd = -1; + wd = -1; + partial_line_len = 0; + } + } + + /* If file isn't opened, try to open it and parse oopses */ + if (file_fd < 0) + { + file_fd = open(filename, O_RDONLY); + if (file_fd < 0) + { + if (!(opts & OPT_w)) + perror_msg_and_die("Can't open '%s'", filename); + /* with -w, we ignore open errors */ + } + else + { + VERB2 log("Opened '%s'", filename); + /* For -w case, if we don't have inotify watch yet, open one */ + if ((opts & OPT_w) && wd < 0) + { + wd = inotify_add_watch(inotify_fd, filename, IN_MODIFY | IN_MOVE_SELF | IN_DELETE_SELF); + if (wd < 0) + perror_msg("inotify_add_watch failed on '%s'", filename); + else + VERB2 log("Added inotify watch for '%s'", filename); + } + if (fstat(file_fd, &statbuf) == 0) + { + /* If file is large, skip the beginning. + * IOW: ignore old log messages because they are unlikely + * to have sufficiently recent data to be useful. + */ + if (statbuf.st_size > (MAX_SCAN_BLOCK - READ_AHEAD)) + lseek(file_fd, statbuf.st_size - (MAX_SCAN_BLOCK - READ_AHEAD), SEEK_SET); + /* Note that statbuf is filled by fstat by now, + * scan_syslog_file needs that + */ + partial_line_len = scan_syslog_file(&oops_list, file_fd, &statbuf, partial_line_len); + } + } + } + + /* Print and/or save oopses */ + int oops_cnt = g_list_length(oops_list); + if (!(opts & OPT_w) || oops_cnt != 0) + log("Found oopses: %d", oops_cnt); + if (oops_cnt != 0) + { + if (opts & OPT_o) + { + int i = 0; + while (i < oops_cnt) + printf("\nVersion: %s", (char*)g_list_nth_data(oops_list, i++)); + } + if (opts & OPT_d) + { + log("Creating dump directories"); + int errors = save_oops_to_dump_dir(oops_list, oops_cnt); + if (errors > 0) + log("%d errors while dumping oopses", errors); + } + } + for (GList *li = oops_list; li; li = g_list_next(li)) + free((char*)li->data); + g_list_free(oops_list); + oops_list = NULL; + + /* Done if no -w */ + if (!(opts & OPT_w)) + break; + + /* Even if log file grows all the time, say, a new line every 5 ms, + * we don't want to scan it all the time. Sleep a bit and let it grow + * in bigger increments. + * Sleep longer if file does not exist. + */ + sleep(file_fd >= 0 ? 1 : 59); + + /* Now wait for it to change, be moved or deleted */ + if (wd >= 0) + { + char buf[4096]; + VERB3 log("Waiting for '%s' to change", filename); + /* We block here: */ + int len = read(inotify_fd, buf, sizeof(buf)); + if (len < 0 && errno != EINTR) /* I saw EINTR here on strace attach */ + perror_msg("Error reading inotify fd"); + /* we don't actually check what happened to file - + * the code will handle all possibilities. + */ + VERB3 log("Change in '%s' detected", filename); + } + + } /* while (1) */ + + return 0; +} -- cgit From 3a16d6494d6117c7515ad9000b1f9d86a54bb536 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jan 2011 16:49:30 +0100 Subject: remove dumpoops and KerneloopsScanner plugin Signed-off-by: Denys Vlasenko --- src/plugins/Kerneloops.conf | 6 - src/plugins/KerneloopsScanner.cpp | 229 -------------------- src/plugins/KerneloopsScanner.h | 42 ---- src/plugins/KerneloopsSysLog.c | 391 ----------------------------------- src/plugins/KerneloopsSysLog.h | 43 ---- src/plugins/Makefile.am | 19 +- src/plugins/abrt-KerneloopsScanner.7 | 46 ----- src/plugins/abrt-plugins.7 | 1 - 8 files changed, 1 insertion(+), 776 deletions(-) delete mode 100644 src/plugins/KerneloopsScanner.cpp delete mode 100644 src/plugins/KerneloopsScanner.h delete mode 100644 src/plugins/KerneloopsSysLog.c delete mode 100644 src/plugins/KerneloopsSysLog.h delete mode 100644 src/plugins/abrt-KerneloopsScanner.7 (limited to 'src/plugins') diff --git a/src/plugins/Kerneloops.conf b/src/plugins/Kerneloops.conf index 67ad07b9..e65e176f 100644 --- a/src/plugins/Kerneloops.conf +++ b/src/plugins/Kerneloops.conf @@ -4,10 +4,4 @@ Enabled = yes # Set to "yes" for compatibility with kerneloops.org tool. InformAllUsers = yes -# Kerneloops Scanner configuration -################################## -SysLogFile = /var/log/messages - -# KerneloopsReporter configuration -################################## SubmitURL = http://submit.kerneloops.org/submitoops.php diff --git a/src/plugins/KerneloopsScanner.cpp b/src/plugins/KerneloopsScanner.cpp deleted file mode 100644 index f4a637eb..00000000 --- a/src/plugins/KerneloopsScanner.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Authors: - Anton Arapov - Arjan van de Ven -*/ -#include -#include /* __NR_syslog */ -#include -#include "abrtlib.h" -#include "comm_layer_inner.h" -#include "KerneloopsSysLog.h" -#include "KerneloopsScanner.h" - -// TODO: https://fedorahosted.org/abrt/ticket/78 - -static int scan_dmesg(GList **oopsList) -{ - VERB1 log("Scanning dmesg"); - - /* syslog(3) - read the last len bytes from the log buffer - * (non-destructively), but dont read more than was written - * into the buffer since the last"clear ring buffer" cmd. - * Returns the number of bytes read. - */ - char *buffer = (char*)xzalloc(16*1024); - syscall(__NR_syslog, 3, buffer, 16*1024 - 1); /* always NUL terminated */ - int cnt_FoundOopses = extract_oopses(oopsList, buffer, strlen(buffer)); - free(buffer); - - return cnt_FoundOopses; -} - - -/* "dumpoops" tool uses these two functions too */ -extern "C" { - -int scan_syslog_file(GList **oopsList, const char *filename, time_t *last_changed_p) -{ - VERB1 log("Scanning syslog file '%s'", filename); - - char *buffer; - struct stat statb; - int fd; - int cnt_FoundOopses; - ssize_t sz; - fd = open(filename, O_RDONLY); - if (fd < 0) - return 0; - statb.st_size = 0; /* paranoia */ - if (fstat(fd, &statb) != 0 || statb.st_size < 1) - { - close(fd); - return 0; - } - - if (last_changed_p != NULL) - { - if (*last_changed_p == statb.st_mtime) - { - VERB1 log("Syslog file '%s' hasn't changed since last scan, skipping", filename); - close(fd); - return 0; - } - *last_changed_p = statb.st_mtime; - } - - /* - * In theory we have a race here, since someone could spew - * to /var/log/messages before we read it in... we try to - * deal with it by reading at most 10kbytes extra. If there's - * more than that.. any oops will be in dmesg anyway. - * Do not try to allocate an absurd amount of memory; ignore - * older log messages because they are unlikely to have - * sufficiently recent data to be useful. 32MB is more - * than enough; it's not worth looping through more log - * if the log is larger than that. - */ - sz = statb.st_size + 10*1024; - if (statb.st_size > (32*1024*1024 - 10*1024)) - { - xlseek(fd, statb.st_size - (32*1024*1024 - 10*1024), SEEK_SET); - sz = 32*1024*1024; - } - buffer = (char*)xzalloc(sz); - sz = full_read(fd, buffer, sz); - close(fd); - - cnt_FoundOopses = 0; - if (sz > 0) - cnt_FoundOopses = extract_oopses(oopsList, buffer, sz); - free(buffer); - - return cnt_FoundOopses; -} - -/* returns number of errors */ -int save_oops_to_debug_dump(GList **oopsList) -{ - unsigned countdown = 16; /* do not report hundreds of oopses */ - unsigned idx = g_list_length(*oopsList); - time_t t = time(NULL); - pid_t my_pid = getpid(); - - VERB1 log("Saving %u oopses as crash dump dirs", idx >= countdown ? countdown-1 : idx); - - char *tainted_str = NULL; - /* once tainted flag is set to 1, only restart can reset the flag to 0 */ - FILE *tainted_fd = fopen("/proc/sys/kernel/tainted", "r"); - if (tainted_fd) - { - tainted_str = xmalloc_fgetline(tainted_fd); - fclose(tainted_fd); - } - else - error_msg("/proc/sys/kernel/tainted does not exist"); - - int errors = 0; - - while (idx != 0 && --countdown != 0) - { - char path[sizeof(DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu-%lu") + 3 * sizeof(long)*3]; - sprintf(path, DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu-%lu", (long)t, (long)my_pid, (long)idx); - - char *first_line = (char*)g_list_nth_data(*oopsList,--idx); - char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */ - *second_line++ = '\0'; - - struct dump_dir *dd = dd_create(path, /*uid:*/ 0); - if (dd) - { - dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops"); - dd_save_text(dd, FILENAME_EXECUTABLE, "kernel"); - dd_save_text(dd, FILENAME_KERNEL, first_line); - dd_save_text(dd, FILENAME_CMDLINE, "not_applicable"); - dd_save_text(dd, FILENAME_BACKTRACE, second_line); - /* Optional, makes generated bz more informative */ - strchrnul(second_line, '\n')[0] = '\0'; - dd_save_text(dd, FILENAME_REASON, second_line); - - if (tainted_str && tainted_str[0] != '0') - dd_save_text(dd, FILENAME_TAINTED, tainted_str); - - free(tainted_str); - dd_close(dd); - } - else - errors++; - } - - return errors; -} - -} /* extern "C" */ - - -CKerneloopsScanner::CKerneloopsScanner() -{ - int cnt_FoundOopses; - m_syslog_last_change = 0; - - /* Scan dmesg, on first call only */ - GList *oopsList = NULL; - cnt_FoundOopses = scan_dmesg(&oopsList); - if (cnt_FoundOopses > 0) - { - int errors = save_oops_to_debug_dump(&oopsList); - if (errors > 0) - log("%d errors while dumping oopses", errors); - } -} - -void CKerneloopsScanner::Run(const char *pActionDir, const char *pArgs, int force) -{ - const char *syslog_file = "/var/log/messages"; - map_plugin_settings_t::const_iterator it = m_pSettings.find("SysLogFile"); - if (it != m_pSettings.end()) - syslog_file = it->second.c_str(); - - GList *oopsList = NULL; - int cnt_FoundOopses = scan_syslog_file(&oopsList, syslog_file, &m_syslog_last_change); - if (cnt_FoundOopses > 0) - { - int errors = save_oops_to_debug_dump(&oopsList); - if (errors > 0) - log("%d errors while dumping oopses", errors); - /* - * This marker in syslog file prevents us from - * re-parsing old oopses (any oops before it is - * ignored by scan_syslog_file()). The only problem - * is that we can't be sure here that syslog_file - * is the file where syslog(xxx) stuff ends up. - */ - openlog("abrt", 0, LOG_KERN); - syslog(LOG_WARNING, - "Kerneloops: Reported %u kernel oopses to Abrt", - cnt_FoundOopses); - closelog(); - } - - for (GList *li = oopsList; li != NULL; li = g_list_next(li)) - free((char*)li->data); - g_list_free(oopsList); -} - -PLUGIN_INFO(ACTION, - CKerneloopsScanner, - "KerneloopsScanner", - "0.0.1", - _("Periodically scans for and saves kernel oopses"), - "anton@redhat.com", - "http://people.redhat.com/aarapov", - ""); diff --git a/src/plugins/KerneloopsScanner.h b/src/plugins/KerneloopsScanner.h deleted file mode 100644 index 2bddb0f4..00000000 --- a/src/plugins/KerneloopsScanner.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, Intel Corporation - * Copyright 2009, Red Hat Inc. - * - * This file is part of Abrt. - * - * This program file 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; version 2 of the License. - * - * 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 in a file named COPYING; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: - * Anton Arapov - * Arjan van de Ven - */ -#ifndef KERNELOOPSSCANNER_H_ -#define KERNELOOPSSCANNER_H_ - -#include "abrt_types.h" -#include "plugin.h" -#include "action.h" - -class CKerneloopsScanner : public CAction -{ - private: - time_t m_syslog_last_change; - public: - CKerneloopsScanner(); - virtual void Run(const char *pActionDir, const char *pArgs, int force); -}; - -#endif diff --git a/src/plugins/KerneloopsSysLog.c b/src/plugins/KerneloopsSysLog.c deleted file mode 100644 index 162fd977..00000000 --- a/src/plugins/KerneloopsSysLog.c +++ /dev/null @@ -1,391 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - Authors: - Anton Arapov - Arjan van de Ven - */ -#include "abrtlib.h" -#include "KerneloopsSysLog.h" -#include - -static void queue_oops(GList **vec, const char *data, const char *version) -{ - char *ver_data = xasprintf("%s\n%s", version, data); - *vec = g_list_append(*vec, ver_data); -} - -/* - * extract_version tries to find the kernel version in given data - */ -static char *extract_version(const char *linepointer) -{ - if (strstr(linepointer, "Pid") - || strstr(linepointer, "comm") - || strstr(linepointer, "CPU") - || strstr(linepointer, "REGS") - || strstr(linepointer, "EFLAGS") - ) { - char* start; - char* end; - - start = strstr((char*)linepointer, "2.6."); - if (start) - { - end = strchr(start, ')'); - if (!end) - end = strchrnul(start, ' '); - return xstrndup(start, end-start); - } - } - - return NULL; -} - -/* - * extract_oops tries to find oops signatures in a log - */ -struct line_info { - char *ptr; - char level; -}; - -static int record_oops(GList **oopses, struct line_info* lines_info, int oopsstart, int oopsend) -{ - int q; - int len; - char *oops; - char *version; - - len = 2; - for (q = oopsstart; q <= oopsend; q++) - len += strlen(lines_info[q].ptr) + 1; - - oops = (char*)xzalloc(len); - - version = NULL; - for (q = oopsstart; q <= oopsend; q++) - { - if (!version) - version = extract_version(lines_info[q].ptr); - - if (lines_info[q].ptr[0]) - { - strcat(oops, lines_info[q].ptr); - strcat(oops, "\n"); - } - } - int rv = 1; - /* too short oopses are invalid */ - if (strlen(oops) > 100) - queue_oops(oopses, oops, version ? version : "undefined"); - else - { - VERB3 log("Dropped oops: too short"); - rv = 0; - } - free(oops); - free(version); - return rv; -} -#define REALLOC_CHUNK 1000 -int extract_oopses(GList **oopses, char *buffer, size_t buflen) -{ - char *c; - int linecount = 0; - int lines_info_alloc = 0; - struct line_info *lines_info = NULL; - - /* Split buffer into lines */ - - if (buflen != 0) - buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ - c = buffer; - while (c < buffer + buflen) - { - char linelevel; - char *c9; - char *colon; - - c9 = (char*)memchr(c, '\n', buffer + buflen - c); /* a \n will always be found */ - assert(c9); - *c9 = '\0'; /* turn the \n into a string termination */ - if (c9 == c) - goto next_line; - - /* Is it a syslog file (/var/log/messages or similar)? - * Even though _usually_ it looks like "Nov 19 12:34:38 localhost kernel: xxx", - * some users run syslog in non-C locale: - * "2010-02-22T09:24:08.156534-08:00 gnu-4 gnome-session[2048]: blah blah" - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !!! - * We detect it by checking for N:NN:NN pattern in first 15 chars - * (and this still is not good enough... false positive: "pci 0000:15:00.0: PME# disabled") - */ - colon = strchr(c, ':'); - if (colon && colon > c && colon < c + 15 - && isdigit(colon[-1]) /* N:... */ - && isdigit(colon[1]) /* ...N:NN:... */ - && isdigit(colon[2]) - && colon[3] == ':' - && isdigit(colon[4]) /* ...N:NN:NN... */ - && isdigit(colon[5]) - ) { - /* It's syslog file, not a bare dmesg */ - - /* Skip non-kernel lines */ - char *kernel_str = strstr(c, "kernel: "); - if (kernel_str == NULL) - { - /* if we see our own marker: - * "hostname abrt: Kerneloops: Reported 1 kernel oopses to Abrt" - * we know we submitted everything upto here already */ - if (strstr(c, "abrt:") && strstr(c, "Abrt")) - { - VERB3 log("Found our marker at line %d, restarting line count from 0", linecount); - linecount = 0; - lines_info_alloc = 0; - free(lines_info); - lines_info = NULL; - } - goto next_line; - } - c = kernel_str + sizeof("kernel: ")-1; - } - - linelevel = 0; - /* store and remove kernel log level */ - if (*c == '<' && c[1] && c[2] == '>') - { - linelevel = c[1]; - c += 3; - } - /* remove jiffies time stamp counter if present */ - if (*c == '[') - { - char *c2 = strchr(c, '.'); - char *c3 = strchr(c, ']'); - if (c2 && c3 && (c2 < c3) && (c3-c) < 14 && (c2-c) < 8) - { - c = c3 + 1; - if (*c == ' ') - c++; - } - } - if (linecount >= lines_info_alloc) - { - lines_info_alloc += REALLOC_CHUNK; - lines_info = (struct line_info*)xrealloc(lines_info, - lines_info_alloc * sizeof(lines_info[0])); - } - lines_info[linecount].ptr = c; - lines_info[linecount].level = linelevel; - linecount++; -next_line: - c = c9 + 1; - } - - /* Analyze lines */ - - int i; - char prevlevel = 0; - int oopsstart = -1; - int inbacktrace = 0; - int oopsesfound = 0; - - i = 0; - while (i < linecount) - { - char *curline = lines_info[i].ptr; - - if (curline == NULL) - { - i++; - continue; - } - while (*curline == ' ') - curline++; - - if (oopsstart < 0) - { - /* Find start-of-oops markers */ - /* In some comparisons, we skip 1st letter, to avoid dealing with - * changes in capitalization in kernel. For example, I see that - * current kernel git (at 2011-01-01) has both "kernel BUG at ..." - * and "Kernel BUG at ..." messages, and I don't want to change - * the code below whenever kernel is changed to use "K" (or "k") - * uniformly. - */ - if (strstr(curline, /*g*/ "eneral protection fault:")) - oopsstart = i; - else if (strstr(curline, "BUG:")) - oopsstart = i; - else if (strstr(curline, /*k*/ "ernel BUG at")) - oopsstart = i; - else if (strstr(curline, "do_IRQ: stack overflow:")) - oopsstart = i; - else if (strstr(curline, "RTNL: assertion failed")) - oopsstart = i; - else if (strstr(curline, /*e*/ "eek! page_mapcount(page) went negative!")) - oopsstart = i; - else if (strstr(curline, /*n*/ "ear stack overflow (cur:")) - oopsstart = i; - else if (strstr(curline, /*d*/ "ouble fault:")) - oopsstart = i; - else if (strstr(curline, /*b*/ "adness at")) - oopsstart = i; - else if (strstr(curline, "NETDEV WATCHDOG")) - oopsstart = i; - else if (strstr(curline, "WARNING: at ")) /* WARN_ON() generated message */ - oopsstart = i; - else if (strstr(curline, /*u*/ "nable to handle kernel")) - oopsstart = i; - else if (strstr(curline, /*s*/ "ysctl table check failed")) - oopsstart = i; - else if (strstr(curline, "INFO: possible recursive locking detected")) - oopsstart = i; - // Not needed: "--[ cut here ]--" is always followed - // by "Badness at", "kernel BUG at", or "WARNING: at" string - //else if (strstr(curline, "------------[ cut here ]------------")) - // oopsstart = i; - else if (strstr(curline, "list_del corruption")) - oopsstart = i; - else if (strstr(curline, "list_add corruption")) - oopsstart = i; - - if (i >= 3 && strstr(curline, "Oops:")) - oopsstart = i-3; - - if (oopsstart >= 0) - { - /* debug information */ - VERB3 { - log("Found oops at line %d: '%s'", oopsstart, lines_info[oopsstart].ptr); - if (oopsstart != i) - log("Trigger line is %d: '%s'", i, c); - } - /* try to find the end marker */ - int i2 = i + 1; - while (i2 < linecount && i2 < (i+50)) - { - if (strstr(lines_info[i2].ptr, "---[ end trace")) - { - inbacktrace = 1; - i = i2; - break; - } - i2++; - } - } - } - - /* Are we entering a call trace part? */ - /* a call trace starts with "Call Trace:" or with the " [<.......>] function+0xFF/0xAA" pattern */ - if (oopsstart >= 0 && !inbacktrace) - { - if (strstr(curline, "Call Trace:")) - inbacktrace = 1; - else - if (strnlen(curline, 9) > 8 - && curline[0] == '[' && curline[1] == '<' - && strstr(curline, ">]") - && strstr(curline, "+0x") - && strstr(curline, "/0x") - ) { - inbacktrace = 1; - } - } - - /* Are we at the end of an oops? */ - else if (oopsstart >= 0 && inbacktrace) - { - int oopsend = INT_MAX; - - /* line needs to start with " [" or have "] [" if it is still a call trace */ - /* example: "[] radeon_get_ring_head+0x16/0x41 [radeon]" */ - if (curline[0] != '[' - && !strstr(curline, "] [") - && !strstr(curline, "--- Exception") - && !strstr(curline, "LR =") - && !strstr(curline, "<#DF>") - && !strstr(curline, "") - && !strstr(curline, "") - && !strstr(curline, "<>") - && strncmp(curline, "Code: ", 6) != 0 - && strncmp(curline, "RIP ", 4) != 0 - && strncmp(curline, "RSP ", 4) != 0 - ) { - oopsend = i-1; /* not a call trace line */ - } - /* oops lines are always more than 8 chars long */ - else if (strnlen(curline, 8) < 8) - oopsend = i-1; - /* single oopses are of the same loglevel */ - else if (lines_info[i].level != prevlevel) - oopsend = i-1; - else if (strstr(curline, "Instruction dump:")) - oopsend = i; - /* if a new oops starts, this one has ended */ - else if (strstr(curline, "WARNING: at ") && oopsstart != i) /* WARN_ON() generated message */ - oopsend = i-1; - else if (strstr(curline, "Unable to handle") && oopsstart != i) - oopsend = i-1; - /* kernel end-of-oops marker (not including marker itself) */ - else if (strstr(curline, "---[ end trace")) - oopsend = i-1; - - if (oopsend <= i) - { - VERB3 log("End of oops at line %d (%d): '%s'", oopsend, i, lines_info[oopsend].ptr); - if (record_oops(oopses, lines_info, oopsstart, oopsend)) - oopsesfound++; - oopsstart = -1; - inbacktrace = 0; - } - } - - prevlevel = lines_info[i].level; - i++; - - if (oopsstart >= 0) - { - /* Do we have a suspiciously long oops? Cancel it */ - if (i-oopsstart > 60) - { - inbacktrace = 0; - oopsstart = -1; - VERB3 log("Dropped oops, too long"); - continue; - } - if (!inbacktrace && i-oopsstart > 40) - { - /*inbacktrace = 0; - already is */ - oopsstart = -1; - VERB3 log("Dropped oops, too long"); - continue; - } - } - } /* while (i < linecount) */ - - /* process last oops if we have one */ - if (oopsstart >= 0 && inbacktrace) - { - int oopsend = i-1; - VERB3 log("End of oops at line %d (end of file): '%s'", oopsend, lines_info[oopsend].ptr); - if (record_oops(oopses, lines_info, oopsstart, oopsend)) - oopsesfound++; - } - - free(lines_info); - return oopsesfound; -} diff --git a/src/plugins/KerneloopsSysLog.h b/src/plugins/KerneloopsSysLog.h deleted file mode 100644 index eeaaed6b..00000000 --- a/src/plugins/KerneloopsSysLog.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2007, Intel Corporation - * Copyright 2009, Red Hat Inc. - * - * This file is part of Abrt. - * - * This program file 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; version 2 of the License. - * - * 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 in a file named COPYING; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: - * Anton Arapov - * Arjan van de Ven - */ - -#ifndef __INCLUDE_GUARD_KERNELOOPSSYSLOG_H_ -#define __INCLUDE_GUARD_KERNELOOPSSYSLOG_H_ - -#include "abrt_types.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int extract_oopses(GList **oopses, char *buffer, size_t buflen); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 5d3b5890..f70198be 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -17,8 +17,7 @@ bin_PROGRAMS = \ abrt-action-print pluginslib_LTLIBRARIES = \ - libCCpp.la \ - libKerneloopsScanner.la + libCCpp.la dist_pluginslib_DATA = \ Logger.glade \ @@ -42,7 +41,6 @@ dist_pluginsconf_DATA = \ man_MANS = \ abrt-Bugzilla.7 \ - abrt-KerneloopsScanner.7 \ abrt-KerneloopsReporter.7 \ abrt-Logger.7 \ abrt-Mailx.7 \ @@ -76,21 +74,6 @@ libCCpp_la_CPPFLAGS = \ libCCpp_la_LDFLAGS = \ -avoid-version -# KerneloopsScanner -libKerneloopsScanner_la_SOURCES = \ - KerneloopsScanner.cpp KerneloopsScanner.h \ - KerneloopsSysLog.c KerneloopsSysLog.h -libKerneloopsScanner_la_CPPFLAGS = \ - -I$(srcdir)/../include/report -I$(srcdir)/../include \ - -I$(srcdir)/../lib \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - $(GLIB_CFLAGS) \ - -D_GNU_SOURCE \ - -Wall -Werror -libKerneloopsScanner_la_LDFLAGS = \ - -avoid-version \ - $(GLIB_LIBS) - abrt_dump_oops_SOURCES = \ abrt-dump-oops.c abrt_dump_oops_CPPFLAGS = \ diff --git a/src/plugins/abrt-KerneloopsScanner.7 b/src/plugins/abrt-KerneloopsScanner.7 deleted file mode 100644 index ff094847..00000000 --- a/src/plugins/abrt-KerneloopsScanner.7 +++ /dev/null @@ -1,46 +0,0 @@ -.TH abrt "7" "1 Jun 2009" "" -.SH NAME -KerneloopsScanner plugin for abrt(8) -.SH DESCRIPTION -.P -.I abrt -is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIKerneloopsScanner\fP -plugin for \fIabrt\fP. -.P -This plugin reads the system log file (default /var/log/messages) -and stores the kernel oops crashes, which were not already -reported, to abrt's debug dump directory. -.P -To distinguish between new crashes and crashes -that were already reported, the plugin makes its own entry -in the log file, which acts as a separator. -.SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. -No parameters are necessary. -.SH CONFIGURATION -The \fIKerneloopsScanner.conf\fP configuration file contains one entry: -.SS SysLogFile -The file to scan. The default is -.br -SysLogFile = /var/log/messages -.SH EXAMPLES -.P -This is a snippet from the \fIabrt.conf\fP configuration file. -Every 10 seconds look if there were any kernel crashes: -.P -[common] -.br -ActionsAndReporters = Kerneloops, KerneloopsScanner -.br -[cron] -.br -10 = KerneloopsScanner -.SH "SEE ALSO" -.IR abrt (8), -.IR abrt.conf (5), -.IR abrt-plugins (7) -.SH AUTHOR -Written by Anton Arapov . Manual -page by Daniel Novotny . diff --git a/src/plugins/abrt-plugins.7 b/src/plugins/abrt-plugins.7 index 28de8f02..d8027057 100644 --- a/src/plugins/abrt-plugins.7 +++ b/src/plugins/abrt-plugins.7 @@ -33,7 +33,6 @@ stored in the \fI/etc/abrt/plugins\fP directory. .IR abrt-Bugzilla (7), .IR abrt-Upload (7), .IR abrt-KerneloopsReporter (7), -.IR abrt-KerneloopsScanner (7), .IR abrt-Logger (7), .IR abrt-Mailx (7), .SH AUTHOR -- cgit From 480cac7647d567c3c3cb148c5a4750091b651934 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 19 Jan 2011 17:14:05 +0100 Subject: remove old plugin machinery. -10k and -1 library dependence in abrtd Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 301 ------------------------------------------------ src/plugins/CCpp.h | 49 -------- src/plugins/Makefile.am | 19 --- 3 files changed, 369 deletions(-) delete mode 100644 src/plugins/CCpp.cpp delete mode 100644 src/plugins/CCpp.h (limited to 'src/plugins') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp deleted file mode 100644 index df2c4482..00000000 --- a/src/plugins/CCpp.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - CCpp.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - 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 -#include "abrtlib.h" -#include "CCpp.h" -#include "comm_layer_inner.h" - -using namespace std; - -#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -/* - * %s - signal number - * %c - ulimit -c value - * %p - pid - * %u - uid - * %g - gid - * %t - UNIX time of dump - * %h - hostname - * %e - executable filename - * %% - output one "%" - */ -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %s %c %p %u %g %t %h %e" - -#define CORE_PIPE_LIMIT_IFACE "/proc/sys/kernel/core_pipe_limit" -/* core_pipe_limit specifies how many dump_helpers might run at the same time - * 0 - means unlimited, but it's not guaranteed that /proc/ of crashing - * process will be available for dump_helper. - * 4 - means that 4 dump_helpers can run at the same time (the rest will also - * run, but they will fail to read /proc/). - * This should be enough for ABRT, we can miss some crashes, but what are - * the odds that more processes crash at the same time? - * The value of 4 has been recommended by nhorman. - */ -#define CORE_PIPE_LIMIT "4" - -#define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di" - -CAnalyzerCCpp::CAnalyzerCCpp() : - m_bBacktrace(true), - m_bBacktraceRemotes(false), - m_bMemoryMap(false), - m_bInstallDebugInfo(true), - m_nDebugInfoCacheMB(4000), - m_nGdbTimeoutSec(60) -{} - -/* - this is just a workaround until kernel changes it's behavior - when handling pipes in core_pattern -*/ -#ifdef HOSTILE_KERNEL -#define CORE_SIZE_PATTERN "Max core file size=1:unlimited" -static int isdigit_str(char *str) -{ - do { - if (*str < '0' || *str > '9') - return 0; - } while (*++str); - return 1; -} - -static int set_limits() -{ - DIR *dir = opendir("/proc"); - if (!dir) { - /* this shouldn't fail, but to be safe.. */ - return 1; - } - - struct dirent *ent; - while ((ent = readdir(dir)) != NULL) { - if (!isdigit_str(ent->d_name)) - continue; - - char limits_name[sizeof("/proc/%s/limits") + sizeof(long)*3]; - snprintf(limits_name, sizeof(limits_name), "/proc/%s/limits", ent->d_name); - FILE *limits_fp = fopen(limits_name, "r"); - if (!limits_fp) { - break; - } - - char line[128]; - char *ulimit_c = NULL; - while (1) { - if (fgets(line, sizeof(line)-1, limits_fp) == NULL) - break; - if (strncmp(line, "Max core file size", sizeof("Max core file size")-1) == 0) { - ulimit_c = skip_whitespace(line + sizeof("Max core file size")-1); - skip_non_whitespace(ulimit_c)[0] = '\0'; - break; - } - } - fclose(limits_fp); - if (!ulimit_c || ulimit_c[0] != '0' || ulimit_c[1] != '\0') { - /*process has nonzero ulimit -c, so need to modify it*/ - continue; - } - /* echo -n 'Max core file size=1:unlimited' >/proc/PID/limits */ - int fd = open(limits_name, O_WRONLY); - if (fd >= 0) { - errno = 0; - /*full_*/ - ssize_t n = write(fd, CORE_SIZE_PATTERN, sizeof(CORE_SIZE_PATTERN)-1); - if (n < sizeof(CORE_SIZE_PATTERN)-1) - log("warning: can't write core_size limit to: %s", limits_name); - close(fd); - } - else - { - log("warning: can't open %s for writing", limits_name); - } - } - closedir(dir); - return 0; -} -#endif /* HOSTILE_KERNEL */ - -void CAnalyzerCCpp::Init() -{ - FILE *fp = fopen(CORE_PATTERN_IFACE, "r"); - if (fp) - { - char line[PATH_MAX]; - if (fgets(line, sizeof(line), fp)) - m_sOldCorePattern = line; - fclose(fp); - } - if (m_sOldCorePattern[0] == '|') - { - if (strncmp(m_sOldCorePattern.c_str(), CORE_PATTERN, strlen(CORE_PATTERN)) == 0) - { - log("warning: %s already contains %s, " - "did abrt daemon crash recently?", - CORE_PATTERN_IFACE, CORE_PATTERN); - /* There is no point in "restoring" CORE_PATTERN_IFACE - * to CORE_PATTERN on exit. Will restore to a default value: - */ - m_sOldCorePattern = "core"; - } else { - log("warning: %s was already set to run a crash analyser (%s), " - "abrt may interfere with it", - CORE_PATTERN_IFACE, CORE_PATTERN); - } - } -#ifdef HOSTILE_KERNEL - if (set_limits() != 0) - log("warning: failed to set core_size limit, ABRT won't detect crashes in" - "compiled apps"); -#endif - - fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - if (m_sOldCorePattern[0] != '|') - { - const char *old = m_sOldCorePattern.c_str(); - unsigned len = strchrnul(old, '\n') - old; - char *hex_old = (char*)xmalloc(len * 2 + 1); - bin2hex(hex_old, old, len)[0] = '\0'; - /* Trailing 00 is a sentinel. Decoder in the hook will check it. - * If it won't see it, then kernel has truncated the argument: - */ - char *pattern = xasprintf("%s %s00", CORE_PATTERN, hex_old); - //log("old:'%s'->'%s'", old, hex_old); - //log("pattern:'%s'", pattern); - - fputs(pattern, fp); - - free(pattern); - free(hex_old); - } - else - { - fputs(CORE_PATTERN, fp); - } - fclose(fp); - } - - /* read the core_pipe_limit and change it if it's == 0 - * otherwise the abrt-hook-ccpp won't be able to read /proc/ - * of the crashing process - */ - fp = fopen(CORE_PIPE_LIMIT_IFACE, "r"); - if (fp) - { - /* we care only about the first char, if it's - * not '0' then we don't have to change it, - * because it means that it's already != 0 - */ - char pipe_limit[2]; - if (!fgets(pipe_limit, sizeof(pipe_limit), fp)) - pipe_limit[0] = '1'; /* not 0 */ - fclose(fp); - if (pipe_limit[0] == '0') - { - fp = fopen(CORE_PIPE_LIMIT_IFACE, "w"); - if (fp) - { - fputs(CORE_PIPE_LIMIT, fp); - fclose(fp); - } - else - { - log("warning: failed to set core_pipe_limit, ABRT won't detect" - "crashes in compiled apps if kernel > 2.6.31"); - } - } - } -} - -void CAnalyzerCCpp::DeInit() -{ - /* no need to restore the core_pipe_limit, because it's only used - when there is s pipe in core_pattern - */ - FILE *fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - fputs(m_sOldCorePattern.c_str(), fp); - fclose(fp); - } -} - -void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("Backtrace"); - if (it != end) - { - m_bBacktrace = string_to_bool(it->second.c_str()); - } - it = pSettings.find("BacktraceRemotes"); - if (it != end) - { - m_bBacktraceRemotes = string_to_bool(it->second.c_str()); - } - it = pSettings.find("MemoryMap"); - if (it != end) - { - m_bMemoryMap = string_to_bool(it->second.c_str()); - } - it = pSettings.find("DebugInfo"); - if (it != end) - { - m_sDebugInfo = it->second; - } - it = pSettings.find("DebugInfoCacheMB"); - if (it != end) - { - m_nDebugInfoCacheMB = xatou(it->second.c_str()); - } - it = pSettings.find("GdbTimeoutSec"); - if (it != end) - { - m_nGdbTimeoutSec = xatoi_positive(it->second.c_str()); - } - it = pSettings.find("InstallDebugInfo"); - if (it == end) //compat, remove after 0.0.11 - it = pSettings.find("InstallDebuginfo"); - if (it != end) - { - m_bInstallDebugInfo = string_to_bool(it->second.c_str()); - } - m_sDebugInfoDirs = DEBUGINFO_CACHE_DIR; - it = pSettings.find("ReadonlyLocalDebugInfoDirs"); - if (it != end) - { - m_sDebugInfoDirs += ':'; - m_sDebugInfoDirs += it->second; - } -} - -PLUGIN_INFO(ANALYZER, - CAnalyzerCCpp, - "CCpp", - "0.0.1", - _("Analyzes crashes in C/C++ programs"), - "zprikryl@redhat.com", - "https://fedorahosted.org/abrt/wiki", - ""); diff --git a/src/plugins/CCpp.h b/src/plugins/CCpp.h deleted file mode 100644 index e95b4d09..00000000 --- a/src/plugins/CCpp.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - CCpp.h - header file for C/C++ analyzer plugin - - it can get UUID and memory maps from core files - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - 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 CCPP_H_ -#define CCPP_H_ - -#include -#include "plugin.h" -#include "analyzer.h" - -class CAnalyzerCCpp : public CAnalyzer -{ - private: - bool m_bBacktrace; - bool m_bBacktraceRemotes; - bool m_bMemoryMap; - bool m_bInstallDebugInfo; - unsigned m_nDebugInfoCacheMB; - unsigned m_nGdbTimeoutSec; - std::string m_sOldCorePattern; - std::string m_sDebugInfo; - std::string m_sDebugInfoDirs; - - public: - CAnalyzerCCpp(); - virtual void Init(); - virtual void DeInit(); - virtual void SetSettings(const map_plugin_settings_t& pSettings); -}; - -#endif /* CCPP */ diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index f70198be..3ba454e2 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -16,9 +16,6 @@ bin_PROGRAMS = \ abrt-action-mailx \ abrt-action-print -pluginslib_LTLIBRARIES = \ - libCCpp.la - dist_pluginslib_DATA = \ Logger.glade \ Mailx.glade \ @@ -58,22 +55,6 @@ install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) sed 's: = /var/: = $(localstatedir)/:g' -i \ $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf -# CCpp -libCCpp_la_SOURCES = \ - CCpp.cpp CCpp.h -libCCpp_la_CPPFLAGS = \ - -I$(srcdir)/../include/report -I$(srcdir)/../include \ - -I$(srcdir)/../lib \ - -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DLOCALSTATEDIR='"$(localstatedir)"' \ - $(GLIB_CFLAGS) \ - -D_GNU_SOURCE \ - -Wall -Werror -# -DHOSTILE_KERNEL -libCCpp_la_LDFLAGS = \ - -avoid-version - abrt_dump_oops_SOURCES = \ abrt-dump-oops.c abrt_dump_oops_CPPFLAGS = \ -- 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/plugins/abrt-dump-oops.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c index ad222edd..07e2618b 100644 --- a/src/plugins/abrt-dump-oops.c +++ b/src/plugins/abrt-dump-oops.c @@ -675,9 +675,7 @@ int main(int argc, char **argv) log("%d errors while dumping oopses", errors); } } - for (GList *li = oops_list; li; li = g_list_next(li)) - free((char*)li->data); - g_list_free(oops_list); + list_free_with_free(oops_list); oops_list = NULL; /* Done if no -w */ -- cgit From e3d48ee0458f1d0078da65bad99804d2ba58aaf0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 20:33:34 +0100 Subject: make option handling more regular across all tools Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-analyze-c.c | 12 +++--- src/plugins/abrt-action-analyze-oops.c | 8 ++-- src/plugins/abrt-action-analyze-python.c | 12 +++--- src/plugins/abrt-action-bugzilla.cpp | 8 ++-- src/plugins/abrt-action-generate-backtrace.c | 58 ++++++++++++++-------------- src/plugins/abrt-action-kerneloops.c | 8 ++-- src/plugins/abrt-action-mailx.c | 8 ++-- src/plugins/abrt-action-print.c | 9 +++-- src/plugins/abrt-action-rhtsupport.c | 8 ++-- src/plugins/abrt-action-upload.c | 8 ++-- src/plugins/abrt-dump-oops.c | 17 ++++---- 11 files changed, 75 insertions(+), 81 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c index e45e39cf..a736c4f8 100644 --- a/src/plugins/abrt-action-analyze-c.c +++ b/src/plugins/abrt-action-analyze-c.c @@ -149,28 +149,28 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); + const char *dump_dir_name = "."; + /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( - PROGNAME" [-vs] -d DIR\n\n" + PROGNAME" [-v] -d DIR\n\n" "Calculates and saves UUID of coredumps" - ); - const char *dump_dir_name = "."; + ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, - OPT_s = 1 << 2, +// OPT_s = 1 << 2, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Crash dump directory")), - OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), +// OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - msg_prefix = PROGNAME; //Maybe we will want this... later // if (opts & OPT_s) diff --git a/src/plugins/abrt-action-analyze-oops.c b/src/plugins/abrt-action-analyze-oops.c index 24538641..0072c71d 100644 --- a/src/plugins/abrt-action-analyze-oops.c +++ b/src/plugins/abrt-action-analyze-oops.c @@ -126,28 +126,28 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); + const char *dump_dir_name = "."; + /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( PROGNAME" [-vs] -d DIR\n\n" "Calculates and saves UUID and DUPHASH of oops crash dumps" ); - const char *dump_dir_name = "."; enum { OPT_v = 1 << 0, OPT_d = 1 << 1, - OPT_s = 1 << 2, +// OPT_s = 1 << 2, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Crash dump directory")), - OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), +// OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - msg_prefix = PROGNAME; //Maybe we will want this... later // if (opts & OPT_s) diff --git a/src/plugins/abrt-action-analyze-python.c b/src/plugins/abrt-action-analyze-python.c index 9fe563db..feffb439 100644 --- a/src/plugins/abrt-action-analyze-python.c +++ b/src/plugins/abrt-action-analyze-python.c @@ -31,28 +31,28 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); + const char *dump_dir_name = "."; + /* Can't keep these strings/structs static: _() doesn't support that */ const char *program_usage_string = _( - PROGNAME" [-vs] -d DIR\n\n" + PROGNAME" [-v] -d DIR\n\n" "Calculates and saves UUID and DUPHASH of python crash dumps" - ); - const char *dump_dir_name = "."; + ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, - OPT_s = 1 << 2, +// OPT_s = 1 << 2, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Crash dump directory")), - OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), +// OPT_BOOL( 's', NULL, NULL, _("Log to syslog" )), OPT_END() }; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - msg_prefix = PROGNAME; //Maybe we will want this... later // if (opts & OPT_s) diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 19735452..9d849d99 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -906,7 +906,7 @@ int main(int argc, char **argv) enum { OPT_s = (1 << 0), }; - int optflags = 0; + int opts = 0; int opt; while ((opt = getopt(argc, argv, "c:d:vs")) != -1) { @@ -924,7 +924,7 @@ int main(int argc, char **argv) g_verbose++; break; case 's': - optflags |= OPT_s; + opts |= OPT_s; break; default: /* Careful: the string below contains tabs, dont replace with spaces */ @@ -943,11 +943,9 @@ int main(int argc, char **argv) } putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. // msg_prefix = xasprintf("abrt-action-bugzilla[%u]", getpid()); - - if (optflags & OPT_s) + if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index a575a191..05f878e2 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -28,7 +28,7 @@ #define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di" static const char *dump_dir_name = "."; -static const char *debuginfo_dirs; +static const char *debuginfo_dirs = DEBUGINFO_CACHE_DIR; static int exec_timeout_sec = 60; @@ -244,49 +244,49 @@ static char *get_backtrace(struct dump_dir *dd) return bt; } -static char *i_opt; -static const char abrt_action_generage_backtrace_usage[] = PROGNAME" [options] -d DIR"; -enum { - OPT_v = 1 << 0, - OPT_d = 1 << 1, - OPT_i = 1 << 2, - OPT_t = 1 << 3, - OPT_s = 1 << 4, -}; -/* Keep enum above and order of options below in sync! */ -static struct options abrt_action_generate_backtrace_options[] = { - OPT__VERBOSE(&g_verbose), - OPT_STRING( 'd', NULL, &dump_dir_name, "DIR", "Crash dump directory"), - OPT_STRING( 'i', NULL, &i_opt, "dir1[:dir2]...", "Additional debuginfo directories"), - OPT_INTEGER('t', NULL, &exec_timeout_sec, "Kill gdb if it runs for more than N seconds"), - OPT_BOOL( 's', NULL, NULL, "Log to syslog"), - OPT_END() -}; - int main(int argc, char **argv) { char *env_verbose = getenv("ABRT_VERBOSE"); if (env_verbose) g_verbose = atoi(env_verbose); - unsigned opts = parse_opts(argc, argv, abrt_action_generate_backtrace_options, - abrt_action_generage_backtrace_usage); - - debuginfo_dirs = DEBUGINFO_CACHE_DIR; - if (i_opt) - { - debuginfo_dirs = xasprintf("%s:%s", DEBUGINFO_CACHE_DIR, i_opt); - } + char *i_opt = NULL; + + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( + PROGNAME" [options] -d DIR" + ); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_i = 1 << 2, + OPT_t = 1 << 3, + OPT_s = 1 << 4, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_STRING( 'd', NULL, &dump_dir_name , "DIR" , _("Crash dump directory")), + OPT_STRING( 'i', NULL, &i_opt , "dir1[:dir2]...", _("Additional debuginfo directories")), + OPT_INTEGER('t', NULL, &exec_timeout_sec, _("Kill gdb if it runs for more than N seconds")), + OPT_BOOL( 's', NULL, NULL , _("Log to syslog")), + OPT_END() + }; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); msg_prefix = PROGNAME; - if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; } + if (i_opt) + { + debuginfo_dirs = xasprintf("%s:%s", DEBUGINFO_CACHE_DIR, i_opt); + } + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index 160b6412..4fef19b4 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) enum { OPT_s = (1 << 0), }; - int optflags = 0; + int opts = 0; int opt; while ((opt = getopt(argc, argv, "c:d:vs")) != -1) { @@ -147,7 +147,7 @@ int main(int argc, char **argv) g_verbose++; break; case 's': - optflags |= OPT_s; + opts |= OPT_s; break; default: /* Careful: the string below contains tabs, dont replace with spaces */ @@ -166,11 +166,9 @@ int main(int argc, char **argv) } putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. // msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); - - if (optflags & OPT_s) + if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index 00f73d03..0ac5454d 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -133,7 +133,8 @@ int main(int argc, char **argv) const char *dump_dir_name = "."; const char *conf_file = NULL; - const char *program_usage = _( + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( PROGNAME" [-v] -d DIR [-c CONFFILE]\n" "\n" "Upload compressed tarball of crash dump" @@ -150,12 +151,11 @@ int main(int argc, char **argv) OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), OPT_END() }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //msg_prefix = PROGNAME; - //if (optflags & OPT_s) + //if (opts & OPT_s) //{ // openlog(msg_prefix, 0, LOG_DAEMON); // logmode = LOGMODE_SYSLOG; diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 86a9a1d0..830d0b11 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -34,10 +34,12 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); - const char *program_usage = _( + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( PROGNAME" [-v] [-o FILE] -d DIR\n" "\n" - "Print information about the crash to standard output"); + "Print information about the crash to standard output" + ); enum { OPT_v = 1 << 0, OPT_d = 1 << 1, @@ -50,8 +52,7 @@ int main(int argc, char **argv) OPT_STRING('o', NULL, &output_file , "FILE", _("Output file")), OPT_END() }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //msg_prefix = PROGNAME; diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index a596ac40..42859d5c 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -259,7 +259,7 @@ int main(int argc, char **argv) enum { OPT_s = (1 << 0), }; - int optflags = 0; + int opts = 0; int opt; while ((opt = getopt(argc, argv, "c:d:vs")) != -1) { @@ -277,7 +277,7 @@ int main(int argc, char **argv) g_verbose++; break; case 's': - optflags |= OPT_s; + opts |= OPT_s; break; default: /* Careful: the string below contains tabs, dont replace with spaces */ @@ -296,11 +296,9 @@ int main(int argc, char **argv) } putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. // msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); - - if (optflags & OPT_s) + if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index 4bc5a458..6b54962b 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -244,7 +244,8 @@ int main(int argc, char **argv) const char *conf_file = NULL; const char *url = NULL; - const char *program_usage = _( + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( PROGNAME" [-v] -d DIR [-c CONFFILE] [-u URL]\n" "\n" "Upload compressed tarball of crash dump" @@ -263,12 +264,11 @@ int main(int argc, char **argv) OPT_STRING('u', NULL, &url , "URL" , _("Base URL to upload to")), OPT_END() }; - - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //msg_prefix = PROGNAME; - //if (optflags & OPT_s) + //if (opts & OPT_s) //{ // openlog(msg_prefix, 0, LOG_DAEMON); // logmode = LOGMODE_SYSLOG; diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c index 07e2618b..bf4f1e96 100644 --- a/src/plugins/abrt-dump-oops.c +++ b/src/plugins/abrt-dump-oops.c @@ -534,9 +534,8 @@ int main(int argc, char **argv) if (env_verbose) g_verbose = atoi(env_verbose); - const char *filename = "/var/log/messages"; - - const char *program_usage = _( + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( PROGNAME" [-vsrdow] FILE\n" "\n" "Extract oops from syslog/dmesg file" @@ -559,12 +558,7 @@ int main(int argc, char **argv) OPT_BOOL('w', NULL, NULL, _("Do not exit, watch the file for new oopses")), OPT_END() }; - - unsigned opts = parse_opts(argc, argv, program_options, program_usage); - argv += optind; - if (!argv[0]) - show_usage_and_die(program_usage, program_options); - filename = argv[0]; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); msg_prefix = PROGNAME; @@ -575,6 +569,11 @@ int main(int argc, char **argv) logmode = LOGMODE_SYSLOG; } + argv += optind; + if (!argv[0]) + show_usage_and_die(program_usage_string, program_options); + const char *filename = argv[0]; + int inotify_fd = -1; if (opts & OPT_w) { -- cgit From a0dc58e8355a0d4b98b9c88e0f26172b1418d7c9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 21:32:58 +0100 Subject: add OPT_LIST mechanism to handle multiply occurring options This allowed to convert abrt-action-bugzilla, abrt-action-rhtsupport and abrt-action-kerneloops to parse_opts() Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 71 +++++++++++++++++------------------- src/plugins/abrt-action-kerneloops.c | 68 ++++++++++++++++------------------ src/plugins/abrt-action-mailx.c | 1 - src/plugins/abrt-action-print.c | 1 - src/plugins/abrt-action-rhtsupport.c | 68 ++++++++++++++++------------------ src/plugins/abrt-action-upload.c | 1 - 6 files changed, 96 insertions(+), 114 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 9d849d99..4dfafe90 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -19,6 +19,9 @@ #include "abrtlib.h" #include "abrt_xmlrpc.h" #include "abrt_crash_data.h" +#include "parse_options.h" + +#define PROGNAME "abrt-action-bugzilla" #define XML_RPC_SUFFIX "/xmlrpc.cgi" #define MAX_HOPS 5 @@ -903,54 +906,48 @@ int main(int argc, char **argv) map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; + GList *conf_file = NULL; + + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( + PROGNAME" [-vs] -c CONFFILE -d DIR" + "\n" + "\nReport a crash to Bugzilla" + ); enum { - OPT_s = (1 << 0), + OPT_v = 1 << 0, + OPT_s = 1 << 1, + OPT_d = 1 << 2, + OPT_c = 1 << 3, }; - int opts = 0; - int opt; - while ((opt = getopt(argc, argv, "c:d:vs")) != -1) - { - switch (opt) - { - case 'c': - VERB1 log("Loading settings from '%s'", optarg); - load_conf_file(optarg, settings, /*skip key w/o values:*/ true); - VERB3 log("Loaded '%s'", optarg); - break; - case 'd': - dump_dir_name = optarg; - break; - case 'v': - g_verbose++; - break; - case 's': - opts |= OPT_s; - break; - default: - /* Careful: the string below contains tabs, dont replace with spaces */ - error_msg_and_die( - "Usage: abrt-action-bugzilla -c CONFFILE -d DIR [-vs]" - "\n" - "\nReport a crash to Bugzilla" - "\n" - "\nOptions:" - "\n -c FILE Configuration file (may be given many times)" - "\n -d DIR Crash dump directory" - "\n -v Be verbose" - "\n -s Log to syslog" - ); - } - } + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_BOOL( 's', NULL, NULL , _("Log to syslog")), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_LIST( 'c', NULL, &conf_file , "FILE", _("Configuration file (may be given many times)")), + OPT_END() + }; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. -// msg_prefix = xasprintf("abrt-action-bugzilla[%u]", getpid()); +// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; } + while (conf_file) + { + char *fn = (char *)conf_file->data; + VERB1 log("Loading settings from '%s'", fn); + load_conf_file(fn, settings, /*skip key w/o values:*/ true); + VERB3 log("Loaded '%s'", fn); + conf_file = g_list_remove(conf_file, fn); + } + VERB1 log("Initializing XML-RPC library"); xmlrpc_env env; xmlrpc_env_init(&env); diff --git a/src/plugins/abrt-action-kerneloops.c b/src/plugins/abrt-action-kerneloops.c index 4fef19b4..8d00da52 100644 --- a/src/plugins/abrt-action-kerneloops.c +++ b/src/plugins/abrt-action-kerneloops.c @@ -19,7 +19,7 @@ #include #include "abrtlib.h" -#include "abrt_crash_data.h" +#include "parse_options.h" #define PROGNAME "abrt-action-kerneloops" @@ -126,44 +126,29 @@ int main(int argc, char **argv) map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; + GList *conf_file = NULL; + + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( + PROGNAME" [-vs] -c CONFFILE -d DIR" + "\n" + "\nReport a kernel oops to kerneloops.org (or similar) site" + ); enum { - OPT_s = (1 << 0), + OPT_v = 1 << 0, + OPT_s = 1 << 1, + OPT_d = 1 << 2, + OPT_c = 1 << 3, }; - int opts = 0; - int opt; - while ((opt = getopt(argc, argv, "c:d:vs")) != -1) - { - switch (opt) - { - case 'c': - VERB1 log("Loading settings from '%s'", optarg); - load_conf_file(optarg, settings, /*skip key w/o values:*/ true); - VERB3 log("Loaded '%s'", optarg); - break; - case 'd': - dump_dir_name = optarg; - break; - case 'v': - g_verbose++; - break; - case 's': - opts |= OPT_s; - break; - default: - /* Careful: the string below contains tabs, dont replace with spaces */ - error_msg_and_die( - "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" - "\n" - "\nReport a kernel oops to kerneloops.org (or similar) site" - "\n" - "\nOptions:" - "\n -c FILE Configuration file (may be given many times)" - "\n -d DIR Crash dump directory" - "\n -v Be verbose" - "\n -s Log to syslog" - ); - } - } + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_BOOL( 's', NULL, NULL , _("Log to syslog")), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_LIST( 'c', NULL, &conf_file , "FILE", _("Configuration file (may be given many times)")), + OPT_END() + }; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. @@ -174,6 +159,15 @@ int main(int argc, char **argv) logmode = LOGMODE_SYSLOG; } + while (conf_file) + { + char *fn = (char *)conf_file->data; + VERB1 log("Loading settings from '%s'", fn); + load_conf_file(fn, settings, /*skip key w/o values:*/ true); + VERB3 log("Loaded '%s'", fn); + conf_file = g_list_remove(conf_file, fn); + } + report_to_kerneloops(dump_dir_name, settings); free_map_string(settings); diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index 0ac5454d..3debf449 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -21,7 +21,6 @@ #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_data.h" #define PROGNAME "abrt-action-mailx" diff --git a/src/plugins/abrt-action-print.c b/src/plugins/abrt-action-print.c index 830d0b11..cc7fbb34 100644 --- a/src/plugins/abrt-action-print.c +++ b/src/plugins/abrt-action-print.c @@ -20,7 +20,6 @@ */ #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_data.h" #define PROGNAME "abrt-action-print" diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 42859d5c..337adae1 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -22,7 +22,7 @@ #include "abrt_curl.h" #include "abrt_xmlrpc.h" #include "abrt_rh_support.h" -#include "abrt_crash_data.h" +#include "parse_options.h" #define PROGNAME "abrt-action-rhtsupport" @@ -256,44 +256,29 @@ int main(int argc, char **argv) map_string_h *settings = new_map_string(); const char *dump_dir_name = "."; + GList *conf_file = NULL; + + /* Can't keep these strings/structs static: _() doesn't support that */ + const char *program_usage_string = _( + PROGNAME" [-vs] -c CONFFILE -d DIR" + "\n" + "\nReport a crash to RHTSupport" + ); enum { - OPT_s = (1 << 0), + OPT_v = 1 << 0, + OPT_s = 1 << 1, + OPT_d = 1 << 2, + OPT_c = 1 << 3, }; - int opts = 0; - int opt; - while ((opt = getopt(argc, argv, "c:d:vs")) != -1) - { - switch (opt) - { - case 'c': - VERB1 log("Loading settings from '%s'", optarg); - load_conf_file(optarg, settings, /*skip key w/o values:*/ true); - VERB3 log("Loaded '%s'", optarg); - break; - case 'd': - dump_dir_name = optarg; - break; - case 'v': - g_verbose++; - break; - case 's': - opts |= OPT_s; - break; - default: - /* Careful: the string below contains tabs, dont replace with spaces */ - error_msg_and_die( - "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" - "\n" - "\nReport a crash to RHTSupport" - "\n" - "\nOptions:" - "\n -c FILE Configuration file (may be given many times)" - "\n -d DIR Crash dump directory" - "\n -v Be verbose" - "\n -s Log to syslog" - ); - } - } + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_BOOL( 's', NULL, NULL , _("Log to syslog")), + OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")), + OPT_LIST( 'c', NULL, &conf_file , "FILE", _("Configuration file (may be given many times)")), + OPT_END() + }; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); //DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. @@ -304,6 +289,15 @@ int main(int argc, char **argv) logmode = LOGMODE_SYSLOG; } + while (conf_file) + { + char *fn = (char *)conf_file->data; + VERB1 log("Loading settings from '%s'", fn); + load_conf_file(fn, settings, /*skip key w/o values:*/ true); + VERB3 log("Loaded '%s'", fn); + conf_file = g_list_remove(conf_file, fn); + } + VERB1 log("Initializing XML-RPC library"); xmlrpc_env env; xmlrpc_env_init(&env); diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index 6b54962b..82c99fd5 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -21,7 +21,6 @@ #include #include "abrtlib.h" #include "parse_options.h" -#include "abrt_crash_data.h" #define PROGNAME "abrt-action-upload" -- cgit From 5eadc6530d76de846ec63ece738f425c9291941d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Jan 2011 20:59:14 +0100 Subject: move block of code to eliminate a goto Signed-off-by: Denys Vlasenko --- src/plugins/abrt_rh_support.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt_rh_support.c b/src/plugins/abrt_rh_support.c index 04e2c8ef..e9092023 100644 --- a/src/plugins/abrt_rh_support.c +++ b/src/plugins/abrt_rh_support.c @@ -391,6 +391,15 @@ send_report_to_new_case(const char* baseURL, char *case_location = find_header_in_abrt_post_state(case_state, "Location:"); switch (case_state->http_resp_code) { + case 404: + /* Not strictly necessary (default branch would deal with it too), + * but makes this typical error less cryptic: + * instead of returning html-encoded body, we show short concise message, + * and show offending URL (typos in which is a typical cause) */ + retval = xasprintf("error in case creation, " + "HTTP code: 404 (Not found), URL:'%s'", case_url); + break; + case 301: /* "301 Moved Permanently" (for example, used to move http:// to https://) */ case 302: /* "302 Found" (just in case) */ case 305: /* "305 Use Proxy" */ @@ -401,18 +410,9 @@ send_report_to_new_case(const char* baseURL, free_abrt_post_state(case_state); goto redirect_case; } - goto bad_resp_code; - - case 404: - /* Not strictly necessary, but makes this typical error less cryptic: - * instead of returning html-encoded body, we show short concise message, - * and show offending URL (typos in which is a typical cause) */ - retval = xasprintf("error in case creation, " - "HTTP code: 404 (Not found), URL:'%s'", case_url); - break; + /* fall through */ default: - bad_resp_code: errmsg = case_state->curl_error_msg; if (errmsg) retval = xasprintf("error in case creation: %s", errmsg); -- cgit From 14fea7f8299a1bd82101f28d4106ee2f399527fc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Jan 2011 21:00:31 +0100 Subject: comment out unused function post_signature Signed-off-by: Denys Vlasenko --- src/plugins/abrt_rh_support.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/abrt_rh_support.c b/src/plugins/abrt_rh_support.c index e9092023..fb1106de 100644 --- a/src/plugins/abrt_rh_support.c +++ b/src/plugins/abrt_rh_support.c @@ -211,6 +211,7 @@ reportfile_free(reportfile_t* file) } +#if 0 //unused // // post_signature() // @@ -272,6 +273,7 @@ post_signature(const char* baseURL, bool ssl_verify, const char* signature) free_abrt_post_state(state); return retval; } +#endif // -- cgit From 5b9e9ee58b4c778b3c07c1960b874efd058c21a0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Jan 2011 21:02:22 +0100 Subject: plug memory leak on error paths Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 4dfafe90..abbd53ae 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -685,6 +685,7 @@ static void report_to_bugzilla( char *product = NULL; char *version = NULL; parse_release(release, &product, &version); + free(version); xmlrpc_value *result; if (strcmp(product, "Fedora") == 0) @@ -761,7 +762,6 @@ static void report_to_bugzilla( } } free(product); - free(version); if (all_bugs_size < 0) { -- cgit From 7f5cbf38caa3c6fdd0afe3a4cb7a9bd3b3010596 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Jan 2011 21:17:49 +0100 Subject: split parse_release() into Bz and RHTS versions Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-bugzilla.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index abbd53ae..ed8a7e72 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -328,7 +328,7 @@ xmlrpc_value* ctx::call_quicksearch_duphash(const char* component, const char* r { char *product = NULL; char *version = NULL; - parse_release(release, &product, &version); + parse_release_for_bz(release, &product, &version); query = xasprintf("ALL component:\"%s\" whiteboard:\"%s\" product:\"%s\"", component, duphash, product ); @@ -482,7 +482,7 @@ xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) char *product = NULL; char *version = NULL; - parse_release(release, &product, &version); + parse_release_for_bz(release, &product, &version); xmlrpc_value* result = NULL; char *summary = strbuf_free_nobuf(buf_summary); @@ -684,7 +684,7 @@ static void report_to_bugzilla( char *product = NULL; char *version = NULL; - parse_release(release, &product, &version); + parse_release_for_bz(release, &product, &version); free(version); xmlrpc_value *result; -- cgit From b27a8ff7442559409fe005ef721bc855b5512e3c Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 25 Jan 2011 22:58:42 +0100 Subject: don't try to remove the tmp dir if it's not created - if no package is found the tmp dir is not created, but we tried to remove it anyway which failed --- src/plugins/abrt-action-install-debuginfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index b16cc3e9..d59d0e5f 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -210,7 +210,7 @@ class DebugInfoDownload(YumBase): installed_size += float(pkg[0].installedsize) total_pkgs += 1 - log2("found pkg for %s" % debuginfo_path) + log2("found pkg for %s : %s" % (debuginfo_path, pkg[0])) else: log2("not found pkg for %s" % debuginfo_path) not_found.append(debuginfo_path) @@ -271,13 +271,13 @@ class DebugInfoDownload(YumBase): downloaded_pkgs += 1 - if not self.keeprpms: + if not self.keeprpms and os.path.exists(self.tmpdir): print (_("All downloaded packages have been extracted, removing %s") % self.tmpdir) try: os.rmdir(self.tmpdir) except OSError: - print _("Can't remove %s, probably contains an error log") + print _("Can't remove %s, probably contains an error log" % self.tmpdir) verbose = 0 def log1(message): -- cgit From 38a0e2f132853f6ded18b9cb3c787b7e0a0206e8 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Mon, 31 Jan 2011 17:06:43 +0100 Subject: Rating 0 (worst) for backtrace on which the parser fails. --- src/plugins/abrt-action-generate-backtrace.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 05f878e2..0c4d4165 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -318,10 +318,9 @@ int main(int argc, char **argv) { VERB1 log(_("Backtrace parsing failed for %s"), dump_dir_name); VERB1 log("%d:%d: %s", location.line, location.column, location.message); - /* If the parser failed compute the UUID from the executable - and package only. This is not supposed to happen often. - Do not store the rating, as we do not know how good the - backtrace is. */ + /* If the parser failed, compute the UUID from the executable + * and package only. This is not supposed to happen often. + */ struct strbuf *emptybt = strbuf_new(); strbuf_prepend_str(emptybt, executable); strbuf_prepend_str(emptybt, package); @@ -329,6 +328,13 @@ int main(int argc, char **argv) create_hash(hash_str, emptybt->buf); dd_save_text(dd, FILENAME_DUPHASH, hash_str); + /* Other parts of ABRT assume that if no rating is available, + * it is ok to allow reporting of the bug. To be sure no bad + * backtrace is reported, rate the backtrace with the lowest + * rating. + */ + dd_save_text(dd, FILENAME_RATING, "0"); + strbuf_free(emptybt); free(backtrace_str); free(package); -- cgit From 5988da0639d88ee841fec7c6144533e6850bcdc1 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Mon, 31 Jan 2011 18:23:56 +0100 Subject: Increase limit for gdb run, as it was reported that 60 secs is too limiting on slow machines --- src/plugins/abrt-action-generate-backtrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 0c4d4165..234d91e9 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -29,7 +29,8 @@ static const char *dump_dir_name = "."; static const char *debuginfo_dirs = DEBUGINFO_CACHE_DIR; -static int exec_timeout_sec = 60; +/* 60 seconds was too limiting on slow machines */ +static int exec_timeout_sec = 240; static void create_hash(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *pInput) -- cgit From 63a7bca1faf63c4abc075a2fc293dd58f0760a62 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 31 Jan 2011 09:55:20 +0100 Subject: rhtsupport reads from uninitialized variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit abrt-action-rhtsupport.c: In function ‘main’: abrt-action-rhtsupport.c:231:12: warning: ‘child’ may be used uninitialized in this function [-Wuninitialized] abrt-action-rhtsupport.c:45:11: note: ‘child’ was declared here ... ... pid_t child; ... ... if (!login[0] || !password[0]) { errmsg = _("Empty login or password, please check RHTSupport.conf"); goto ret; } ... ... ret: // Damn, selinux does not allow SIGKILLing our own child! wtf?? //kill(child, SIGKILL); /* just in case */ waitpid(child, NULL, 0); ... ... Signed-off-by: Nikola Pajkovsky --- src/plugins/abrt-action-rhtsupport.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 337adae1..d6d677ac 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -66,8 +66,12 @@ static void report_to_rhtsupport( if (!login[0] || !password[0]) { - errmsg = _("Empty login or password, please check RHTSupport.conf"); - goto ret; + free_crash_data(crash_data); + free(url); + free(login); + free(password); + error_msg_and_die(_("Empty login or password, please check RHTSupport.conf")); + return; } package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); -- 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/plugins/abrt-dump-oops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins') diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c index bf4f1e96..5b6a2062 100644 --- a/src/plugins/abrt-dump-oops.c +++ b/src/plugins/abrt-dump-oops.c @@ -506,6 +506,7 @@ static int save_oops_to_dump_dir(GList *oops_list, unsigned oops_cnt) struct dump_dir *dd = dd_create(path, /*uid:*/ 0); if (dd) { + dd_create_basic_files(dd, /*uid:*/ 0); dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops"); dd_save_text(dd, FILENAME_EXECUTABLE, "kernel"); dd_save_text(dd, FILENAME_KERNEL, first_line); -- cgit From 3fc1eead9f0671c87e62b2059eb0332760eb2e88 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Feb 2011 15:27:08 +0100 Subject: abrt_rh_support: remove code which looks into Strata-Message: header Signed-off-by: Denys Vlasenko --- src/plugins/abrt_rh_support.c | 77 +++---------------------------------------- 1 file changed, 4 insertions(+), 73 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt_rh_support.c b/src/plugins/abrt_rh_support.c index fb1106de..9a48485b 100644 --- a/src/plugins/abrt_rh_support.c +++ b/src/plugins/abrt_rh_support.c @@ -211,71 +211,6 @@ reportfile_free(reportfile_t* file) } -#if 0 //unused -// -// post_signature() -// -char* -post_signature(const char* baseURL, bool ssl_verify, const char* signature) -{ - char *URL = concat_path_file(baseURL, "/signatures"); - - abrt_post_state_t *state = new_abrt_post_state(0 - + ABRT_POST_WANT_HEADERS - + ABRT_POST_WANT_BODY - + ABRT_POST_WANT_ERROR_MSG - + (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0) - ); - int http_resp_code = abrt_post_string(state, URL, "application/xml", signature); - free(URL); - - char *retval; - const char *strata_msg; - switch (http_resp_code) - { - case 200: - case 201: - if (state->body) - { - retval = state->body; - state->body = NULL; - break; - } - strata_msg = find_header_in_abrt_post_state(state, "Strata-Message:"); - if (strata_msg && strcmp(strata_msg, "CREATED") != 0) { - retval = xstrdup(strata_msg); - break; - } - retval = xstrdup("Signature submitted successfully"); - break; - - default: - strata_msg = find_header_in_abrt_post_state(state, "Strata-Message:"); - if (strata_msg) - { - retval = xasprintf("Error (HTTP response %d): %s", - http_resp_code, - strata_msg); - break; - } - if (state->curl_error_msg) - { - if (http_resp_code >= 0) - retval = xasprintf("Error (HTTP response %d): %s", http_resp_code, state->curl_error_msg); - else - retval = xasprintf("Error in HTTP transaction: %s", state->curl_error_msg); - break; - } - retval = xasprintf("Error (HTTP response %d), body:\n%s", http_resp_code, state->body); - break; - } - - free_abrt_post_state(state); - return retval; -} -#endif - - // // send_report_to_new_case() // @@ -416,14 +351,12 @@ send_report_to_new_case(const char* baseURL, default: errmsg = case_state->curl_error_msg; - if (errmsg) + if (errmsg && errmsg[0]) retval = xasprintf("error in case creation: %s", errmsg); else { - errmsg = find_header_in_abrt_post_state(case_state, "Strata-Message:"); - if ((!errmsg || !errmsg[0]) && case_state->body && case_state->body[0]) - errmsg = case_state->body; - if (errmsg) + errmsg = case_state->body; + if (errmsg && errmsg[0]) retval = xasprintf("error in case creation, HTTP code: %d, server says: '%s'", case_state->http_resp_code, errmsg); else @@ -469,9 +402,7 @@ send_report_to_new_case(const char* baseURL, default: /* Case Creation Succeeded, attachement FAILED */ - errmsg = find_header_in_abrt_post_state(atch_state, "Strata-Message:"); - if (!errmsg || !errmsg[0]) - errmsg = atch_state->curl_error_msg; + errmsg = atch_state->curl_error_msg; if (atch_state->body && atch_state->body[0]) { if (errmsg && errmsg[0] -- cgit From 236f571db5ec6d0f05891373f518b6d87cedebbe Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Fri, 4 Feb 2011 11:36:50 +0100 Subject: abrt-action-generate-backtrace: exit with 0 even if the parser fails --- src/plugins/abrt-action-generate-backtrace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 234d91e9..7173d778 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -341,7 +341,12 @@ int main(int argc, char **argv) free(package); free(executable); dd_close(dd); - return 2; + + /* Report success even if the parser failed, as the backtrace + * has been created and rated. The failure is caused by a flaw + * in the parser, not in the backtrace. + */ + return 0; } free(backtrace_str); -- 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/plugins/abrt-action-bugzilla.cpp | 6 +++--- src/plugins/abrt-action-rhtsupport.c | 1 - src/plugins/abrt-action-upload.c | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index ed8a7e72..2aa32b75 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -448,7 +448,7 @@ xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno) { const char *package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); - const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); + const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); const char *arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); const char *reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON); @@ -673,7 +673,7 @@ static void report_to_bugzilla( const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT); const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH); - const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); + const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); ctx bz_server(bugzilla_xmlrpc, ssl_verify); @@ -858,7 +858,7 @@ static void report_to_bugzilla( if (dsc) { const char* package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE); - const char* release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE); + const char* release = get_crash_item_content_or_NULL(crash_data, FILENAME_OS_RELEASE); const char* arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE); const char* is_private = get_crash_item_content_or_NULL(crash_data, "is_private"); diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index d6d677ac..3ec81522 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -129,7 +129,6 @@ static void report_to_rhtsupport( if (strcmp(name, CD_DUMPDIR) == 0) continue; if (strcmp(name, FILENAME_INFORMALL) == 0) continue; if (strcmp(name, FILENAME_MESSAGE) == 0) continue; // plugin's status message (if we already reported it yesterday) - if (strcmp(name, FILENAME_DESCRIPTION) == 0) continue; // package description const char *content = value->content; if (value->flags & CD_FLAG_TXT) diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index 82c99fd5..b19f5bfb 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -161,7 +161,6 @@ static int create_and_upload_archive( if (strcmp(short_name, CD_DUMPDIR) == 0) goto next; if (strcmp(short_name, FILENAME_INFORMALL) == 0) goto next; if (strcmp(short_name, FILENAME_MESSAGE) == 0) goto next; // plugin's status message (if we already reported it yesterday) - if (strcmp(short_name, FILENAME_DESCRIPTION) == 0) goto next; // package description // dd_get_next_file guarantees this: //struct stat stbuf; //if (stat(full_name, &stbuf) != 0) -- cgit From 292fb47cb67837bc203c3038f75968a978440be7 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 21 Feb 2011 18:39:48 +0100 Subject: run abrt-action-install-debuginfo.py using trivial sgid wrapper Signed-off-by: Jiri Moskovcak Signed-off-by: Denys Vlasenko --- src/plugins/Makefile.am | 12 +++++++++++- src/plugins/abrt-action-install-debuginfo.c | 16 ++++++++++++++++ src/plugins/abrt-action-install-debuginfo.py | 11 +++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/plugins/abrt-action-install-debuginfo.c (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 3ba454e2..938f88ba 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -14,7 +14,8 @@ bin_PROGRAMS = \ abrt-action-kerneloops \ abrt-action-upload \ abrt-action-mailx \ - abrt-action-print + abrt-action-print \ + abrt-action-install-debuginfo dist_pluginslib_DATA = \ Logger.glade \ @@ -278,4 +279,13 @@ abrt_action_print_CPPFLAGS = \ abrt_action_print_LDADD = \ ../lib/libreport.la +abrt_action_install_debuginfo_SOURCES = \ + abrt-action-install-debuginfo.c +abrt_action_install_debuginfo_CPPFLAGS = \ + -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -I$(srcdir)/../lib \ + -D_GNU_SOURCE \ + -Wall +abrt_action_install_debuginfo_LDADD = + DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ diff --git a/src/plugins/abrt-action-install-debuginfo.c b/src/plugins/abrt-action-install-debuginfo.c new file mode 100644 index 00000000..dc7eed79 --- /dev/null +++ b/src/plugins/abrt-action-install-debuginfo.c @@ -0,0 +1,16 @@ +#include +#include + +#define EXECUTABLE "abrt-action-install-debuginfo.py" + +/* A binary wrapper is needed around python scripts if we want + * to run them in sgid/suid mode. + * + * This is such a wrapper. + */ +int main(int argc, char **argv) +{ + execvp(EXECUTABLE, argv); + write(2, "Can't execute "EXECUTABLE"\n", strlen("Can't execute "EXECUTABLE"\n")); + return 1; +} diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index d59d0e5f..535796e6 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -51,7 +51,11 @@ def unmute_stdout(): def ask_yes_no(prompt, retries=4): while True: - response = raw_input(prompt) + try: + response = raw_input(prompt) + except EOFError: + log1("got eof, probably executed from helper, assuming - yes") + response = 'y' if response in ('y', 'Y'): return True if response in ('n', 'N', ''): @@ -412,7 +416,7 @@ if __name__ == "__main__": help_text = _("Usage: %s --core= " "--tmpdir= " - "--cachedir=") % sys.argv[0] + "--cache=") % sys.argv[0] try: opts, args = getopt.getopt(sys.argv[1:], "vyhc:", ["help", "core=", "cache=", "tmpdir=", @@ -443,7 +447,7 @@ if __name__ == "__main__": print help_text exit(RETURN_FAILURE) if not cachedir: - print _("You have to specify the path to cachedir.") + print _("You have to specify the path to cache.") print help_text exit(RETURN_FAILURE) if not tmpdir: @@ -469,4 +473,3 @@ if __name__ == "__main__": print _("Complete!") exit(result) - -- cgit From 20a9c4ddff4e597bc67f6cc232890ea946b38692 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Feb 2011 05:09:13 +0100 Subject: abrt-action-install-debuginfo: disallow overriding paths to writable dirs Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo.c | 31 ++++++++++++++++++++++++++-- src/plugins/abrt-action-install-debuginfo.py | 9 +++----- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.c b/src/plugins/abrt-action-install-debuginfo.c index dc7eed79..39915e59 100644 --- a/src/plugins/abrt-action-install-debuginfo.c +++ b/src/plugins/abrt-action-install-debuginfo.c @@ -3,6 +3,20 @@ #define EXECUTABLE "abrt-action-install-debuginfo.py" +static void error_msg_and_die(const char *msg, const char *arg) +{ + write(2, msg, strlen(msg)); + if (arg) + { + write(2, " '", 2); + write(2, msg, strlen(msg)); + write(2, "'", 1); + } + write(2, "\n", 1); + exit(1); +} + + /* A binary wrapper is needed around python scripts if we want * to run them in sgid/suid mode. * @@ -10,7 +24,20 @@ */ int main(int argc, char **argv) { + /* + * We disallow passing of arguments which point to writable dirs. + * This way, the script will always use default arguments. + */ + char **pp = argv; + char *arg; + while ((arg = *++pp) != NULL) + { + if (strncmp(arg, "--cache", 7) == 0) + error_msg_and_die("bad option", arg); + if (strncmp(arg, "--tmpdir", 8) == 0) + error_msg_and_die("bad option", arg); + } + execvp(EXECUTABLE, argv); - write(2, "Can't execute "EXECUTABLE"\n", strlen("Can't execute "EXECUTABLE"\n")); - return 1; + error_msg_and_die("Can't execute", EXECUTABLE); } diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index 535796e6..72f56a9d 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -6,6 +6,7 @@ from subprocess import Popen, PIPE import sys import os +import time import getopt import shutil from yum import _, YumBase @@ -447,13 +448,9 @@ if __name__ == "__main__": print help_text exit(RETURN_FAILURE) if not cachedir: - print _("You have to specify the path to cache.") - print help_text - exit(RETURN_FAILURE) + cachedir = "/var/cache/abrt-di" if not tmpdir: - print _("You have to specify the path to tmpdir.") - print help_text - exit(RETURN_FAILURE) + tmpdir = "/var/run/abrt/install-debuginfo-%s.%u" % (time.strftime("%Y-%m-%d-%H:%M:%S"), os.getpid()) b_ids = extract_info_from_core(core) if b_ids == RETURN_FAILURE: -- cgit From 6cc86c66a15ea305b453e5d1b2d62e4d974f579d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Feb 2011 05:10:31 +0100 Subject: abrt-action-install-debuginfo.py: do not truncate package names on output Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index 72f56a9d..d09f00f5 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -123,7 +123,7 @@ class MyDownloadCallback(DownloadBaseCallback): DownloadBaseCallback.__init__(self) def updateProgress(self, name, frac, fread, ftime): - pct = int( frac*100 ) + pct = int(frac * 100) if pct == self.last_pct: log2("percentage is the same, not updating progress") return @@ -131,18 +131,18 @@ class MyDownloadCallback(DownloadBaseCallback): self.last_pct = pct # if run from terminal we can have a fancy output if sys.stdout.isatty(): - sys.stdout.write("\033[sDownloading (%i of %i) %.30s : %.3s %%\033[u" + sys.stdout.write("\033[sDownloading (%i of %i) %s: %.3s %%\033[u" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) if pct == 100: - print _("Downloading (%i of %i) %.30s : %.3s %%" + print _("Downloading (%i of %i) %s: %.3s %%" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) # but we want machine friendly output when spawned from abrt-server else: - print (_("Downloading (%i of %i) %.30s : %.3s %%") + print (_("Downloading (%i of %i) %s: %.3s %%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) @@ -222,7 +222,7 @@ class DebugInfoDownload(YumBase): # connect our progress update callback dnlcb = MyDownloadCallback(total_pkgs) - self.repos.setProgressBar( dnlcb ) + self.repos.setProgressBar(dnlcb) log1("%i files in %i packages" % (len(files), total_pkgs)) @@ -431,7 +431,7 @@ if __name__ == "__main__": verbose += 1 elif opt == "-y": noninteractive = True - elif opt in ("--core","-c"): + elif opt in ("--core", "-c"): core = arg elif opt in ("--cache"): cachedir = arg -- cgit From ffece2d20673269029bb0b9403e20125e92382fa Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Feb 2011 05:59:43 +0100 Subject: correct rights on /var/run/abrt; improve new GUI a bit Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo.py | 6 +++--- src/plugins/abrt-action-upload.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index d09f00f5..f9d1f50f 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -131,18 +131,18 @@ class MyDownloadCallback(DownloadBaseCallback): self.last_pct = pct # if run from terminal we can have a fancy output if sys.stdout.isatty(): - sys.stdout.write("\033[sDownloading (%i of %i) %s: %.3s %%\033[u" + sys.stdout.write("\033[sDownloading (%i of %i) %s: %3u%%\033[u" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) if pct == 100: - print _("Downloading (%i of %i) %s: %.3s %%" + print _("Downloading (%i of %i) %s: %3u%%" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) # but we want machine friendly output when spawned from abrt-server else: - print (_("Downloading (%i of %i) %s: %.3s %%") + print (_("Downloading (%i of %i) %s: %3u%%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index b19f5bfb..6f9c5fab 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -128,7 +128,7 @@ static int create_and_upload_archive( /* Create a child gzip which will compress the data */ /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); + tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/upload-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); int pipe_from_parent_to_child[2]; xpipe(pipe_from_parent_to_child); child = fork(); -- cgit From f085ee31f7e264fb3c288dc7ad7f88118d275318 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Feb 2011 12:45:19 +0100 Subject: abrt-action-install-debuginfo.py: use /tmp for now Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index f9d1f50f..14838168 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -450,7 +450,9 @@ if __name__ == "__main__": if not cachedir: cachedir = "/var/cache/abrt-di" if not tmpdir: - tmpdir = "/var/run/abrt/install-debuginfo-%s.%u" % (time.strftime("%Y-%m-%d-%H:%M:%S"), os.getpid()) + # security people prefer temp subdirs in app's private dir, like /var/run/abrt + # for now, we use /tmp... + tmpdir = "/tmp/abrt-tmp-debuginfo-%s.%u" % (time.strftime("%Y-%m-%d-%H:%M:%S"), os.getpid()) b_ids = extract_info_from_core(core) if b_ids == RETURN_FAILURE: -- cgit From 72a31a2a391e6c37255ed08b3bdbf1c38f20d753 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Feb 2011 18:17:13 +0100 Subject: gui-wizard-gtk: add forward_page_func which skips analyze step when it is missing Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-analyze-c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c index a736c4f8..5def9aa1 100644 --- a/src/plugins/abrt-action-analyze-c.c +++ b/src/plugins/abrt-action-analyze-c.c @@ -104,7 +104,7 @@ static char *run_unstrip_n(const char *dump_dir_name, unsigned timeout_sec) if (status != 0) { - /* unstrip didnt exit with exitcode 0 */ + /* unstrip didnt exit with exit code 0 */ strbuf_free(buf_out); return NULL; } -- cgit From 8445adb47ece5ecf03d95d3d4d1af7b3415b25af Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 22 Feb 2011 19:53:10 +0100 Subject: move ccpp related events to events.d/ - so now when the abrt-addon-ccpp is removed it's config will be removed with it, so the rest of abrt and libreport won't be confused --- src/plugins/Makefile.am | 5 +++++ src/plugins/ccpp_events.conf | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/plugins/ccpp_events.conf (limited to 'src/plugins') diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 938f88ba..c6451c83 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -37,6 +37,11 @@ dist_pluginsconf_DATA = \ RHTSupport.conf \ Upload.conf +eventsconfdir = $(EVENTS_CONF_DIR) + +dist_eventsconf_DATA = \ + ccpp_events.conf + man_MANS = \ abrt-Bugzilla.7 \ abrt-KerneloopsReporter.7 \ diff --git a/src/plugins/ccpp_events.conf b/src/plugins/ccpp_events.conf new file mode 100644 index 00000000..1ad57608 --- /dev/null +++ b/src/plugins/ccpp_events.conf @@ -0,0 +1,17 @@ +EVENT=post-create analyzer=CCpp abrt-action-analyze-c + +#TODO: implement this (or add this functionality to abrt-action-install-debuginfo): +#EVENT=analyze analyzer=CCpp backtrace= trim-debuginfo-cache /var/cache/abrt-di 4096m + +#TODO: can we still specify additional directories to search for debuginfos, +# or was this ability lost with move to python installer? +EVENT=analyze analyzer=CCpp backtrace= abrt-action-install-debuginfo --core="$DUMP_DIR/coredump" +EVENT=analyze analyzer=CCpp backtrace= abrt-action-generate-backtrace + +# Same as "analyze", but executed when user requests "refresh" in GUI +#EVENT=reanalyze analyzer=CCpp trim-debuginfo-cache /var/cache/abrt-di 4096m +EVENT=reanalyze analyzer=CCpp abrt-action-install-debuginfo --core="$DUMP_DIR/coredump" +EVENT=reanalyze analyzer=CCpp abrt-action-generate-backtrace + +EVENT=report_Bugzilla analyzer=CCpp abrt-action-bugzilla -c /etc/abrt/plugins/Bugzilla.conf +EVENT=report_Logger analyzer=CCpp abrt-action-print -o /var/log/abrt.log -- cgit From 2db904065288fe6da52792de0ef8297092682c82 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Feb 2011 17:57:18 +0100 Subject: abrt-action-generate-backtrace/install-debuginfo: a bit better logging Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-generate-backtrace.c | 48 ++++++---- src/plugins/abrt-action-install-debuginfo.py | 131 +++++++++++++-------------- 2 files changed, 94 insertions(+), 85 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 7173d778..a8c18e36 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -276,7 +276,7 @@ int main(int argc, char **argv) unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - msg_prefix = PROGNAME; + //msg_prefix = PROGNAME; if (opts & OPT_s) { openlog(msg_prefix, 0, LOG_DAEMON); @@ -295,41 +295,53 @@ int main(int argc, char **argv) char *package = dd_load_text(dd, FILENAME_PACKAGE); char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); - /* Create and store backtrace */ + /* Create gdb backtrace */ /* NB: get_backtrace() closes dd */ char *backtrace_str = get_backtrace(dd); if (!backtrace_str) { backtrace_str = xstrdup(""); - VERB3 log("get_backtrace() returns NULL, broken core/gdb?"); + log("get_backtrace() returns NULL, broken core/gdb?"); } + /* Compute backtrace hash */ + struct btp_location location; + btp_location_init(&location); + char *backtrace_str_ptr = backtrace_str; + struct btp_backtrace *backtrace = btp_backtrace_parse(&backtrace_str_ptr, &location); + + /* Store gdb backtrace */ + dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return 1; - dd_save_text(dd, FILENAME_BACKTRACE, backtrace_str); + /* Don't be completely silent. gdb run takes a few seconds, + * it is useful to let user know it (maybe) worked. + */ + log(_("Backtrace is generated and saved, %u bytes"), (int)strlen(backtrace_str)); + free(backtrace_str); + + /* Store backtrace hash */ - /* Compute and store backtrace hash. */ - struct btp_location location; - btp_location_init(&location); - char *backtrace_str_ptr = backtrace_str; - struct btp_backtrace *backtrace = btp_backtrace_parse(&backtrace_str_ptr, &location); if (!backtrace) { - VERB1 log(_("Backtrace parsing failed for %s"), dump_dir_name); - VERB1 log("%d:%d: %s", location.line, location.column, location.message); - /* If the parser failed, compute the UUID from the executable + /* + * The parser failed. Compute the UUID from the executable * and package only. This is not supposed to happen often. */ + VERB1 log(_("Backtrace parsing failed for %s"), dump_dir_name); + VERB1 log("%d:%d: %s", location.line, location.column, location.message); struct strbuf *emptybt = strbuf_new(); strbuf_prepend_str(emptybt, executable); strbuf_prepend_str(emptybt, package); + char hash_str[SHA1_RESULT_LEN*2 + 1]; create_hash(hash_str, emptybt->buf); - dd_save_text(dd, FILENAME_DUPHASH, hash_str); - /* Other parts of ABRT assume that if no rating is available, + dd_save_text(dd, FILENAME_DUPHASH, hash_str); + /* + * Other parts of ABRT assume that if no rating is available, * it is ok to allow reporting of the bug. To be sure no bad * backtrace is reported, rate the backtrace with the lowest * rating. @@ -337,7 +349,6 @@ int main(int argc, char **argv) dd_save_text(dd, FILENAME_RATING, "0"); strbuf_free(emptybt); - free(backtrace_str); free(package); free(executable); dd_close(dd); @@ -348,7 +359,6 @@ int main(int argc, char **argv) */ return 0; } - free(backtrace_str); /* Compute duplication hash. */ char *str_hash_core = btp_backtrace_get_duplication_hash(backtrace); @@ -356,8 +366,10 @@ int main(int argc, char **argv) strbuf_append_str(str_hash, package); strbuf_append_str(str_hash, executable); strbuf_append_str(str_hash, str_hash_core); + char hash_str[SHA1_RESULT_LEN*2 + 1]; create_hash(hash_str, str_hash->buf); + dd_save_text(dd, FILENAME_DUPHASH, hash_str); strbuf_free(str_hash); free(str_hash_core); @@ -380,14 +392,14 @@ int main(int argc, char **argv) /* Get the function name from the crash frame. */ struct btp_frame *crash_frame = btp_backtrace_get_crash_frame(backtrace); if (crash_frame) - { + { if (crash_frame->function_name && 0 != strcmp(crash_frame->function_name, "??")) { dd_save_text(dd, FILENAME_CRASH_FUNCTION, crash_frame->function_name); } btp_frame_free(crash_frame); - } + } btp_backtrace_free(backtrace); dd_close(dd); diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index 14838168..98cb6e7c 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -70,30 +70,30 @@ def ask_yes_no(prompt, retries=4): # ..that can lead to: foo.c No such file and directory # files is not used... def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): - package_file_suffix = ".rpm" - package_full_path = tmp_dir + "/" + package_nevra + package_file_suffix + package_name = package_nevra + ".rpm" + package_full_path = tmp_dir + "/" + package_name log1("Extracting %s to %s" % (package_full_path, destdir)) log2(files) - print (_("Extracting cpio from %s") % (package_full_path)) + print _("Extracting cpio from %s") % (package_full_path) unpacked_cpio_path = tmp_dir + "/unpacked.cpio" try: unpacked_cpio = open(unpacked_cpio_path, 'wb') except IOError, ex: - print (_("Can't write to:"), (unpacked_cpio_path,ex)) + print _("Can't write to '%s': %s") % (unpacked_cpio_path, ex) return RETURN_FAILURE rpm2cpio = Popen(["rpm2cpio", package_full_path], - stdout=unpacked_cpio, bufsize=-1) + stdout = unpacked_cpio, bufsize = -1) retcode = rpm2cpio.wait() if retcode == 0: log1("cpio written OK") if not keeprpm: log1("keeprpms = False, removing %s" % package_full_path) - print _("Removing the temporary rpm file") + #print _("Removing temporary rpm file") os.unlink(package_full_path) else: unpacked_cpio.close() - print (_("Can't extract package: %s") % package_full_path) + print _("Can't extract package '%s'") % package_full_path return RETURN_FAILURE # close the file @@ -101,18 +101,17 @@ def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): # and open it for reading unpacked_cpio = open(unpacked_cpio_path, 'rb') - print (_("Caching files from %s made from %s") % - (unpacked_cpio_path, package_full_path)) + print _("Caching files from %s made from %s") % ("unpacked.cpio", package_name) cpio = Popen(["cpio","-i", "-d", "--quiet"], stdin=unpacked_cpio, cwd=destdir, bufsize=-1) retcode = cpio.wait() if retcode == 0: log1("files extracted OK") - print _("Removing the temporary cpio file") + #print _("Removing temporary cpio file") os.unlink(unpacked_cpio_path) else: - print (_("Can't extract files from: %s") % unpacked_cpio_path) + print _("Can't extract files from '%s'") % unpacked_cpio_path return RETURN_FAILURE class MyDownloadCallback(DownloadBaseCallback): @@ -120,6 +119,7 @@ class MyDownloadCallback(DownloadBaseCallback): self.total_pkgs = total_pkgs self.downloaded_pkgs = 0 self.last_pct = 0 + self.last_time = 0 DownloadBaseCallback.__init__(self) def updateProgress(self, name, frac, fread, ftime): @@ -129,27 +129,32 @@ class MyDownloadCallback(DownloadBaseCallback): return self.last_pct = pct - # if run from terminal we can have a fancy output + # if run from terminal we can have fancy output if sys.stdout.isatty(): sys.stdout.write("\033[sDownloading (%i of %i) %s: %3u%%\033[u" - % (self.downloaded_pkgs + 1, self.total_pkgs, - name, pct) - ) + % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) + ) if pct == 100: - print _("Downloading (%i of %i) %s: %3u%%" - % (self.downloaded_pkgs + 1, self.total_pkgs, - name, pct) - ) + print (_("Downloading (%i of %i) %s: %3u%%") + % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) + ) # but we want machine friendly output when spawned from abrt-server else: - print (_("Downloading (%i of %i) %s: %3u%%") - % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) - ) + t = time.time() + if self.last_time == 0: + self.last_time = t + # update only every 10 seconds + if pct == 100 or self.last_time > t or t - self.last_time >= 10: + print (_("Downloading (%i of %i) %s: %3u%%") + % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) + ) + self.last_time = t + if pct == 100: + self.last_time = 0 sys.stdout.flush() class DebugInfoDownload(YumBase): - """abrt-debuginfo-install --core=CORE tmpdir cachedir""" def __init__(self, cache, tmp, keep_rpms=False): self.cachedir = cache self.tmpdir = tmp @@ -171,13 +176,16 @@ class DebugInfoDownload(YumBase): if not files: return - print _("Searching the missing debuginfo packages") - # this suppress yum messages about setting up repositories - mute_stdout() + if verbose != 0 or len(files) != 0: + print _("Searching for packages for %u debuginfo files") % len(files) + + if verbose == 0: + # this suppress yum messages about setting up repositories + mute_stdout() # make yumdownloader work as non root user. if not self.setCacheDir(): - self.logger.error("Error: Could not make cachedir, exiting") + self.logger.error("Error: can't make cachedir, exiting") sys.exit(50) # disable all not needed @@ -196,13 +204,14 @@ class DebugInfoDownload(YumBase): self.repos.populateSack(mdtype='metadata', cacheonly=1) self.repos.populateSack(mdtype='filelists', cacheonly=1) - # re-enable the output to stdout - unmute_stdout() + if verbose == 0: + # re-enable the output to stdout + unmute_stdout() not_found = [] package_files_dict = {} for debuginfo_path in files: - log2("yum whatprovides %s" %debuginfo_path) + log2("yum whatprovides %s" % debuginfo_path) pkg = self.pkgSack.searchFiles(debuginfo_path) # sometimes one file is provided by more rpms, we can use either of # them, so let's use the first match @@ -215,7 +224,7 @@ class DebugInfoDownload(YumBase): installed_size += float(pkg[0].installedsize) total_pkgs += 1 - log2("found pkg for %s : %s" % (debuginfo_path, pkg[0])) + log2("found pkg for %s: %s" % (debuginfo_path, pkg[0])) else: log2("not found pkg for %s" % debuginfo_path) not_found.append(debuginfo_path) @@ -224,20 +233,14 @@ class DebugInfoDownload(YumBase): dnlcb = MyDownloadCallback(total_pkgs) self.repos.setProgressBar(dnlcb) - log1("%i files in %i packages" % (len(files), total_pkgs)) - - print (_("To download: (%.2f) M / Installed size: %.2f M" % - ( - todownload_size / (1024**2), - installed_size / (1024**2)) - ) - ) - #print _("%i debug infos not found" % len(not_found)) - - log1("packages: %i\nTo download: %f \nUnpacked size: %f" % - (total_pkgs, - todownload_size / (1024**2), - installed_size / (1024**2))) + if verbose != 0 or len(not_found) != 0: + print _("Packages for %u debuginfo files were not found") % len(not_found) + if verbose != 0 or total_pkgs != 0: + print _("Found %u packages to download") % total_pkgs + print _("Downloading %.2fMb, installed size: %.2fMb") % ( + todownload_size / (1024**2), + installed_size / (1024**2) + ) # ask only if we have terminal, because for now we don't have a way # how to pass the question to gui and the response back @@ -307,8 +310,7 @@ def extract_info_from_core(corefile): #SEP = 3 EXECUTABLE = 4 - print (_("Analyzing corefile: %(corefile_path)s") % - {"corefile_path":corefile}) + print _("Analyzing corefile '%s'") % corefile eu_unstrip_OUT = Popen(["eu-unstrip","--core=%s" % corefile, "-n"], stdout=PIPE, bufsize=-1).communicate()[0] # parse eu_unstrip_OUT and return the list of build_ids @@ -328,7 +330,7 @@ def extract_info_from_core(corefile): #print eu_unstrip_OUT # we failed to get build ids from the core -> die if not eu_unstrip_OUT: - log1("can't get build ids from the core") + print "Can't get build ids from %s" % corefile return RETURN_FAILURE lines = eu_unstrip_OUT.split('\n') @@ -349,7 +351,7 @@ def extract_info_from_core(corefile): libraries.add(library) build_ids.add(build_id) else: - log2("skipping line %s" % line) + log2("skipping line '%s'" % line) log1("Found %i build_ids" % len(build_ids)) log1("Found %i libs" % len(libraries)) return build_ids @@ -359,7 +361,7 @@ def build_ids_to_path(build_ids): build_id1=${build_id:0:2} build_id2=${build_id:2} file="usr/lib/debug/.build-id/$build_id1/$build_id2.debug" - """ + """ return ["/usr/lib/debug/.build-id/%s/%s.debug" % (b_id[:2], b_id[2:]) for b_id in build_ids] # beware this finds only missing libraries, but not the executable itself .. @@ -386,9 +388,7 @@ def clean_up(): try: shutil.rmtree(tmpdir) except OSError, ex: - print (_("Can't remove %(tmpdir_path)s: %(reason)s") - % {"tmpdir_path":tmpdir, "reason": ex } - ) + print _("Can't remove '%s': %s") % (tmpdir, ex) def sigterm_handler(signum, frame): clean_up() @@ -396,10 +396,11 @@ def sigterm_handler(signum, frame): def sigint_handler(signum, frame): clean_up() - print "\n", _("Exiting on user Command") + print "\n", _("Exiting on user command") exit(RETURN_OK) import signal + if __name__ == "__main__": # abrt-server can send SIGTERM to abort the download signal.signal(signal.SIGTERM, sigterm_handler) @@ -409,15 +410,14 @@ if __name__ == "__main__": cachedir = None tmpdir = None keeprpms = False - result = RETURN_OK noninteractive = False # localization init_gettext() - help_text = _("Usage: %s --core= " - "--tmpdir= " - "--cache=") % sys.argv[0] + help_text = _("Usage: %s --core=COREFILE " + "--tmpdir=TMPDIR " + "--cache=CACHEDIR") % sys.argv[0] try: opts, args = getopt.getopt(sys.argv[1:], "vyhc:", ["help", "core=", "cache=", "tmpdir=", @@ -462,13 +462,10 @@ if __name__ == "__main__": log2(missing) downloader = DebugInfoDownload(cache=cachedir, tmp=tmpdir) result = downloader.download(missing) - else: - print _("All debuginfo seems to be available") - exit(RETURN_OK) + missing = filter_installed_debuginfos(b_ids, cachedir) + for bid in missing: + print _("Missing debuginfo file: %s") % bid + exit(result) - missing = filter_installed_debuginfos(b_ids, cachedir) - for bid in missing: - log1("MISSING:%s" % bid) - - print _("Complete!") - exit(result) + print _("All debuginfo files are available") + exit(RETURN_OK) -- cgit From 58febe0ae9096e10ab9e27e125a888bd7318f22d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Feb 2011 14:29:42 +0100 Subject: gui-wizard-gtk: use fixed font for backtrace and log textviews Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-install-debuginfo.py b/src/plugins/abrt-action-install-debuginfo.py index 98cb6e7c..9253c87f 100755 --- a/src/plugins/abrt-action-install-debuginfo.py +++ b/src/plugins/abrt-action-install-debuginfo.py @@ -176,9 +176,6 @@ class DebugInfoDownload(YumBase): if not files: return - if verbose != 0 or len(files) != 0: - print _("Searching for packages for %u debuginfo files") % len(files) - if verbose == 0: # this suppress yum messages about setting up repositories mute_stdout() @@ -234,7 +231,7 @@ class DebugInfoDownload(YumBase): self.repos.setProgressBar(dnlcb) if verbose != 0 or len(not_found) != 0: - print _("Packages for %u debuginfo files were not found") % len(not_found) + print _("Can't find packages for %u debuginfo files") % len(not_found) if verbose != 0 or total_pkgs != 0: print _("Found %u packages to download") % total_pkgs print _("Downloading %.2fMb, installed size: %.2fMb") % ( @@ -457,9 +454,11 @@ if __name__ == "__main__": b_ids = extract_info_from_core(core) if b_ids == RETURN_FAILURE: exit(RETURN_FAILURE) + missing = filter_installed_debuginfos(b_ids, cachedir) if missing: log2(missing) + print _("Coredump references %u debuginfo files, %u of them are not installed") % (len(b_ids), len(missing)) downloader = DebugInfoDownload(cache=cachedir, tmp=tmpdir) result = downloader.download(missing) missing = filter_installed_debuginfos(b_ids, cachedir) @@ -467,5 +466,5 @@ if __name__ == "__main__": print _("Missing debuginfo file: %s") % bid exit(result) - print _("All debuginfo files are available") + print _("All %u debuginfo files are available") % len(b_ids) exit(RETURN_OK) -- cgit From 39ce00f37c753ae7830a8f33631de468a0ec8212 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 17:16:28 +0100 Subject: show more useful columns in abrt-gtk; use human-readable time in dir names For most users, "hostname" is the same for every crash (it is their hostname). Not every problem even has "Application" field ("low on disk space" problem, for example, doesn't), whereas any problem should have "Reason" field. For non-root, it is useful to see which dumps are in /var/spool/abrt (and aren't writable), and which are in $HOME/.abrt/spool. Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-rhtsupport.c | 2 +- src/plugins/abrt-action-upload.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/abrt-action-rhtsupport.c b/src/plugins/abrt-action-rhtsupport.c index 3ec81522..94523e08 100644 --- a/src/plugins/abrt-action-rhtsupport.c +++ b/src/plugins/abrt-action-rhtsupport.c @@ -95,7 +95,7 @@ static void report_to_rhtsupport( file = new_reportfile(); /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); + tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%s-%lu.tar.gz", iso_date_string(NULL), (long)getpid()); int pipe_from_parent_to_child[2]; xpipe(pipe_from_parent_to_child); diff --git a/src/plugins/abrt-action-upload.c b/src/plugins/abrt-action-upload.c index 6f9c5fab..88380bd7 100644 --- a/src/plugins/abrt-action-upload.c +++ b/src/plugins/abrt-action-upload.c @@ -128,7 +128,7 @@ static int create_and_upload_archive( /* Create a child gzip which will compress the data */ /* SELinux guys are not happy with /tmp, using /var/run/abrt */ - tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/upload-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL)); + tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/upload-%s-%lu.tar.gz", iso_date_string(NULL), (long)getpid()); int pipe_from_parent_to_child[2]; xpipe(pipe_from_parent_to_child); child = fork(); -- cgit