diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-05-12 15:55:34 +0200 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-05-12 15:55:34 +0200 |
| commit | b6bc6d13eed2f346414d731ecb29579a719556f3 (patch) | |
| tree | b429d87c2dc7a7b97e2ee4fe19a2e1c1a5b1180d /lib | |
| parent | f92d9b70a2cb12451f2df00a5a2f9a47e2b9c5ce (diff) | |
| parent | 6b77cb82cb7b918660435effb0fe356401bfdd55 (diff) | |
| download | abrt-b6bc6d13eed2f346414d731ecb29579a719556f3.tar.gz abrt-b6bc6d13eed2f346414d731ecb29579a719556f3.tar.xz abrt-b6bc6d13eed2f346414d731ecb29579a719556f3.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Conflicts:
src/Daemon/Daemon.cpp
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/MiddleWare/Action.h | 2 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 111 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 29 | ||||
| -rw-r--r-- | lib/Plugins/CCpp.cpp | 2 | ||||
| -rw-r--r-- | lib/Plugins/Kerneloops.cpp | 178 | ||||
| -rw-r--r-- | lib/Plugins/Kerneloops.h | 13 | ||||
| -rw-r--r-- | lib/Plugins/KerneloopsScanner.conf (renamed from lib/Plugins/Kerneloops.conf) | 2 | ||||
| -rw-r--r-- | lib/Plugins/KerneloopsScanner.cpp | 159 | ||||
| -rw-r--r-- | lib/Plugins/KerneloopsScanner.h | 38 | ||||
| -rw-r--r-- | lib/Plugins/Makefile.am | 16 | ||||
| -rw-r--r-- | lib/Plugins/RunApp.cpp | 4 | ||||
| -rw-r--r-- | lib/Plugins/RunApp.h | 2 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 2 |
13 files changed, 309 insertions, 249 deletions
diff --git a/lib/MiddleWare/Action.h b/lib/MiddleWare/Action.h index 9a2c2f1..96461f3 100644 --- a/lib/MiddleWare/Action.h +++ b/lib/MiddleWare/Action.h @@ -29,7 +29,7 @@ class CAction : public CPlugin { public: virtual ~CAction() {} - virtual void Run(const std::string& pDebugDumpDir, + virtual void Run(const std::string& pActionDir, const std::string& pArgs) = 0; }; diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 03285ee..d5e8237 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -185,24 +185,58 @@ int CMiddleWare::CreateCrashReport(const std::string& pUUID, return 1; } -void CMiddleWare::Report(const std::string& pDebugDumpDir) +void CMiddleWare::RunAction(const std::string& pActionDir, + const std::string& pPluginName, + const std::string& pPluginArgs) { - map_crash_report_t crashReport; + try + { + CAction* action = m_pPluginManager->GetAction(pPluginName); + if (action) + { + action->Run(pActionDir, pPluginArgs); + } + else + { + throw CABRTException(EXCEP_ERROR, "Plugin '"+pPluginName+"' is not registered."); + } + } + catch (CABRTException& e) + { + comm_layer_inner_warning("CMiddleWare::RunAction(): " + e.what()); + comm_layer_inner_status("Execution of '"+pPluginName+"' was not successful: " + e.what()); + } - DebugDumpToCrashReport(pDebugDumpDir, crashReport); +} - set_reporters_t::iterator it_r; - for (it_r = m_setReporters.begin(); it_r != m_setReporters.end(); it_r++) +void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir) +{ + vector_actions_and_reporters_t::iterator it_ar; + for (it_ar = m_vectorActionsAndReporters.begin(); it_ar != m_vectorActionsAndReporters.end(); it_ar++) { try { - CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first); - reporter->Report(crashReport, (*it_r).second); + CReporter* reporter = m_pPluginManager->GetReporter((*it_ar).first); + CAction* action = m_pPluginManager->GetAction((*it_ar).first); + if (reporter) + { + map_crash_report_t crashReport; + DebugDumpToCrashReport(pDebugDumpDir, crashReport); + reporter->Report(crashReport, (*it_ar).second); + } + else if (action) + { + action->Run(pDebugDumpDir, (*it_ar).second); + } + else + { + throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_ar).first+"' is not registered."); + } } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::Report(): " + e.what()); - comm_layer_inner_status("Reporting via '"+(*it_r).first+"' was not successful: " + e.what()); + comm_layer_inner_warning("CMiddleWare::RunActionsAndReporters(): " + e.what()); + comm_layer_inner_status("Reporting via '"+(*it_ar).first+"' was not successful: " + e.what()); } } } @@ -219,17 +253,24 @@ void CMiddleWare::Report(const map_crash_report_t& pCrashReport) std::string UID = pCrashReport.find(CD_MWUID)->second[CD_CONTENT]; std::string UUID = pCrashReport.find(CD_MWUUID)->second[CD_CONTENT]; - if (m_mapAnalyzerReporters.find(analyzer) != m_mapAnalyzerReporters.end()) + if (m_mapAnalyzerActionsAndReporters.find(analyzer) != m_mapAnalyzerActionsAndReporters.end()) { - set_reporters_t::iterator it_r; - for (it_r = m_mapAnalyzerReporters[analyzer].begin(); - it_r != m_mapAnalyzerReporters[analyzer].end(); + vector_actions_and_reporters_t::iterator it_r; + for (it_r = m_mapAnalyzerActionsAndReporters[analyzer].begin(); + it_r != m_mapAnalyzerActionsAndReporters[analyzer].end(); it_r++) { try { CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first); - reporter->Report(pCrashReport, (*it_r).second); + if (reporter) + { + reporter->Report(pCrashReport, (*it_r).second); + } + else + { + throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_r).first+"' is not registered."); + } } catch (CABRTException& e) { @@ -311,6 +352,7 @@ int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutabl if (packageName == "" || (m_setBlackList.find(packageName) != m_setBlackList.end())) { + comm_layer_inner_debug("Blacklisted package - deleting debug dump..."); DeleteDebugDumpDir(pDebugDumpDir); return 0; } @@ -319,6 +361,7 @@ int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutabl if (!m_RPM.CheckFingerprint(packageName) || !m_RPM.CheckHash(packageName, pExecutable)) { + comm_layer_inner_debug("Can not find package - deleting debug dump..."); DeleteDebugDumpDir(pDebugDumpDir); return 0; } @@ -338,17 +381,24 @@ int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutabl void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir) { - if (m_mapAnalyzerActions.find(pAnalyzer) != m_mapAnalyzerActions.end()) + if (m_mapAnalyzerActionsAndReporters.find(pAnalyzer) != m_mapAnalyzerActionsAndReporters.end()) { - set_pairt_strings_t::iterator it_a; - for (it_a = m_mapAnalyzerActions[pAnalyzer].begin(); - it_a != m_mapAnalyzerActions[pAnalyzer].end(); + vector_actions_and_reporters_t::iterator it_a; + for (it_a = m_mapAnalyzerActionsAndReporters[pAnalyzer].begin(); + it_a != m_mapAnalyzerActionsAndReporters[pAnalyzer].end(); it_a++) { try { CAction* action = m_pPluginManager->GetAction((*it_a).first); - action->Run(pDebugDumpDir, (*it_a).second); + if (action) + { + action->Run(pDebugDumpDir, (*it_a).second); + } + else if (m_pPluginManager->GetReporter((*it_a).first) == NULL) + { + throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_a).first+"' is not registered."); + } } catch (CABRTException& e) { @@ -374,6 +424,7 @@ int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID, database->DisConnect(); if (row.m_sReported == "1") { + comm_layer_inner_debug("Crash is already reported - deleting debug dump..."); DeleteDebugDumpDir(pDebugDumpDir); return 0; } @@ -381,6 +432,7 @@ int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID, pCrashInfo = GetCrashInfo(pUUID, pUID); if (row.m_sCount != "1") { + comm_layer_inner_debug("Crash is in database already - deleting debug dump..."); DeleteDebugDumpDir(pDebugDumpDir); return 2; } @@ -522,22 +574,15 @@ void CMiddleWare::AddBlackListedPackage(const std::string& pPackage) m_setBlackList.insert(pPackage); } -void CMiddleWare::AddAnalyzerReporter(const std::string& pAnalyzer, - const std::string& pReporter, - const std::string& pArgs) -{ - m_mapAnalyzerReporters[pAnalyzer].insert(make_pair(pReporter, pArgs)); -} - -void CMiddleWare::AddAnalyzerAction(const std::string& pAnalyzer, - const std::string& pAction, - const std::string& pArgs) +void CMiddleWare::AddAnalyzerActionOrReporter(const std::string& pAnalyzer, + const std::string& pAnalyzerOrReporter, + const std::string& pArgs) { - m_mapAnalyzerActions[pAnalyzer].insert(make_pair(pAction, pArgs)); + m_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(pAnalyzerOrReporter, pArgs)); } -void CMiddleWare::AddReporter(const std::string& pReporter, - const std::string& pArgs) +void CMiddleWare::AddActionOrReporter(const std::string& pActionOrReporter, + const std::string& pArgs) { - m_setReporters.insert(make_pair(pReporter, pArgs)); + m_vectorActionsAndReporters.push_back(make_pair(pActionOrReporter, pArgs)); } diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h index c3b47a4..cad737a 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/lib/MiddleWare/MiddleWare.h @@ -35,18 +35,16 @@ class CMiddleWare typedef set_strings_t set_blacklist_t; typedef set_strings_t set_enabled_plugins_t; - typedef std::set<pair_string_string_t> set_pairt_strings_t; - typedef std::map<std::string, set_pairt_strings_t> map_reporter_associations_t; - typedef std::map<std::string, set_pairt_strings_t> map_action_associations_t; - typedef set_pairt_strings_t set_reporters_t; + typedef std::vector<pair_string_string_t> vector_pairt_strings_t; + typedef vector_pairt_strings_t vector_actions_and_reporters_t; + typedef std::map<std::string, vector_actions_and_reporters_t> map_analyzer_actions_and_reporters_t; CPluginManager* m_pPluginManager; CRPM m_RPM; set_blacklist_t m_setBlackList; std::string m_sDatabase; - map_reporter_associations_t m_mapAnalyzerReporters; - map_action_associations_t m_mapAnalyzerActions; - set_reporters_t m_setReporters; + map_analyzer_actions_and_reporters_t m_mapAnalyzerActionsAndReporters; + vector_actions_and_reporters_t m_vectorActionsAndReporters; bool m_bOpenGPGCheck; @@ -83,7 +81,11 @@ class CMiddleWare const std::string& pUID, map_crash_report_t& pCrashReport); - void Report(const std::string& pDebugDumpDir); + void RunAction(const std::string& pActionDir, + const std::string& pPluginName, + const std::string& pPluginArgs); + void RunActionsAndReporters(const std::string& pDebugDumpDir); + void Report(const map_crash_report_t& pCrashReport); void DeleteDebugDumpDir(const std::string& pDebugDumpDir); void DeleteCrashInfo(const std::string& pUUID, @@ -100,14 +102,11 @@ class CMiddleWare void SetDatabase(const std::string& pDatabase); void AddOpenGPGPublicKey(const std::string& pKey); void AddBlackListedPackage(const std::string& pPackage); - void AddAnalyzerReporter(const std::string& pAnalyzer, - const std::string& pReporter, + void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, + const std::string& pActionOrReporter, + const std::string& pArgs); + void AddActionOrReporter(const std::string& pActionOrReporter, const std::string& pArgs); - void AddAnalyzerAction(const std::string& pAnalyzer, - const std::string& pAction, - const std::string& pArgs); - void AddReporter(const std::string& pReporter, - const std::string& pArgs); }; #endif /*MIDDLEWARE_H_*/ diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 62c1722..2561842 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -85,7 +85,7 @@ std::string CAnalyzerCCpp::CreateHash(const std::string& pInput) return ss.str(); } -#include <iostream> + void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) { comm_layer_inner_status("Installing debug infos..."); diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index c868bae..57482c0 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -25,38 +25,14 @@ */ #include "Kerneloops.h" -#include "KerneloopsSysLog.h" #include "DebugDump.h" -#include "PluginSettings.h" #include "ABRTException.h" #include "CommLayerInner.h" #include <sstream> -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <limits.h> -#include <sys/prctl.h> -#include <sys/stat.h> -#include <asm/unistd.h> -#define MAX(A,B) ((A) > (B) ? (A) : (B)) #define FILENAME_KERNELOOPS "kerneloops" -CAnalyzerKerneloops::CAnalyzerKerneloops() : - m_sSysLogFile("/var/log/messages") -{} - -void CAnalyzerKerneloops::WriteSysLog(int m_nCount) -{ - if (m_nCount > 0) { - openlog("abrt", 0, LOG_KERN); - syslog(LOG_WARNING, "Kerneloops: Reported %i kernel oopses to Abrt", m_nCount); - closelog(); - } -} - std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) { comm_layer_inner_status("Getting local/global universal unique identification..."); @@ -85,157 +61,3 @@ std::string CAnalyzerKerneloops::GetGlobalUUID(const std::string& pDebugDumpDir) { return GetLocalUUID(pDebugDumpDir); } - -void CAnalyzerKerneloops::Report() -{ - comm_layer_inner_status("Creating crash reports..."); - - CDebugDump m_pDebugDump; - char m_sPath[PATH_MAX]; - std::list<COops> m_pOopsList; - - time_t t = time(NULL); - if (((time_t) -1) == t) - { - throw CABRTException(EXCEP_PLUGIN, "CAnalyzerKerneloops::Report(): cannot get local time."); - } - - m_pOopsList = m_pSysLog.GetOopsList(); - m_pSysLog.ClearOopsList(); - while (!m_pOopsList.empty()) - { - snprintf(m_sPath, sizeof(m_sPath), "%s/kerneloops-%d-%d", DEBUG_DUMPS_DIR, t, m_pOopsList.size()); - - COops m_pOops; - m_pOops = m_pOopsList.back(); - - try - { - m_pDebugDump.Create(m_sPath); - m_pDebugDump.SaveText(FILENAME_ANALYZER, "Kerneloops"); - m_pDebugDump.SaveText(FILENAME_UID, "0"); - m_pDebugDump.SaveText(FILENAME_EXECUTABLE, "kernel"); - m_pDebugDump.SaveText(FILENAME_KERNEL, m_pOops.m_sVersion); - m_pDebugDump.SaveText(FILENAME_PACKAGE, "not_applicable"); - m_pDebugDump.SaveText(FILENAME_KERNELOOPS, m_pOops.m_sData); - m_pDebugDump.Close(); - } - catch (CABRTException& e) - { - throw CABRTException(EXCEP_PLUGIN, "CAnalyzerKerneloops::Report(): " + e.what()); - } - m_pOopsList.pop_back(); - } -} - -void CAnalyzerKerneloops::Init() -{ - /* daemonize */ - pid_t pid = fork(); - if (pid < 0) - throw CABRTException(EXCEP_PLUGIN, "CAnalyzerKerneloops::Init(): fork failed."); - - /* hack: release Init() */ - if (pid) - return; - - sched_yield(); - -#ifdef PR_SET_TIMERSLACK - /* - * Signal the kernel that we're not timing critical - */ - prctl(PR_SET_TIMERSLACK,1000*1000*1000, 0, 0, 0); -#endif - - /* we scan dmesg before /var/log/messages; dmesg is a more accurate source normally */ - ScanDmesg(); - /* during boot... don't go too fast and slow the system down */ - sleep(10); - ScanSysLogFile(m_sSysLogFile.c_str(), 1); - - while(1) { - sleep(10); - ScanDmesg(); - } -} - -void CAnalyzerKerneloops::ScanDmesg() -{ - comm_layer_inner_debug("Scanning dmesg..."); - - int m_nFoundOopses; - char *buffer; - - buffer = (char*)calloc(getpagesize()+1, 1); - - syscall(__NR_syslog, 3, buffer, getpagesize()); - m_nFoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer), 0); - free(buffer); - - if (m_nFoundOopses > 0) - Report(); -} - -void CAnalyzerKerneloops::ScanSysLogFile(const char *filename, int issyslog) -{ - comm_layer_inner_debug("Scanning syslog..."); - - char *buffer; - struct stat statb; - FILE *file; - int ret; - int m_nFoundOopses; - size_t buflen; - - memset(&statb, 0, sizeof(statb)); - - ret = stat(filename, &statb); - - if (statb.st_size < 1 || ret != 0) - return; - - /* - * in theory there's 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 1023 bytes extra. If there's - * more than that.. any oops will be in dmesg anyway. - * Do not try to allocate an absurt 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. - */ - buflen = MAX(statb.st_size+1024, 32*1024*1024); - buffer = (char*)calloc(buflen, 1); - assert(buffer != NULL); - - file = fopen(filename, "rm"); - if (!file) { - free(buffer); - return; - } - fseek(file, -buflen, SEEK_END); - ret = fread(buffer, 1, buflen-1, file); - fclose(file); - - if (ret > 0) - m_nFoundOopses = m_pSysLog.ExtractOops(buffer, buflen-1, issyslog); - free(buffer); - - if (m_nFoundOopses > 0) { - Report(); - WriteSysLog(m_nFoundOopses); - } -} - -void CAnalyzerKerneloops::LoadSettings(const std::string& pPath) -{ - map_settings_t settings; - plugin_load_settings(pPath, settings); - - if (settings.find("SysLogFile")!= settings.end()) - { - m_sSysLogFile = settings["SysLogFile"]; - } -} diff --git a/lib/Plugins/Kerneloops.h b/lib/Plugins/Kerneloops.h index 2fa9026..00b4ea0 100644 --- a/lib/Plugins/Kerneloops.h +++ b/lib/Plugins/Kerneloops.h @@ -36,28 +36,17 @@ class CAnalyzerKerneloops : public CAnalyzer { - private: - void WriteSysLog(int m_nCount); - void Report(); - std::string m_sSysLogFile; - CSysLog m_pSysLog; - public: - CAnalyzerKerneloops(); virtual ~CAnalyzerKerneloops() {} virtual std::string GetLocalUUID(const std::string& pDebugDumpDir); virtual std::string GetGlobalUUID(const std::string& pDebugDumpDir); - virtual void Init(); virtual void CreateReport(const std::string& pDebugDumpDir) {} - virtual void LoadSettings(const std::string& pPath); - void ScanDmesg(); - void ScanSysLogFile(const char *filename, int issyslog); }; PLUGIN_INFO(ANALYZER, CAnalyzerKerneloops, "Kerneloops", - "0.0.1", + "0.0.2", "Abrt's Kerneloops plugin.", "anton@redhat.com", "https://people.redhat.com/aarapov"); diff --git a/lib/Plugins/Kerneloops.conf b/lib/Plugins/KerneloopsScanner.conf index 0022711..36aac09 100644 --- a/lib/Plugins/Kerneloops.conf +++ b/lib/Plugins/KerneloopsScanner.conf @@ -1,4 +1,4 @@ -# Kerneloops configuration. +# Kerneloops Scanner configuration. ################################################################################ SysLogFile = /var/log/messages diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp new file mode 100644 index 0000000..05e2a18 --- /dev/null +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -0,0 +1,159 @@ +#include "KerneloopsScanner.h" +#include "DebugDump.h" +#include "ABRTException.h" +#include "CommLayerInner.h" +#include "PluginSettings.h" + +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include <sys/stat.h> +#include <asm/unistd.h> + + +#define MAX(A,B) ((A) > (B) ? (A) : (B)) +#define FILENAME_KERNELOOPS "kerneloops" + +void CKerneloopsScanner::WriteSysLog(int m_nCount) +{ + if (m_nCount > 0) { + openlog("abrt", 0, LOG_KERN); + syslog(LOG_WARNING, "Kerneloops: Reported %i kernel oopses to Abrt", m_nCount); + closelog(); + } +} + +void CKerneloopsScanner::Run(const std::string& pActionDir, + const std::string& pArgs) +{ + ScanDmesg(); + if (!m_bSysLogFileScanned) + { + ScanSysLogFile(m_sSysLogFile.c_str(), 1); + m_bSysLogFileScanned = true; + } +} + +void CKerneloopsScanner::SaveOopsToDebugDump() +{ + comm_layer_inner_status("Creating kernel oops crash reports..."); + + CDebugDump m_pDebugDump; + char m_sPath[PATH_MAX]; + std::list<COops> m_pOopsList; + + time_t t = time(NULL); + if (((time_t) -1) == t) + { + throw CABRTException(EXCEP_PLUGIN, "CAnalyzerKerneloops::Report(): cannot get local time."); + } + + m_pOopsList = m_pSysLog.GetOopsList(); + m_pSysLog.ClearOopsList(); + while (!m_pOopsList.empty()) + { + snprintf(m_sPath, sizeof(m_sPath), "%s/kerneloops-%d-%d", DEBUG_DUMPS_DIR, t, m_pOopsList.size()); + + COops m_pOops; + m_pOops = m_pOopsList.back(); + + try + { + m_pDebugDump.Create(m_sPath); + m_pDebugDump.SaveText(FILENAME_ANALYZER, "Kerneloops"); + m_pDebugDump.SaveText(FILENAME_UID, "0"); + m_pDebugDump.SaveText(FILENAME_EXECUTABLE, "kernel"); + m_pDebugDump.SaveText(FILENAME_KERNEL, m_pOops.m_sVersion); + m_pDebugDump.SaveText(FILENAME_PACKAGE, "not_applicable"); + m_pDebugDump.SaveText(FILENAME_KERNELOOPS, m_pOops.m_sData); + m_pDebugDump.Close(); + } + catch (CABRTException& e) + { + throw CABRTException(EXCEP_PLUGIN, "CAnalyzerKerneloops::Report(): " + e.what()); + } + m_pOopsList.pop_back(); + } +} + + +void CKerneloopsScanner::ScanDmesg() +{ + comm_layer_inner_debug("Scanning dmesg..."); + + int m_nFoundOopses; + char *buffer; + + buffer = (char*)calloc(getpagesize()+1, 1); + + syscall(__NR_syslog, 3, buffer, getpagesize()); + m_nFoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer), 0); + free(buffer); + + if (m_nFoundOopses > 0) + SaveOopsToDebugDump(); +} + +void CKerneloopsScanner::ScanSysLogFile(const char *filename, int issyslog) +{ + comm_layer_inner_debug("Scanning syslog..."); + + char *buffer; + struct stat statb; + FILE *file; + int ret; + int m_nFoundOopses; + size_t buflen; + + memset(&statb, 0, sizeof(statb)); + + ret = stat(filename, &statb); + + if (statb.st_size < 1 || ret != 0) + return; + + /* + * in theory there's 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 1023 bytes extra. If there's + * more than that.. any oops will be in dmesg anyway. + * Do not try to allocate an absurt 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. + */ + buflen = MAX(statb.st_size+1024, 32*1024*1024); + buffer = (char*)calloc(buflen, 1); + assert(buffer != NULL); + + file = fopen(filename, "rm"); + if (!file) { + free(buffer); + return; + } + fseek(file, -buflen, SEEK_END); + ret = fread(buffer, 1, buflen-1, file); + fclose(file); + + if (ret > 0) + m_nFoundOopses = m_pSysLog.ExtractOops(buffer, buflen-1, issyslog); + free(buffer); + + if (m_nFoundOopses > 0) { + SaveOopsToDebugDump(); + WriteSysLog(m_nFoundOopses); + } +} + +void CKerneloopsScanner::LoadSettings(const std::string& pPath) +{ + map_settings_t settings; + plugin_load_settings(pPath, settings); + + if (settings.find("SysLogFile")!= settings.end()) + { + m_sSysLogFile = settings["SysLogFile"]; + } +} diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h new file mode 100644 index 0000000..f823d1f --- /dev/null +++ b/lib/Plugins/KerneloopsScanner.h @@ -0,0 +1,38 @@ +#ifndef KERNELOOPSSCANNER_H_ +#define KERNELOOPSSCANNER_H_ + +#include "KerneloopsSysLog.h" +#include "Plugin.h" +#include "Action.h" + +class CKerneloopsScanner : public CAction +{ + private: + std::string m_sSysLogFile; + CSysLog m_pSysLog; + bool m_bSysLogFileScanned; + + void SaveOopsToDebugDump(); + void ScanDmesg(); + void ScanSysLogFile(const char *filename, int issyslog); + void WriteSysLog(int m_nCount); + public: + CKerneloopsScanner() : + m_sSysLogFile("/var/log/messages"), + m_bSysLogFileScanned(false) + {} + virtual ~CKerneloopsScanner() {} + virtual void Run(const std::string& pActionDir, + const std::string& pArgs); + virtual void LoadSettings(const std::string& pPath); +}; + +PLUGIN_INFO(ACTION, + CKerneloopsScanner, + "KerneloopsScanner", + "0.0.1", + "Save new Kerneloops crashes into debug dump dir", + "anton@redhat.com", + "http://people.redhat.com/aarapov"); + +#endif /* KERNELOOPSSCANNER_H_ */ diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 396b205..51436f7 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -4,6 +4,7 @@ pluginslib_LTLIBRARIES = libCCpp.la \ libMailx.la \ libSQLite3.la \ libLogger.la \ + libKerneloopsScanner.la\ libKerneloopsReporter.la\ libKerneloops.la \ libRunApp.la \ @@ -11,7 +12,7 @@ pluginslib_LTLIBRARIES = libCCpp.la \ libPython.la pluginsconfdir=$(PLUGINS_CONF_DIR) -dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf Kerneloops.conf KerneloopsReporter.conf Bugzilla.conf +dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf KerneloopsScanner.conf KerneloopsReporter.conf Bugzilla.conf # CCpp libCCpp_la_SOURCES = CCpp.cpp CCpp.h PluginSettings.h @@ -20,9 +21,9 @@ libCCpp_la_LIBADD = $(NSS_LIBS) libCCpp_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) # Kerneloops -libKerneloops_la_SOURCES = Kerneloops.cpp Kerneloops.h KerneloopsSysLog.cpp KerneloopsSysLog.h PluginSettings.h +libKerneloops_la_SOURCES = Kerneloops.cpp Kerneloops.h libKerneloops_la_LDFLAGS = -avoid-version -libKerneloops_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" -DCCPP_HOOK_PATH=\"${libexecdir}/hookKerneloopsoops\" +libKerneloops_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils # KerneloopsReporter libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h PluginSettings.h @@ -30,6 +31,11 @@ libKerneloopsReporter_la_LDFLAGS = -avoid-version libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare $(CURL_CFLAGS) +# KerneloopsScanner +libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h PluginSettings.h +libKerneloopsScanner_la_LDFLAGS = -avoid-version +libKerneloopsScanner_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" + # Mailx libMailx_la_SOURCES = Mailx.cpp Mailx.h PluginSettings.h libMailx_la_LDFLAGS = -avoid-version @@ -50,9 +56,9 @@ libRunApp_la_LDFLAGS = -avoid-version # Bugzilla libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp -libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) +libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) $(NSS_LIBS) libBugzilla_la_LDFLAGS = -avoid-version -libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils # Python libPython_la_SOURCES = Python.h Python.cpp diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp index 4f9d21d..9d996ee 100644 --- a/lib/Plugins/RunApp.cpp +++ b/lib/Plugins/RunApp.cpp @@ -56,7 +56,7 @@ void CActionRunApp::ParseArgs(const std::string& psArgs, vector_args_t& pArgs) } } -void CActionRunApp::Run(const std::string& pDebugDumpDir, +void CActionRunApp::Run(const std::string& pActionDir, const std::string& pArgs) { comm_layer_inner_status("Executing RunApp plugin..."); @@ -82,7 +82,7 @@ void CActionRunApp::Run(const std::string& pDebugDumpDir, if (args.size() > 1) { CDebugDump dd; - dd.Open(pDebugDumpDir); + dd.Open(pActionDir); dd.SaveText(args[FILENAME], output); dd.Close(); } diff --git a/lib/Plugins/RunApp.h b/lib/Plugins/RunApp.h index 1ffd00a..bbefc0a 100644 --- a/lib/Plugins/RunApp.h +++ b/lib/Plugins/RunApp.h @@ -34,7 +34,7 @@ class CActionRunApp : public CAction public: virtual ~CActionRunApp() {} - virtual void Run(const std::string& pDebugDumpDir, + virtual void Run(const std::string& pActionDir, const std::string& pArgs); }; diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 73fdeb6..23c1fbd 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -35,6 +35,8 @@ #define FILENAME_ANALYZER "analyzer" #define FILENAME_RELEASE "release" #define FILENAME_EXECUTABLE "executable" +#define FILENAME_REASON "reason" + class CDebugDump { |
