diff options
| author | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-05-12 14:02:23 +0200 |
|---|---|---|
| committer | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-05-12 14:02:23 +0200 |
| commit | 132e3403a62e47df970241c289f718e5ca2ece97 (patch) | |
| tree | 78d130f75feac1c176ccc4201e1e2a6d92e661a9 | |
| parent | 7d0eaab97308c65d0da2db0a0d2f5710ce36e2fe (diff) | |
| download | abrt-132e3403a62e47df970241c289f718e5ca2ece97.tar.gz abrt-132e3403a62e47df970241c289f718e5ca2ece97.tar.xz abrt-132e3403a62e47df970241c289f718e5ca2ece97.zip | |
support for simpler settings
| -rw-r--r-- | lib/MiddleWare/Action.h | 2 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 107 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 29 | ||||
| -rw-r--r-- | lib/Plugins/CCpp.cpp | 2 | ||||
| -rw-r--r-- | lib/Plugins/RunApp.cpp | 4 | ||||
| -rw-r--r-- | lib/Plugins/RunApp.h | 2 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 2 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 162 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.h | 26 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 2 | ||||
| -rw-r--r-- | src/Daemon/Settings.cpp | 91 | ||||
| -rw-r--r-- | src/Daemon/Settings.h | 31 | ||||
| -rw-r--r-- | src/Daemon/abrt.conf | 16 |
13 files changed, 344 insertions, 132 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..3c8ed4a 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) { @@ -338,17 +379,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) { @@ -522,22 +570,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/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 { diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 2a2f05b..3525571 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -82,7 +82,7 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, { if(cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo)) { - cc->m_pMW->Report(crashinfo[CD_MWDDD][CD_CONTENT]); + cc->m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); /* send message to dbus */ cc->m_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT]); } @@ -111,6 +111,49 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, return TRUE; } +gboolean CCrashWatcher::cron_activation_periodic_cb(gpointer data) +{ + cron_callback_data_t* cronPeriodicCallbackData = static_cast<cron_callback_data_t*>(data); + std::cerr << "Activating plugin: " << cronPeriodicCallbackData->m_sPluginName << std::endl; + cronPeriodicCallbackData->m_pCrashWatcher->m_pMW->RunAction(cronPeriodicCallbackData->m_pCrashWatcher->m_sTarget, + cronPeriodicCallbackData->m_sPluginName, + cronPeriodicCallbackData->m_sPluginArgs); + return TRUE; +} +gboolean CCrashWatcher::cron_activation_one_cb(gpointer data) +{ + cron_callback_data_t* cronOneCallbackData = static_cast<cron_callback_data_t*>(data); + std::cerr << "Activating plugin: " << cronOneCallbackData->m_sPluginName << std::endl; + cronOneCallbackData->m_pCrashWatcher->m_pMW->RunAction(cronOneCallbackData->m_pCrashWatcher->m_sTarget, + cronOneCallbackData->m_sPluginName, + cronOneCallbackData->m_sPluginArgs); + return FALSE; +} +gboolean CCrashWatcher::cron_activation_reshedule_cb(gpointer data) +{ + cron_callback_data_t* cronResheduleCallbackData = static_cast<cron_callback_data_t*>(data); + std::cerr << "Rescheduling plugin: " << cronResheduleCallbackData->m_sPluginName << std::endl; + + cron_callback_data_t* cronPeriodicCallbackData = new cron_callback_data_t(cronResheduleCallbackData->m_pCrashWatcher, + cronResheduleCallbackData->m_sPluginName, + cronResheduleCallbackData->m_sPluginArgs, + cronResheduleCallbackData->m_nTimeout); + g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, + cronPeriodicCallbackData->m_nTimeout, + cron_activation_periodic_cb, + static_cast<gpointer>(cronPeriodicCallbackData), + cron_delete_callback_data_cb); + + + return FALSE; +} + +void CCrashWatcher::cron_delete_callback_data_cb(gpointer data) +{ + cron_callback_data_t* cronDeleteCallbackData = static_cast<cron_callback_data_t*>(data); + delete cronDeleteCallbackData; +} + void CCrashWatcher::SetUpMW() { m_pMW->SetOpenGPGCheck(m_pSettings->GetOpenGPGCheck()); @@ -133,30 +176,112 @@ void CCrashWatcher::SetUpMW() { m_pMW->RegisterPlugin(*it_p); } - CSettings::set_pair_strings_t reporters = m_pSettings->GetReporters(); - CSettings::set_pair_strings_t::iterator it_r; - for (it_r = reporters.begin(); it_r != reporters.end(); it_r++) + CSettings::vector_pair_strings_t actionsAndReporters = m_pSettings->GetActionsAndReporters(); + CSettings::vector_pair_strings_t::iterator it_ar; + for (it_ar = actionsAndReporters.begin(); it_ar != actionsAndReporters.end(); it_ar++) { - m_pMW->AddReporter((*it_r).first, (*it_r).second); + m_pMW->AddActionOrReporter((*it_ar).first, (*it_ar).second); } - CSettings::map_analyzer_reporters_t analyzer_reporters = m_pSettings->GetAnalyzerReporters(); - CSettings::map_analyzer_reporters_t::iterator it_pr; - for (it_pr = analyzer_reporters.begin(); it_pr != analyzer_reporters.end(); it_pr++) + + CSettings::map_analyzer_actions_and_reporters_t analyzerActionsAndReporters = m_pSettings->GetAnalyzerActionsAndReporters(); + CSettings::map_analyzer_actions_and_reporters_t::iterator it_aar; + for (it_aar = analyzerActionsAndReporters.begin(); it_aar != analyzerActionsAndReporters.end(); it_aar++) { - CSettings::set_pair_strings_t::iterator it_r; - for (it_r = it_pr->second.begin(); it_r != it_pr->second.end(); it_r++) + CSettings::vector_pair_strings_t::iterator it_ar; + for (it_ar = it_aar->second.begin(); it_ar != it_aar->second.end(); it_ar++) { - m_pMW->AddAnalyzerReporter(it_pr->first, (*it_r).first, (*it_r).second); + m_pMW->AddAnalyzerActionOrReporter(it_aar->first, (*it_ar).first, (*it_ar).second); } } - CSettings::map_analyzer_actions_t analyser_actions = m_pSettings->GetAnalyzerActions(); - CSettings::map_analyzer_actions_t::iterator it_pa; - for (it_pa = analyser_actions.begin(); it_pa != analyser_actions.end(); it_pa++) +} + +void CCrashWatcher::SetUpCron() +{ + CSettings::map_cron_t cron = m_pSettings->GetCron(); + CSettings::map_cron_t::iterator it_c; + for (it_c = cron.begin(); it_c != cron.end(); it_c++) { - CSettings::set_pair_strings_t::iterator it_a; - for (it_a = it_pa->second.begin(); it_a != it_pa->second.end(); it_a++) + std::string::size_type pos = it_c->first.find(":"); + std::string sH = it_c->first; + std::string sM = ""; + int nH = -1; + int nM = -1; + time_t actTime = time(NULL); + if (pos != std::string::npos) + { + sH = it_c->first.substr(0, pos); + sM = it_c->first.substr(pos + 1); + } + int timeout = 0; + if (sH != "*") + { + nH = atoi(sH.c_str()); + timeout = nH * 60 * 60; + } + if (sM != "*") { - m_pMW->AddAnalyzerAction(it_pa->first, (*it_a).first, (*it_a).second); + nM = atoi(sM.c_str()); + timeout = nM * 60; + } + if (nH == -1 || nM == -1) + { + CSettings::vector_pair_strings_t::iterator it_ar; + for (it_ar = it_c->second.begin(); it_ar != it_c->second.end(); it_ar++) + { + + cron_callback_data_t* cronPeriodicCallbackData = new cron_callback_data_t(this, (*it_ar).first, (*it_ar).second, timeout); + g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, + timeout , + cron_activation_periodic_cb, + static_cast<gpointer>(cronPeriodicCallbackData), + cron_delete_callback_data_cb); + } + } + else + { + time_t actTime = time(NULL); + if (actTime == ((time_t)-1)) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::SetUpCron(): Cannot get time."); + } + struct tm locTime; + if (localtime_r(&actTime, &locTime) == NULL) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::SetUpCron(): Cannot get local time."); + } + locTime.tm_hour = nH; + locTime.tm_min = nM; + locTime.tm_sec = 0; + time_t nextTime = mktime(&locTime); + if (nextTime == ((time_t)-1)) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::SetUpCron(): Cannot set up time."); + } + if (actTime > nextTime) + { + timeout = 24*60*60 + (nextTime - actTime); + } + else + { + timeout = nextTime - actTime; + } + CSettings::vector_pair_strings_t::iterator it_ar; + for (it_ar = it_c->second.begin(); it_ar != it_c->second.end(); it_ar++) + { + + cron_callback_data_t* cronOneCallbackData = new cron_callback_data_t(this, (*it_ar).first, (*it_ar).second, timeout); + g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, + timeout, + cron_activation_one_cb, + static_cast<gpointer>(cronOneCallbackData), + cron_delete_callback_data_cb); + cron_callback_data_t* cronResheduleCallbackData = new cron_callback_data_t(this, (*it_ar).first, (*it_ar).second, 24 * 60 * 60); + g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, + timeout, + cron_activation_reshedule_cb, + static_cast<gpointer>(cronResheduleCallbackData), + cron_delete_callback_data_cb); + } } } } @@ -222,6 +347,7 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath) m_pMainloop = g_main_loop_new(NULL,FALSE); m_pMW = new CMiddleWare(PLUGINS_CONF_DIR,PLUGINS_LIB_DIR); SetUpMW(); + SetUpCron(); FindNewDumps(pPath); #ifdef HAVE_DBUS m_pCommLayer = new CCommLayerServerDBus(); @@ -292,7 +418,7 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) if(m_pMW->SaveDebugDump(*itt, crashinfo)) { std::cerr << "Saved new entry: " << *itt << std::endl; - m_pMW->Report(*itt); + m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); } } catch(std::string err) diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index deba901..f42608f 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -48,11 +48,37 @@ class CCrashWatcher : public CObserver { private: + + typedef struct SCronCallbackData + { + CCrashWatcher* m_pCrashWatcher; + std::string m_sPluginName; + std::string m_sPluginArgs; + unsigned int m_nTimeout; + + SCronCallbackData(CCrashWatcher* pCrashWatcher, + const std::string& pPluginName, + const std::string& pPluginArgs, + const unsigned int& pTimeout) : + m_pCrashWatcher(pCrashWatcher), + m_sPluginName(pPluginName), + m_sPluginArgs(pPluginArgs), + m_nTimeout(pTimeout) + {} + + } cron_callback_data_t; + static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer data); + static gboolean cron_activation_periodic_cb(gpointer data); + static gboolean cron_activation_one_cb(gpointer data); + static gboolean cron_activation_reshedule_cb(gpointer data); + static void cron_delete_callback_data_cb(gpointer data); + void StartWatch(); void GStartWatch(); void Lock(); void SetUpMW(); + void SetUpCron(); /* finds dumps created when daemon wasn't running */ void FindNewDumps(const std::string& pPath); double GetDirSize(const std::string &pPath); diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index ab656d2..7acc7b1 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -21,7 +21,7 @@ #include <iostream> #include <cstdio> -CCrashWatcher *g_pCrashWatcher; +CCrashWatcher *g_pCrashWatcher = NULL; //DBus::Glib::BusDispatcher *dispatcher; void terminate(int signal) diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp index 6555e8d..d55ac1f 100644 --- a/src/Daemon/Settings.cpp +++ b/src/Daemon/Settings.cpp @@ -3,9 +3,10 @@ #include <stdlib.h> #define SECTION_COMMON "Common" -#define SECTION_REPORTERS "AnalyzerReporters" -#define SECTION_ACTIONS "AnalyzerActions" +#define SECTION_ANALYZER_ACTIONS_AND_REPORTERS "AnalyzerActionsAndReporters" +#define SECTION_CRON "Cron" +#include <iostream> void CSettings::LoadSettings(const std::string& pPath) { std::ifstream fIn; @@ -67,23 +68,35 @@ void CSettings::LoadSettings(const std::string& pPath) { if (section == SECTION_COMMON) { - m_mapSettingsCommon[key] = value; + if (m_mapSettingsCommon[key] != "") + { + m_mapSettingsCommon[key] += ","; + } + m_mapSettingsCommon[key] += value; } - else if (section == SECTION_REPORTERS) + else if (section == SECTION_ANALYZER_ACTIONS_AND_REPORTERS) { - m_mapSettingsReporters[key] = value; + if (m_mapSettingsAnalyzerActionsAndReporters[key] != "") + { + m_mapSettingsAnalyzerActionsAndReporters[key] += ","; + } + m_mapSettingsAnalyzerActionsAndReporters[key] += value; } - else if (section == SECTION_ACTIONS) + else if (section == SECTION_CRON) { - m_mapSettingsActions[key] = value; + if (m_mapSettingsCron[key] != "") + { + m_mapSettingsCron[key] += ","; + } + m_mapSettingsCron[key] += value; } } } fIn.close(); } ParseCommon(); - ParseReporters(); - ParseActions(); + ParseAnalyzerActionsAndReporters(); + ParseCron(); } void CSettings::ParseCommon() @@ -112,41 +125,40 @@ void CSettings::ParseCommon() { m_nMaxCrashReportsSize = atoi(m_mapSettingsCommon["MaxCrashReportsSize"].c_str()); } - if (m_mapSettingsCommon.find("Reporters") != m_mapSettingsCommon.end()) + if (m_mapSettingsCommon.find("ActionsAndReporters") != m_mapSettingsCommon.end()) { - m_setReporters = ParseListWithArgs(m_mapSettingsCommon["Reporters"]); + m_vectorActionsAndReporters = ParseListWithArgs(m_mapSettingsCommon["ActionsAndReporters"]); } - } -void CSettings::ParseReporters() +void CSettings::ParseAnalyzerActionsAndReporters() { map_settings_t::iterator it; - for (it = m_mapSettingsReporters.begin(); it != m_mapSettingsReporters.end(); it++) - { - m_mapAnalyzerReporters[it->first] = ParseListWithArgs(it->second); - } -} - -void CSettings::ParseActions() -{ - map_settings_t::iterator it; - for (it = m_mapSettingsActions.begin(); it != m_mapSettingsActions.end(); it++) + for (it = m_mapSettingsAnalyzerActionsAndReporters.begin(); it != m_mapSettingsAnalyzerActionsAndReporters.end(); it++) { set_strings_t keys = ParseKey(it->first); - set_pair_strings_t singleActions = ParseListWithArgs(it->second); + vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second); set_strings_t::iterator it_keys; for (it_keys = keys.begin(); it_keys != keys.end(); it_keys++) { - m_mapAnalyzerActions[*it_keys] = singleActions; + m_mapAnalyzerActionsAndReporters[*it_keys] = actionsAndReporters; } } } +void CSettings::ParseCron() +{ + map_settings_t::iterator it; + for (it = m_mapSettingsCron.begin(); it != m_mapSettingsCron.end(); it++) + { + vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second); + m_mapCron[it->first] = actionsAndReporters; + } +} -CSettings::set_pair_strings_t CSettings::ParseListWithArgs(const std::string& pValue) +CSettings::vector_pair_strings_t CSettings::ParseListWithArgs(const std::string& pValue) { - set_pair_strings_t pluginArgs; + vector_pair_strings_t pluginsWithArgs; unsigned int ii; std::string item = ""; std::string action = ""; @@ -167,7 +179,7 @@ CSettings::set_pair_strings_t CSettings::ParseListWithArgs(const std::string& pV } else if (pValue[ii] == ')' && is_arg && !is_quote) { - pluginArgs.insert(make_pair(action, item)); + pluginsWithArgs.push_back(make_pair(action, item)); item = ""; is_arg = false; action = ""; @@ -176,7 +188,7 @@ CSettings::set_pair_strings_t CSettings::ParseListWithArgs(const std::string& pV { if (item != "") { - pluginArgs.insert(make_pair(item, "")); + pluginsWithArgs.push_back(make_pair(item, "")); item = ""; } } @@ -187,9 +199,9 @@ CSettings::set_pair_strings_t CSettings::ParseListWithArgs(const std::string& pV } if (item != "") { - pluginArgs.insert(make_pair(item, "")); + pluginsWithArgs.push_back(make_pair(item, "")); } - return pluginArgs; + return pluginsWithArgs; } CSettings::set_strings_t CSettings::ParseKey(const std::string& Key) @@ -279,26 +291,27 @@ const bool& CSettings::GetOpenGPGCheck() return m_bOpenGPGCheck; } -const CSettings::map_analyzer_reporters_t& CSettings::GetAnalyzerReporters() +const CSettings::map_analyzer_actions_and_reporters_t& CSettings::GetAnalyzerActionsAndReporters() { - return m_mapAnalyzerReporters; + return m_mapAnalyzerActionsAndReporters; } -const CSettings::map_analyzer_actions_t& CSettings::GetAnalyzerActions() -{ - return m_mapAnalyzerActions; -} const unsigned int& CSettings::GetMaxCrashReportsSize() { return m_nMaxCrashReportsSize; } -const CSettings::set_pair_strings_t& CSettings::GetReporters() +const CSettings::vector_pair_strings_t& CSettings::GetActionsAndReporters() { - return m_setReporters; + return m_vectorActionsAndReporters; } const std::string& CSettings::GetDatabase() { return m_sDatabase; } + +const CSettings::map_cron_t& CSettings::GetCron() +{ + return m_mapCron; +} diff --git a/src/Daemon/Settings.h b/src/Daemon/Settings.h index 04a16d7..0f92083 100644 --- a/src/Daemon/Settings.h +++ b/src/Daemon/Settings.h @@ -12,30 +12,33 @@ class CSettings typedef std::map<std::string, std::string> map_settings_t; typedef std::set<std::string> set_strings_t; typedef std::pair<std::string, std::string> pair_string_string_t; - typedef std::set<pair_string_string_t> set_pair_strings_t; - typedef std::map<std::string, set_pair_strings_t> map_analyzer_reporters_t; - typedef std::map<std::string, set_pair_strings_t> map_analyzer_actions_t; + typedef std::vector<pair_string_string_t> vector_pair_strings_t; + typedef vector_pair_strings_t vector_actions_and_reporters_t; + typedef std::map<std::string, vector_pair_strings_t> map_analyzer_actions_and_reporters_t; + typedef std::map<std::string, vector_pair_strings_t> map_cron_t; private: map_settings_t m_mapSettingsCommon; - map_settings_t m_mapSettingsReporters; - map_settings_t m_mapSettingsActions; + map_settings_t m_mapSettingsAnalyzerActionsAndReporters; + map_settings_t m_mapSettingsCron; set_strings_t m_setOpenGPGPublicKeys; set_strings_t m_setBlackList; set_strings_t m_setEnabledPlugins; std::string m_sDatabase; - set_pair_strings_t m_setReporters; + vector_actions_and_reporters_t m_vectorActionsAndReporters; + map_cron_t m_mapCron; + bool m_bOpenGPGCheck; unsigned int m_nMaxCrashReportsSize; - map_analyzer_reporters_t m_mapAnalyzerReporters; - map_analyzer_actions_t m_mapAnalyzerActions; + map_analyzer_actions_and_reporters_t m_mapAnalyzerActionsAndReporters; void ParseCommon(); - void ParseReporters(); - void ParseActions(); + void ParseAnalyzerActionsAndReporters(); + void ParseCron(); + set_strings_t ParseList(const std::string& pList); - set_pair_strings_t ParseListWithArgs(const std::string& pList); + vector_pair_strings_t ParseListWithArgs(const std::string& pList); set_strings_t ParseKey(const std::string& pKey); public: @@ -44,11 +47,11 @@ class CSettings const set_strings_t& GetEnabledPlugins(); const set_strings_t& GetOpenGPGPublicKeys(); const bool& GetOpenGPGCheck(); - const map_analyzer_reporters_t& GetAnalyzerReporters(); - const map_analyzer_actions_t& GetAnalyzerActions(); + const map_analyzer_actions_and_reporters_t& GetAnalyzerActionsAndReporters(); const unsigned int& GetMaxCrashReportsSize(); - const set_pair_strings_t& GetReporters(); + const vector_pair_strings_t& GetActionsAndReporters(); const std::string& GetDatabase(); + const map_cron_t& GetCron(); }; #endif diff --git a/src/Daemon/abrt.conf b/src/Daemon/abrt.conf index ff0e854..36c2189 100644 --- a/src/Daemon/abrt.conf +++ b/src/Daemon/abrt.conf @@ -15,14 +15,16 @@ EnabledPlugins = SQLite3, CCpp, Mailx, Logger, Kerneloops, KerneloopsReporter Database = SQLite3 # max size for crash storage MaxCrashReportsSize = 1000 -# set of reporters which are activated immediately after a crash occurs -Reporters = Mailx("[abrt] new crash was detected") +# vector of actions and reporters which are activated immediately after a crash occurs +ActionsAndReporters = Mailx("[abrt] new crash was detected") # reporters association with analyzers -[ AnalyzerReporters ] -CCpp = Logger +[ AnalyzerActionsAndReporters ] Kerneloops = KerneloopsReporter +CCpp = Logger +# CCpp : xorg-x11-apps = RunApp("date", "RunApp") -# actions association -[ AnalyzerActions ] -# CCpp : xorg-x11-apps = RunApp("date", "RunApp")
\ No newline at end of file +# repeated calling of Action and Reporter plugins +[ Cron ] +# hh,mm +*:5 = Kerneloops |
