diff options
Diffstat (limited to 'src/Daemon/MiddleWare.cpp')
-rw-r--r-- | src/Daemon/MiddleWare.cpp | 194 |
1 files changed, 102 insertions, 92 deletions
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 2ccd5890..6a635642 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -20,6 +20,7 @@ */ #include "abrtlib.h" +#include "abrt_types.h" #include "Daemon.h" #include "Settings.h" #include "RPM.h" @@ -60,7 +61,7 @@ static map_analyzer_actions_and_reporters_t s_mapAnalyzerActionsAndReporters; static vector_pair_string_string_t s_vectorActionsAndReporters; -static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir); +static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir); /** @@ -69,7 +70,7 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& * @param pDebugDumpDir A debugdump dir containing all necessary data. * @param pCrashReport A created crash report. */ -static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport) +static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t& pCrashReport) { std::string fileName; std::string content; @@ -84,19 +85,22 @@ static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_r !dd.Exist(FILENAME_RELEASE) || !dd.Exist(FILENAME_EXECUTABLE)) { - throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s)'re missing."); + throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s)'re missing"); } + pCrashReport.clear(); dd.InitGetNextFile(); while (dd.GetNextFile(fileName, content, isTextFile)) { + //VERB3 log(" file:'%s' text:%d", fileName.c_str(), isTextFile); if (!isTextFile) { add_crash_data_to_crash_report(pCrashReport, fileName, CD_BIN, CD_ISNOTEDITABLE, - pDebugDumpDir + "/" + fileName); + concat_path_file(pDebugDumpDir, fileName.c_str()) + ); } else { @@ -135,8 +139,8 @@ static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_r * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return A local UUID. */ -static std::string GetLocalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir) +static std::string GetLocalUUID(const char *pAnalyzer, + const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetLocalUUID(pDebugDumpDir); @@ -148,8 +152,8 @@ static std::string GetLocalUUID(const std::string& pAnalyzer, * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return A global UUID. */ -static std::string GetGlobalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir) +static std::string GetGlobalUUID(const char *pAnalyzer, + const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetGlobalUUID(pDebugDumpDir); @@ -162,32 +166,32 @@ static std::string GetGlobalUUID(const std::string& pAnalyzer, * @param pAnalyzer A name of an analyzer plugin. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ -static void CreateReport(const std::string& pAnalyzer, - const std::string& pDebugDumpDir, +static void CreateReport(const char *pAnalyzer, + const char *pDebugDumpDir, int force) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); analyzer->CreateReport(pDebugDumpDir, force); } -mw_result_t CreateCrashReport(const std::string& pUUID, - const std::string& pUID, +mw_result_t CreateCrashReport(const char *pUUID, + const char *pUID, int force, map_crash_report_t& pCrashReport) { - VERB2 log("CreateCrashReport('%s','%s',result)", pUUID.c_str(), pUID.c_str()); + VERB2 log("CreateCrashReport('%s','%s',result)", pUUID, pUID); database_row_t row; - if (pUUID != "") + if (pUUID[0] != '\0') { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); row = database->GetUUIDData(pUUID, pUID); database->DisConnect(); } - if (pUUID == "" || row.m_sUUID != pUUID) + if (pUUID[0] == '\0' || row.m_sUUID != pUUID) { - warn_client("CreateCrashReport(): UUID '"+pUUID+"' is not in database"); + error_msg("UUID '%s' is not in database", pUUID); return MW_IN_DB_ERROR; } @@ -200,7 +204,7 @@ mw_result_t CreateCrashReport(const std::string& pUUID, std::string reproduce = "1.\n2.\n3.\n"; VERB3 log(" LoadText(FILENAME_ANALYZER,'%s')", row.m_sDebugDumpDir.c_str()); - dd.Open(row.m_sDebugDumpDir); + dd.Open(row.m_sDebugDumpDir.c_str()); dd.LoadText(FILENAME_ANALYZER, analyzer); if (dd.Exist(FILENAME_COMMENT)) { @@ -213,15 +217,15 @@ mw_result_t CreateCrashReport(const std::string& pUUID, dd.Close(); VERB3 log(" CreateReport('%s')", analyzer.c_str()); - CreateReport(analyzer, row.m_sDebugDumpDir, force); + CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force); - gUUID = GetGlobalUUID(analyzer, row.m_sDebugDumpDir); + gUUID = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" GetGlobalUUID:'%s'", gUUID.c_str()); VERB3 log(" RunAnalyzerActions"); - RunAnalyzerActions(analyzer, row.m_sDebugDumpDir); + RunAnalyzerActions(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" DebugDumpToCrashReport"); - DebugDumpToCrashReport(row.m_sDebugDumpDir, pCrashReport); + 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); @@ -232,16 +236,16 @@ mw_result_t CreateCrashReport(const std::string& pUUID, } catch (CABRTException& e) { - warn_client("CreateCrashReport(): " + e.what()); + error_msg("%s", e.what()); if (e.type() == EXCEP_DD_OPEN) { return MW_ERROR; } - else if (e.type() == EXCEP_DD_LOAD) + if (e.type() == EXCEP_DD_LOAD) { return MW_FILE_ERROR; } - else if (e.type() == EXCEP_PLUGIN) + if (e.type() == EXCEP_PLUGIN) { return MW_PLUGIN_ERROR; } @@ -251,48 +255,46 @@ mw_result_t CreateCrashReport(const std::string& pUUID, return MW_OK; } -void RunAction(const std::string& pActionDir, - const std::string& pPluginName, - const std::string& pPluginArgs) +void RunAction(const char *pActionDir, + const char *pPluginName, + const char *pPluginArgs) { try { CAction* action = g_pPluginManager->GetAction(pPluginName); - action->Run(pActionDir, pPluginArgs); } catch (CABRTException& e) { - warn_client("RunAction(): " + e.what()); - update_client("Execution of '"+pPluginName+"' was not successful: " + e.what()); + error_msg("Execution of '%s' was not successful: %s", pPluginName, e.what()); } } -void RunActionsAndReporters(const std::string& pDebugDumpDir) +void RunActionsAndReporters(const char *pDebugDumpDir) { vector_pair_string_string_t::iterator it_ar = s_vectorActionsAndReporters.begin(); + map_plugin_settings_t plugin_settings; for (; it_ar != s_vectorActionsAndReporters.end(); it_ar++) { try { - if (g_pPluginManager->GetPluginType((*it_ar).first) == REPORTER) + if (g_pPluginManager->GetPluginType(it_ar->first) == REPORTER) { - CReporter* reporter = g_pPluginManager->GetReporter((*it_ar).first); + CReporter* reporter = g_pPluginManager->GetReporter(it_ar->first); map_crash_report_t crashReport; DebugDumpToCrashReport(pDebugDumpDir, crashReport); - reporter->Report(crashReport, (*it_ar).second); + reporter->Report(crashReport, plugin_settings, it_ar->second); } - else if (g_pPluginManager->GetPluginType((*it_ar).first) == ACTION) + else if (g_pPluginManager->GetPluginType(it_ar->first) == ACTION) { - CAction* action = g_pPluginManager->GetAction((*it_ar).first); - action->Run(pDebugDumpDir, (*it_ar).second); + CAction* action = g_pPluginManager->GetAction(it_ar->first); + action->Run(pDebugDumpDir, it_ar->second.c_str()); } } catch (CABRTException& e) { - warn_client("RunActionsAndReporters(): " + e.what()); - update_client("Activation of plugin '"+(*it_ar).first+"' was not successful: " + e.what()); + error_msg("Activation of plugin '%s' was not successful: %s", it_ar->first.c_str(), e.what()); } } } @@ -312,6 +314,11 @@ static bool CheckReport(const map_crash_report_t& pCrashReport) map_crash_report_t::const_iterator it_executable = pCrashReport.find(FILENAME_EXECUTABLE); map_crash_report_t::const_iterator end = pCrashReport.end(); + + // 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 || @@ -334,7 +341,8 @@ static bool CheckReport(const map_crash_report_t& pCrashReport) } report_status_t Report(const map_crash_report_t& pCrashReport, - const std::string& pUID) + map_map_string_t& pSettings, + const char *pUID) { report_status_t ret; @@ -352,18 +360,18 @@ report_status_t Report(const map_crash_report_t& pCrashReport, // Save comments and how to reproduciton map_crash_report_t::const_iterator it_comment = pCrashReport.find(CD_COMMENT); map_crash_report_t::const_iterator it_reproduce = pCrashReport.find(CD_REPRODUCE); - std::string pDumpDir = getDebugDumpDir(UUID,UID); + std::string pDumpDir = getDebugDumpDir(UUID.c_str(), UID.c_str()); { CDebugDump dd; - dd.Open(pDumpDir); + dd.Open(pDumpDir.c_str()); if (it_comment != pCrashReport.end()) { - dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT]); + dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT].c_str()); } if (it_reproduce != pCrashReport.end()) { - dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT]); + dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT].c_str()); } } @@ -407,7 +415,8 @@ report_status_t Report(const map_crash_report_t& pCrashReport, } } #endif - std::string res = reporter->Report(pCrashReport, it_r->second); + map_plugin_settings_t plugin_settings = pSettings[pluginName]; + std::string res = reporter->Report(pCrashReport, plugin_settings, it_r->second); #if 0 /* Using ~user/.abrt/ is bad wrt security */ if (home != "") @@ -424,8 +433,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, { ret[pluginName].push_back("0"); ret[pluginName].push_back(e.what()); - warn_client("Report(): " + e.what()); - update_client("Reporting via '" + pluginName + "' was not successful: " + e.what()); + update_client("Reporting via %s' was not successful: %s", pluginName.c_str(), e.what()); } } } @@ -438,15 +446,15 @@ report_status_t Report(const map_crash_report_t& pCrashReport, return ret; } -void DeleteDebugDumpDir(const std::string& pDebugDumpDir) +void DeleteDebugDumpDir(const char *pDebugDumpDir) { CDebugDump dd; dd.Open(pDebugDumpDir); dd.Delete(); } -std::string DeleteCrashInfo(const std::string& pUUID, - const std::string& pUID) +std::string DeleteCrashInfo(const char *pUUID, + const char *pUID) { database_row_t row; CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); @@ -466,8 +474,8 @@ std::string DeleteCrashInfo(const std::string& pUUID, * @return It returns true if debugdump dir is already saved, otherwise * it returns false. */ -static bool IsDebugDumpSaved(const std::string& pUID, - const std::string& pDebugDumpDir) +static bool IsDebugDumpSaved(const char *pUID, + const char *pDebugDumpDir) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); @@ -501,19 +509,19 @@ void LoadOpenGPGPublicKey(const char* key) * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, - const std::string& pDebugDumpDir) +static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, + const char *pDebugDumpDir) { std::string package; std::string packageName; - if (pExecutable == "kernel") + if (strcmp(pExecutable, "kernel") == 0) { packageName = package = "kernel"; } else { - package = GetPackage(pExecutable.c_str()); + package = GetPackage(pExecutable); packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1)); if (packageName == "" || (g_setBlackList.find(packageName) != g_setBlackList.end())) @@ -533,7 +541,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta error_msg("package isn't signed with proper key"); return MW_GPG_ERROR; } - if (!CheckHash(packageName.c_str(), pExecutable.c_str())) + if (!CheckHash(packageName.c_str(), pExecutable)) { error_msg("executable has bad hash"); return MW_GPG_ERROR; @@ -542,19 +550,19 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta } std::string description = GetDescription(packageName.c_str()); - std::string component = GetComponent(pExecutable.c_str()); + std::string component = GetComponent(pExecutable); try { CDebugDump dd; dd.Open(pDebugDumpDir); - dd.SaveText(FILENAME_PACKAGE, package); - dd.SaveText(FILENAME_DESCRIPTION, description); - dd.SaveText(FILENAME_COMPONENT, component); + dd.SaveText(FILENAME_PACKAGE, package.c_str()); + dd.SaveText(FILENAME_DESCRIPTION, description.c_str()); + dd.SaveText(FILENAME_COMPONENT, component.c_str()); } catch (CABRTException& e) { - warn_client("SavePackageDescriptionToDebugDump(): " + e.what()); + error_msg("%s", e.what()); if (e.type() == EXCEP_DD_SAVE) { return MW_FILE_ERROR; @@ -571,7 +579,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta * @param pAnalyzer A name of an analyzer plugin. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ -static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir) +static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir) { map_analyzer_actions_and_reporters_t::iterator analyzer = s_mapAnalyzerActionsAndReporters.find(pAnalyzer); if (analyzer != s_mapAnalyzerActionsAndReporters.end()) @@ -585,13 +593,12 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& if (g_pPluginManager->GetPluginType(pluginName) == ACTION) { CAction* action = g_pPluginManager->GetAction(pluginName); - action->Run(pDebugDumpDir, it_a->second); + action->Run(pDebugDumpDir, it_a->second.c_str()); } } catch (CABRTException& e) { - warn_client("RunAnalyzerActions(): " + e.what()); - update_client("Action performed by '" + pluginName + "' was not successful: " + e.what()); + update_client("Action performed by '%s' was not successful: %s", pluginName.c_str(), e.what()); } } } @@ -608,10 +615,10 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& * @param pCrashInfo A filled crash info. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, - const std::string& pUID, - const std::string& pTime, - const std::string& pDebugDumpDir, +static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, + const char *pUID, + const char *pTime, + const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { mw_result_t res; @@ -635,8 +642,8 @@ static mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, return res; } -std::string getDebugDumpDir( const std::string& pUUID, - const std::string& pUID) +std::string getDebugDumpDir(const char *pUUID, + const char *pUID) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database_row_t row; @@ -646,13 +653,13 @@ std::string getDebugDumpDir( const std::string& pUUID, return row.m_sDebugDumpDir; } -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir) +mw_result_t SaveDebugDump(const char *pDebugDumpDir) { map_crash_info_t info; return SaveDebugDump(pDebugDumpDir, info); } -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, +mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { std::string lUUID; @@ -673,7 +680,7 @@ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, } catch (CABRTException& e) { - warn_client("SaveDebugDump(): " + e.what()); + error_msg("%s", e.what()); if (e.type() == EXCEP_DD_SAVE) { return MW_FILE_ERROR; @@ -681,24 +688,24 @@ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, return MW_ERROR; } - if (IsDebugDumpSaved(UID, pDebugDumpDir)) + if (IsDebugDumpSaved(UID.c_str(), pDebugDumpDir)) { return MW_IN_DB; } - res = SavePackageDescriptionToDebugDump(executable, pDebugDumpDir); + res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); if (res != MW_OK) { return res; } - lUUID = GetLocalUUID(analyzer, pDebugDumpDir); + lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); - return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo); + return SaveDebugDumpToDatabase(lUUID.c_str(), UID.c_str(), time.c_str(), pDebugDumpDir, pCrashInfo); } -mw_result_t GetCrashInfo(const std::string& pUUID, - const std::string& pUID, - map_crash_info_t& pCrashInfo) +mw_result_t GetCrashInfo(const char *pUUID, + const char *pUID, + map_crash_info_t& pCrashInfo) { pCrashInfo.clear(); CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); @@ -710,18 +717,20 @@ mw_result_t GetCrashInfo(const std::string& pUUID, std::string package; std::string executable; std::string description; + std::string analyzer; try { CDebugDump dd; - dd.Open(row.m_sDebugDumpDir); + 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); } catch (CABRTException& e) { - warn_client("GetCrashInfo(): " + e.what()); + error_msg("%s", e.what()); if (e.type() == EXCEP_DD_LOAD) { return MW_FILE_ERROR; @@ -738,11 +747,12 @@ mw_result_t GetCrashInfo(const std::string& pUUID, 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); return MW_OK; } -vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID) +vector_pair_string_string_t GetUUIDsOfCrash(const char *pUID) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); vector_database_rows_t rows; @@ -760,15 +770,15 @@ vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID) return UUIDsUIDs; } -void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, - const std::string& pAnalyzerOrReporter, - const std::string& pArgs) +void AddAnalyzerActionOrReporter(const char *pAnalyzer, + const char *pAnalyzerOrReporter, + const char *pArgs) { - s_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(pAnalyzerOrReporter, pArgs)); + s_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(std::string(pAnalyzerOrReporter), std::string(pArgs))); } -void AddActionOrReporter(const std::string& pActionOrReporter, - const std::string& pArgs) +void AddActionOrReporter(const char *pActionOrReporter, + const char *pArgs) { - s_vectorActionsAndReporters.push_back(make_pair(pActionOrReporter, pArgs)); + s_vectorActionsAndReporters.push_back(make_pair(std::string(pActionOrReporter), std::string(pArgs))); } |