diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2010-01-21 21:20:33 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2010-01-21 21:20:33 +0100 |
| commit | ce57d1299f6dadecb36c597e35c00de79d00c5f4 (patch) | |
| tree | 0a900704b79558b4f1683debc9b36fd62b2f2c5b /src/Daemon/MiddleWare.cpp | |
| parent | f750288769b23497ad5b57b1c50f683402c509f6 (diff) | |
| parent | 4b54f9866f0dbdc859e300b0169b6ef504ee6c12 (diff) | |
| download | abrt-ce57d1299f6dadecb36c597e35c00de79d00c5f4.tar.gz abrt-ce57d1299f6dadecb36c597e35c00de79d00c5f4.tar.xz abrt-ce57d1299f6dadecb36c597e35c00de79d00c5f4.zip | |
Merge branch 'master' into rhel6
Conflicts:
src/Daemon/abrt.conf
Diffstat (limited to 'src/Daemon/MiddleWare.cpp')
| -rw-r--r-- | src/Daemon/MiddleWare.cpp | 330 |
1 files changed, 143 insertions, 187 deletions
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index c2a122a..9abb737 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -85,8 +85,8 @@ static char* is_text_file(const char *name, ssize_t *sz) } /* Some files in our dump directories are known to always be textual */ - if (strcmp(name, "backtrace") == 0 - || strcmp(name, "cmdline") == 0 + if (strcmp(name, FILENAME_BACKTRACE) == 0 + || strcmp(name, FILENAME_CMDLINE) == 0 ) { return buf; } @@ -120,29 +120,11 @@ static char* is_text_file(const char *name, ssize_t *sz) return NULL; /* it's binary */ } -/** - * Transforms a debugdump direcortry to inner crash - * report form. This form is used for later reporting. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @param pCrashReport A created crash report. - */ -static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t& pCrashReport) +static void load_crash_data_from_debug_dump(CDebugDump& dd, map_crash_data_t& data) { - CDebugDump dd; - dd.Open(pDebugDumpDir); - if (!dd.Exist(FILENAME_ARCHITECTURE) - || !dd.Exist(FILENAME_KERNEL) - || !dd.Exist(FILENAME_PACKAGE) - || !dd.Exist(FILENAME_COMPONENT) - || !dd.Exist(FILENAME_RELEASE) - || !dd.Exist(FILENAME_EXECUTABLE) - ) { - throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s) are missing"); - } - std::string short_name; std::string full_name; - pCrashReport.clear(); + dd.InitGetNextFile(); while (dd.GetNextFile(&short_name, &full_name)) { @@ -150,11 +132,11 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t char *text = is_text_file(full_name.c_str(), &sz); if (!text) { - add_crash_data_to_crash_report(pCrashReport, - short_name, - CD_BIN, - CD_ISNOTEDITABLE, - full_name + add_to_crash_data_ext(data, + short_name.c_str(), + CD_BIN, + CD_ISNOTEDITABLE, + full_name.c_str() ); continue; } @@ -166,33 +148,39 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t dd.LoadText(short_name.c_str(), content); free(text); - if (short_name == FILENAME_ARCHITECTURE - || short_name == FILENAME_KERNEL - || short_name == FILENAME_PACKAGE - || short_name == FILENAME_COMPONENT - || short_name == FILENAME_RELEASE - || short_name == FILENAME_EXECUTABLE - ) { - add_crash_data_to_crash_report(pCrashReport, short_name, CD_TXT, CD_ISNOTEDITABLE, content); - continue; - } + add_to_crash_data_ext(data, + short_name.c_str(), + CD_TXT, + is_editable_file(short_name.c_str()) ? CD_ISEDITABLE : CD_ISNOTEDITABLE, + content.c_str() + ); + } +} - if (short_name != FILENAME_UID - && short_name != FILENAME_ANALYZER - && short_name != FILENAME_TIME - && short_name != FILENAME_DESCRIPTION - && short_name != FILENAME_REPRODUCE - && short_name != FILENAME_COMMENT - ) { - add_crash_data_to_crash_report( - pCrashReport, - short_name, - CD_TXT, - CD_ISEDITABLE, - content - ); +/** + * Transforms a debugdump directory to inner crash + * report form. This form is used for later reporting. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @param pCrashData A created crash report. + */ +static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_data_t& pCrashData) +{ + VERB3 log(" DebugDumpToCrashReport('%s')", pDebugDumpDir); + + CDebugDump dd; + dd.Open(pDebugDumpDir); + + const char *const *v = must_have_files; + while (*v) + { + if (!dd.Exist(*v)) + { + throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): important file '%s' is missing", *v); } + v++; } + + load_crash_data_from_debug_dump(dd, pCrashData); } /** @@ -235,7 +223,7 @@ static std::string GetGlobalUUID(const char *pAnalyzer, * @param pAnalyzer A name of an analyzer plugin. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ -static void CreateReport(const char *pAnalyzer, +static void run_analyser_CreateReport(const char *pAnalyzer, const char *pDebugDumpDir, int force) { @@ -250,7 +238,7 @@ static void CreateReport(const char *pAnalyzer, mw_result_t CreateCrashReport(const char *pUUID, const char *pUID, int force, - map_crash_report_t& pCrashReport) + map_crash_data_t& pCrashData) { VERB2 log("CreateCrashReport('%s','%s',result)", pUUID, pUID); @@ -268,64 +256,56 @@ mw_result_t CreateCrashReport(const char *pUUID, return MW_IN_DB_ERROR; } + mw_result_t r = MW_OK; try { - CDebugDump dd; - std::string analyzer; - std::string gUUID; - std::string comment; - std::string reproduce = "1.\n2.\n3.\n"; - - VERB3 log(" LoadText(FILENAME_ANALYZER,'%s')", row.m_sDebugDumpDir.c_str()); - dd.Open(row.m_sDebugDumpDir.c_str()); - dd.LoadText(FILENAME_ANALYZER, analyzer); - if (dd.Exist(FILENAME_COMMENT)) - { - dd.LoadText(FILENAME_COMMENT, comment); - } - if (dd.Exist(FILENAME_REPRODUCE)) { - dd.LoadText(FILENAME_REPRODUCE, reproduce); + CDebugDump dd; + dd.Open(row.m_sDebugDumpDir.c_str()); + load_crash_data_from_debug_dump(dd, pCrashData); } - dd.Close(); - VERB3 log(" CreateReport('%s')", analyzer.c_str()); - CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force); + std::string analyzer = get_crash_data_item_content(pCrashData, FILENAME_ANALYZER); - gUUID = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); - VERB3 log(" GetGlobalUUID:'%s'", gUUID.c_str()); + // TODO: explain what run_analyser_CreateReport and RunAnalyzerActions are expected to do. + // Do they potentially add more files to dump dir? + // Why we calculate dup_hash after run_analyser_CreateReport but before RunAnalyzerActions? + // Why do we reload dump dir's data via DebugDumpToCrashReport? - VERB3 log(" RunAnalyzerActions"); + VERB3 log(" run_analyser_CreateReport('%s')", analyzer.c_str()); + run_analyser_CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force); + + std::string dup_hash = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); + VERB3 log(" DUPHASH:'%s'", dup_hash.c_str()); + + VERB3 log(" RunAnalyzerActions('%s','%s')", analyzer.c_str(), row.m_sDebugDumpDir.c_str()); RunAnalyzerActions(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); - VERB3 log(" DebugDumpToCrashReport"); - DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashReport); - add_crash_data_to_crash_report(pCrashReport, CD_UUID, CD_TXT, CD_ISNOTEDITABLE, gUUID); - add_crash_data_to_crash_report(pCrashReport, CD_MWANALYZER, CD_SYS, CD_ISNOTEDITABLE, analyzer); - add_crash_data_to_crash_report(pCrashReport, CD_MWUID, CD_SYS, CD_ISNOTEDITABLE, pUID); - add_crash_data_to_crash_report(pCrashReport, CD_MWUUID, CD_SYS, CD_ISNOTEDITABLE, pUUID); - add_crash_data_to_crash_report(pCrashReport, CD_COMMENT, CD_TXT, CD_ISEDITABLE, comment); - add_crash_data_to_crash_report(pCrashReport, CD_REPRODUCE, CD_TXT, CD_ISEDITABLE, reproduce); + DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashData); + + add_to_crash_data_ext(pCrashData, CD_DUPHASH, CD_TXT, CD_ISNOTEDITABLE, dup_hash.c_str()); + add_to_crash_data_ext(pCrashData, CD_UUID , CD_SYS, CD_ISNOTEDITABLE, pUUID); } catch (CABRTException& e) { + r = MW_CORRUPTED; error_msg("%s", e.what()); if (e.type() == EXCEP_DD_OPEN) { - return MW_ERROR; + r = MW_ERROR; } - if (e.type() == EXCEP_DD_LOAD) + else if (e.type() == EXCEP_DD_LOAD) { - return MW_FILE_ERROR; + r = MW_FILE_ERROR; } - if (e.type() == EXCEP_PLUGIN) + else if (e.type() == EXCEP_PLUGIN) { - return MW_PLUGIN_ERROR; + r = MW_PLUGIN_ERROR; } - return MW_CORRUPTED; } - return MW_OK; + VERB3 log("CreateCrashReport() returns %d", r); + return r; } void RunAction(const char *pActionDir, @@ -362,7 +342,7 @@ void RunActionsAndReporters(const char *pDebugDumpDir) if (tp == REPORTER) { CReporter* reporter = g_pPluginManager->GetReporter(plugin_name); /* can't be NULL */ - map_crash_report_t crashReport; + map_crash_data_t crashReport; DebugDumpToCrashReport(pDebugDumpDir, crashReport); VERB2 log("%s.Report(...)", plugin_name); reporter->Report(crashReport, plugin_settings, it_ar->second.c_str()); @@ -382,88 +362,70 @@ void RunActionsAndReporters(const char *pDebugDumpDir) } -static bool CheckReport(const map_crash_report_t& pCrashReport) -{ - map_crash_report_t::const_iterator it_analyzer = pCrashReport.find(CD_MWANALYZER); - map_crash_report_t::const_iterator it_mwuid = pCrashReport.find(CD_MWUID); - map_crash_report_t::const_iterator it_mwuuid = pCrashReport.find(CD_MWUUID); - - map_crash_report_t::const_iterator it_package = pCrashReport.find(FILENAME_PACKAGE); - map_crash_report_t::const_iterator it_architecture = pCrashReport.find(FILENAME_ARCHITECTURE); - map_crash_report_t::const_iterator it_kernel = pCrashReport.find(FILENAME_KERNEL); - map_crash_report_t::const_iterator it_component = pCrashReport.find(FILENAME_COMPONENT); - map_crash_report_t::const_iterator it_release = pCrashReport.find(FILENAME_RELEASE); - map_crash_report_t::const_iterator it_executable = pCrashReport.find(FILENAME_EXECUTABLE); - - map_crash_report_t::const_iterator end = pCrashReport.end(); - - if (it_package == end) - { - return false; - } - - // FIXME: bypass the test if it's kerneloops - if (it_package->second[CD_CONTENT] == "kernel") - return true; - - if (it_analyzer == end || it_mwuid == end || - it_mwuuid == end || /* it_package == end || */ - it_architecture == end || it_kernel == end || - it_component == end || it_release == end || - it_executable == end) - { - return false; - } - - if (it_analyzer->second[CD_CONTENT] == "" || it_mwuid->second[CD_CONTENT] == "" || - it_mwuuid->second[CD_CONTENT] == "" || it_package->second[CD_CONTENT] == "" || - it_architecture->second[CD_CONTENT] == "" || it_kernel->second[CD_CONTENT] == "" || - it_component->second[CD_CONTENT] == "" || it_release->second[CD_CONTENT] == "" || - it_executable->second[CD_CONTENT] == "") - { - return false; - } - - return true; -} - -report_status_t Report(const map_crash_report_t& pCrashReport, +// We must not trust client_report here! +// dbus handler passes it from user without checking +report_status_t Report(const map_crash_data_t& client_report, map_map_string_t& pSettings, const char *pUID) { - report_status_t ret; - - /* dbus handler passes pCrashReport from user without checking it */ - - if (!CheckReport(pCrashReport)) - { - throw CABRTException(EXCEP_ERROR, "Report(): Some of mandatory report data are missing."); - } - - std::string analyzer = pCrashReport.find(CD_MWANALYZER)->second[CD_CONTENT]; - std::string UID = pCrashReport.find(CD_MWUID)->second[CD_CONTENT]; - std::string UUID = pCrashReport.find(CD_MWUUID)->second[CD_CONTENT]; - std::string packageNVR = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; - std::string packageName = packageNVR.substr(0, packageNVR.rfind("-", packageNVR.rfind("-") - 1)); - - // Save comment and "how to reproduce" - map_crash_report_t::const_iterator it_comment = pCrashReport.find(CD_COMMENT); - map_crash_report_t::const_iterator it_reproduce = pCrashReport.find(CD_REPRODUCE); - if (it_comment != pCrashReport.end() || it_reproduce != pCrashReport.end()) + // Get ID fields + const char *UID = get_crash_data_item_content_or_NULL(client_report, FILENAME_UID); + const char *UUID = get_crash_data_item_content_or_NULL(client_report, CD_UUID); + if (!UID || !UUID) { + throw CABRTException(EXCEP_ERROR, "Report(): UID or UUID is missing in client's report data"); + } + + // Retrieve corresponding stored record + map_crash_data_t stored_report; + mw_result_t r = FillCrashInfo(UUID, UID, stored_report); + if (r != MW_OK) + return report_status_t(); + const std::string& pDumpDir = get_crash_data_item_content(stored_report, CD_DUMPDIR); + + // Save comment, "how to reproduce", backtrace + const char *comment = get_crash_data_item_content_or_NULL(client_report, FILENAME_COMMENT); + const char *reproduce = get_crash_data_item_content_or_NULL(client_report, FILENAME_REPRODUCE); + const char *backtrace = get_crash_data_item_content_or_NULL(client_report, FILENAME_BACKTRACE); + if (comment || reproduce || backtrace) { - std::string pDumpDir = getDebugDumpDir(UUID.c_str(), UID.c_str()); CDebugDump dd; dd.Open(pDumpDir.c_str()); - if (it_comment != pCrashReport.end()) + if (comment) + { + dd.SaveText(FILENAME_COMMENT, comment); + add_to_crash_data_ext(stored_report, FILENAME_COMMENT, CD_TXT, CD_ISEDITABLE, comment); + } + if (reproduce) { - dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT].c_str()); + dd.SaveText(FILENAME_REPRODUCE, reproduce); + add_to_crash_data_ext(stored_report, FILENAME_REPRODUCE, CD_TXT, CD_ISEDITABLE, reproduce); } - if (it_reproduce != pCrashReport.end()) + if (backtrace) { - dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT].c_str()); + dd.SaveText(FILENAME_BACKTRACE, backtrace); + add_to_crash_data_ext(stored_report, FILENAME_BACKTRACE, CD_TXT, CD_ISEDITABLE, backtrace); } } + const std::string& analyzer = get_crash_data_item_content(stored_report, FILENAME_ANALYZER); + + std::string dup_hash = GetGlobalUUID(analyzer.c_str(), pDumpDir.c_str()); + VERB3 log(" DUPHASH:'%s'", dup_hash.c_str()); + add_to_crash_data_ext(stored_report, CD_DUPHASH, CD_TXT, CD_ISNOTEDITABLE, dup_hash.c_str()); + + // Run reporters + + VERB3 { + log("Run reporters"); + log_map_crash_data(client_report, " client_report"); + log_map_crash_data(stored_report, " stored_report"); + } +#define client_report client_report_must_not_be_used_below + + map_crash_data_t::const_iterator its_PACKAGE = stored_report.find(FILENAME_PACKAGE); + std::string packageNVR = its_PACKAGE->second[CD_CONTENT]; + std::string packageName = packageNVR.substr(0, packageNVR.rfind("-", packageNVR.rfind("-") - 1)); + // analyzer with package name (CCpp:xorg-x11-app) has higher priority std::string key = analyzer + ":" + packageName; map_analyzer_actions_and_reporters_t::iterator end = s_mapAnalyzerActionsAndReporters.end(); @@ -475,6 +437,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, key = analyzer; } + report_status_t ret; std::string message; if (keyPtr != end) { @@ -509,7 +472,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, } #endif map_plugin_settings_t plugin_settings = pSettings[plugin_name]; - std::string res = reporter->Report(pCrashReport, plugin_settings, it_r->second.c_str()); + std::string res = reporter->Report(stored_report, plugin_settings, it_r->second.c_str()); #if 0 /* Using ~user/.abrt/ is bad wrt security */ if (home != "") @@ -535,10 +498,11 @@ report_status_t Report(const map_crash_report_t& pCrashReport, CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); - database->SetReported(UUID.c_str(), UID.c_str(), message.c_str()); + database->SetReported(UUID, UID, message.c_str()); database->DisConnect(); return ret; +#undef client_report } /** @@ -767,7 +731,7 @@ bool analyzer_has_AutoReportUIDs(const char *analyzer_name, const char* uid) return false; } -void autoreport(const pair_string_string_t& reporter_options, const map_crash_report_t& crash_report) +void autoreport(const pair_string_string_t& reporter_options, const map_crash_data_t& crash_report) { CReporter* reporter = g_pPluginManager->GetReporter(reporter_options.first.c_str()); if (!reporter) @@ -821,14 +785,14 @@ static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir) * @param pUID An UID of an user. * @param pTime Time when a crash occurs. * @param pDebugDumpPath A debugdump path. - * @param pCrashInfo A filled crash info. + * @param pCrashData A filled crash info. * @return It return results of operation. See mw_result_t. */ static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, const char *pUID, const char *pTime, const char *pDebugDumpDir, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); @@ -837,7 +801,7 @@ static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, database_row_t row = database->GetRow(pUUID, pUID); database->DisConnect(); - mw_result_t res = FillCrashInfo(pUUID, pUID, pCrashInfo); + mw_result_t res = FillCrashInfo(pUUID, pUID, pCrashData); if (res == MW_OK) { if (row.m_sReported == "1") @@ -854,8 +818,7 @@ static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, return res; } -std::string getDebugDumpDir(const char *pUUID, - const char *pUID) +std::string getDebugDumpDir(const char *pUUID, const char *pUID) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); @@ -865,7 +828,7 @@ std::string getDebugDumpDir(const char *pUUID, } mw_result_t SaveDebugDump(const char *pDebugDumpDir, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { std::string UID; std::string time; @@ -907,12 +870,12 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" : UID.c_str(); - return SaveDebugDumpToDatabase(lUUID.c_str(), uid_str, time.c_str(), pDebugDumpDir, pCrashInfo); + return SaveDebugDumpToDatabase(lUUID.c_str(), uid_str, time.c_str(), pDebugDumpDir, pCrashData); } mw_result_t FillCrashInfo(const char *pUUID, const char *pUID, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); @@ -927,10 +890,7 @@ mw_result_t FillCrashInfo(const char *pUUID, { CDebugDump dd; dd.Open(row.m_sDebugDumpDir.c_str()); - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(FILENAME_PACKAGE, package); - dd.LoadText(FILENAME_DESCRIPTION, description); - dd.LoadText(FILENAME_ANALYZER, analyzer); + load_crash_data_from_debug_dump(dd, pCrashData); } catch (CABRTException& e) { @@ -938,18 +898,14 @@ mw_result_t FillCrashInfo(const char *pUUID, return MW_ERROR; } - pCrashInfo.clear(); - add_crash_data_to_crash_info(pCrashInfo, CD_EXECUTABLE, executable); - add_crash_data_to_crash_info(pCrashInfo, CD_PACKAGE, package); - add_crash_data_to_crash_info(pCrashInfo, CD_DESCRIPTION, description); - add_crash_data_to_crash_info(pCrashInfo, CD_UUID, row.m_sUUID); - add_crash_data_to_crash_info(pCrashInfo, CD_UID, row.m_sUID); - add_crash_data_to_crash_info(pCrashInfo, CD_COUNT, row.m_sCount); - add_crash_data_to_crash_info(pCrashInfo, CD_TIME, row.m_sTime); - add_crash_data_to_crash_info(pCrashInfo, CD_REPORTED, row.m_sReported); - add_crash_data_to_crash_info(pCrashInfo, CD_MESSAGE, row.m_sMessage); - add_crash_data_to_crash_info(pCrashInfo, CD_MWDDD, row.m_sDebugDumpDir); - add_crash_data_to_crash_info(pCrashInfo, CD_MWANALYZER, analyzer); + add_to_crash_data(pCrashData, CD_UUID , row.m_sUUID.c_str() ); + add_to_crash_data(pCrashData, CD_COUNT , row.m_sCount.c_str() ); + add_to_crash_data(pCrashData, CD_REPORTED , row.m_sReported.c_str() ); + add_to_crash_data(pCrashData, CD_MESSAGE , row.m_sMessage.c_str() ); + add_to_crash_data(pCrashData, CD_DUMPDIR , row.m_sDebugDumpDir.c_str()); +//TODO: why do we keep uid and time in DB and in dumpdir?! + add_to_crash_data(pCrashData, FILENAME_UID , row.m_sUID.c_str() ); + add_to_crash_data(pCrashData, FILENAME_TIME , row.m_sTime.c_str() ); return MW_OK; } |
