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 /src/Daemon | |
| parent | 7d0eaab97308c65d0da2db0a0d2f5710ce36e2fe (diff) | |
| download | abrt-132e3403a62e47df970241c289f718e5ca2ece97.tar.gz abrt-132e3403a62e47df970241c289f718e5ca2ece97.tar.xz abrt-132e3403a62e47df970241c289f718e5ca2ece97.zip | |
support for simpler settings
Diffstat (limited to 'src/Daemon')
| -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 |
6 files changed, 249 insertions, 79 deletions
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 |
