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 /src | |
| 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 'src')
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 281 | ||||
| -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 | 18 |
6 files changed, 311 insertions, 138 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 2a3d0f1..f811501 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -50,12 +50,15 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gsize len; gsize i = 0; err = g_io_channel_read (gio, buf, INOTIFY_BUFF_SIZE, &len); - if (err != G_IO_ERROR_NONE) { + CCrashWatcher *cc = (CCrashWatcher*)daemon; + if (err != G_IO_ERROR_NONE) + { g_warning ("Error reading inotify fd: %d\n", err); return FALSE; } /* reconstruct each event and send message to the dbus */ - while (i < len) { + while (i < len) + { const char *name = NULL; struct inotify_event *event; @@ -63,18 +66,12 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, if (event->len) name = &buf[i] + sizeof (struct inotify_event); i += sizeof (struct inotify_event) + event->len; -#ifdef DEBUG - std::cout << "Created file: " << name << std::endl; -#endif /*DEBUG*/ + + cc->Debug(std::string("Created file: ") + name); /* we want to ignore the lock files */ if(event->mask & IN_ISDIR) { - CCrashWatcher *cc = (CCrashWatcher*)daemon; -#ifdef DEBUG - std::cerr << cc->GetDirSize(DEBUG_DUMPS_DIR)/(1024*1024.0) << std::endl; - std::cerr << cc->m_pSettings->GetMaxCrashReportsSize() << std::endl; -#endif /*DEBUG*/ if(cc->GetDirSize(DEBUG_DUMPS_DIR)/(1024*1024.0) < cc->m_pSettings->GetMaxCrashReportsSize()){ //std::string sName = name; map_crash_info_t crashinfo; @@ -82,7 +79,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]); } @@ -90,7 +87,7 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, catch (CABRTException& e) { std::cerr << e.what() << std::endl; - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { return -1; } @@ -98,23 +95,61 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, } else { -#ifdef DEBUG - std::cout << "DebugDumps size has exceeded the limit, deleting the last dump." << name << std::endl; -#endif /*DEBUG*/ + cc->Debug(std::string("DebugDumps size has exceeded the limit, deleting the last dump: ") + name); cc->m_pMW->DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); } } -#ifdef DEBUG else { - std::cerr << "Some file created, ignoring.." << std::endl; + cc->Debug("Some file created, ignoring..."); } -#endif /*DEBUG*/ } delete[] buf; return TRUE; } +gboolean CCrashWatcher::cron_activation_periodic_cb(gpointer data) +{ + cron_callback_data_t* cronPeriodicCallbackData = static_cast<cron_callback_data_t*>(data); + cronPeriodicCallbackData->m_pCrashWatcher->Debug("Activating plugin: " + cronPeriodicCallbackData->m_sPluginName); + 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); + cronOneCallbackData->m_pCrashWatcher->Debug("Activating plugin: " + cronOneCallbackData->m_sPluginName); + 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); + cronResheduleCallbackData->m_pCrashWatcher->Debug("Rescheduling plugin: " + cronResheduleCallbackData->m_sPluginName); + 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()); @@ -137,48 +172,130 @@ 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); + } } } } void CCrashWatcher::Status(const std::string& pMessage) { - std::cout << "Update: " << pMessage << std::endl; + std::cout << "Update: " + pMessage << std::endl; } void CCrashWatcher::Warning(const std::string& pMessage) { - std::cerr << "Warning: " << pMessage << std::endl; + std::cerr << "Warning: " + pMessage << std::endl; } void CCrashWatcher::Debug(const std::string& pMessage) { //some logic to add logging levels? - std::cout << "Debug: " << pMessage << std::endl; + std::cout << "Debug: " + pMessage << std::endl; } double CCrashWatcher::GetDirSize(const std::string &pPath) @@ -207,7 +324,9 @@ double CCrashWatcher::GetDirSize(const std::string &pPath) (void) closedir (dp); } else - throw std::string("Init Failed"); + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::GetDirSize(): Init Failed"); + } return size; } @@ -223,9 +342,11 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath) m_pSettings = new CSettings(); m_pSettings->LoadSettings(std::string(CONF_DIR) + "/abrt.conf"); + 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(); @@ -235,14 +356,13 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath) m_pCommLayer = new CCommLayerServerDBus(); m_pCommLayer->Attach(this); - if((m_nFd = inotify_init()) == -1){ - throw std::string("Init Failed"); - //std::cerr << "Init Failed" << std::endl; - exit(-1); + if((m_nFd = inotify_init()) == -1) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Init Failed"); } if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1){ - throw std::string("Add watch failed:") + pPath.c_str(); + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::CCrashWatcher(): Add watch failed:" + pPath); } m_pGio = g_io_channel_unix_new(m_nFd); } @@ -262,7 +382,7 @@ CCrashWatcher::~CCrashWatcher() } void CCrashWatcher::FindNewDumps(const std::string& pPath) { - std::cerr << "Scanning for unsaved entries" << std::endl; + Debug("Scanning for unsaved entries..."); struct dirent *ep; struct stat stats; DIR *dp; @@ -272,13 +392,14 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) dp = opendir (pPath.c_str()); if (dp != NULL) { - while ((ep = readdir (dp))){ - if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0){ + while ((ep = readdir (dp))) + { + if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0) + { dname = pPath + "/" + ep->d_name; - std::cerr << dname << std::endl; lstat (dname.c_str(), &stats); - if(S_ISDIR (stats.st_mode)){ - std::cerr << ep->d_name << std::endl; + if(S_ISDIR (stats.st_mode)) + { dirs.push_back(dname); } } @@ -286,23 +407,24 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) (void) closedir (dp); } else - perror ("Couldn't open the directory"); + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::FindNewDumps(): Couldn't open the directory:" + pPath); + } for (std::vector<std::string>::iterator itt = dirs.begin(); itt != dirs.end(); ++itt){ map_crash_info_t crashinfo; - std::cerr << "Saving debugdeump: " << *itt << std::endl; try { if(m_pMW->SaveDebugDump(*itt, crashinfo)) { - std::cerr << "Saved new entry: " << *itt << std::endl; - m_pMW->Report(*itt); + Debug("Saved new entry: " + *itt); + m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); } } catch (CABRTException& e) { std::cerr << e.what() << std::endl; - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { exit(-1); } @@ -314,9 +436,13 @@ void CCrashWatcher::Lock() { int lfp = open("abrt.lock",O_RDWR|O_CREAT,0640); if (lfp < 0) - throw std::string("CCrashWatcher.cpp:can not open lock file"); + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): can not open lock file"); + } if (lockf(lfp,F_TLOCK,0) < 0) - throw std::string("CCrashWatcher.cpp:Lock:cannot create lock on lockfile"); + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Lock(): cannot create lock on lockfile"); + } /* only first instance continues */ //sprintf(str,"%d\n",getpid()); //write(lfp,str,strlen(str)); /* record pid to lockfile */ @@ -330,19 +456,24 @@ void CCrashWatcher::StartWatch() char action[FILENAME_MAX]; struct inotify_event *pevent; //run forever - while(1){ + while(1) + { i = 0; len = read(m_nFd,buff,INOTIFY_BUFF_SIZE); - while(i < len){ + while(i < len) + { pevent = (struct inotify_event *)&buff[i]; if (pevent->len) + { std::strcpy(action, pevent->name); + } else + { std::strcpy(action, m_sTarget.c_str()); + } + i += sizeof(struct inotify_event) + pevent->len; -#ifdef DEBUG - std::cout << "Created file: " << action << std::endl; -#endif /*DEBUG*/ + Debug(std::string("Created file: ") + action); } } delete[] buff; @@ -359,21 +490,21 @@ void CCrashWatcher::GStartWatch() void CCrashWatcher::Daemonize() { -#ifdef DEBUG - std::cout << "Daemonize" << std::endl; -#endif + + Debug("Daemonize..."); // forking to background pid_t pid = fork(); if (pid < 0) { - throw "CCrashWatcher.cpp:Daemonize:Fork error"; + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Daemonize(): Fork error"); } /* parent exits */ if (pid > 0) _exit(0); /* child (daemon) continues */ pid_t sid = setsid(); - if(sid == -1){ - throw "CCrashWatcher.cpp:Daemonize:setsid failed"; + if(sid == -1) + { + throw CABRTException(EXCEP_FATAL, "CCrashWatcher::Daemonize(): setsid failed"); } close(STDIN_FILENO); close(STDOUT_FILENO); @@ -384,9 +515,7 @@ void CCrashWatcher::Daemonize() void CCrashWatcher::Run() { -#ifdef DEBUG - std::cout << "Run" << std::endl; -#endif + Debug("Runnig..."); //Lock(); GStartWatch(); } @@ -394,7 +523,7 @@ void CCrashWatcher::Run() vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) { vector_crash_infos_t retval; - std::cerr << "CCommLayerServerDBus::GetCrashInfos" << std::endl; + Debug("Getting crash infos..."); try { retval = m_pMW->GetCrashInfos(pUID); @@ -403,7 +532,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) { std::cerr << e.what() << std::endl; m_pCommLayer->Error(e.what()); - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { exit(-1); } @@ -415,7 +544,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) map_crash_report_t CCrashWatcher::CreateReport(const std::string &pUUID,const std::string &pUID) { map_crash_report_t crashReport; - std::cerr << "Creating report" << std::endl; + Debug("Creating report..."); try { m_pMW->CreateCrashReport(pUUID,pUID,crashReport); @@ -425,7 +554,7 @@ map_crash_report_t CCrashWatcher::CreateReport(const std::string &pUUID,const st { std::cerr << e.what() << std::endl; m_pCommLayer->Error(e.what()); - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { exit(-1); } @@ -450,7 +579,7 @@ bool CCrashWatcher::Report(map_crash_report_t pReport) { std::cerr << e.what() << std::endl; m_pCommLayer->Error(e.what()); - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { exit(-1); } @@ -469,7 +598,7 @@ bool CCrashWatcher::DeleteDebugDump(const std::string& pUUID, const std::string& { std::cerr << e.what() << std::endl; m_pCommLayer->Error(e.what()); - if (e.type() == EXCEP_ERROR) + if (e.type() == EXCEP_FATAL) { return -1; } 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 96914d1..f8d01de 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; 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..d059a9e 100644 --- a/src/Daemon/abrt.conf +++ b/src/Daemon/abrt.conf @@ -10,19 +10,21 @@ OpenGPGPublicKeys = /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora BlackList = bash, bind # enabled plugins # there has to be exactly one database plugin -EnabledPlugins = SQLite3, CCpp, Mailx, Logger, Kerneloops, KerneloopsReporter +EnabledPlugins = SQLite3, CCpp, Mailx, Logger, Kerneloops, KerneloopsScanner, KerneloopsReporter # Database 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 plugins +[ Cron ] +# hh,mm +*:1 = KerneloopsScanner |
