diff options
author | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-05-12 15:40:35 +0200 |
---|---|---|
committer | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-05-12 15:40:35 +0200 |
commit | 6b77cb82cb7b918660435effb0fe356401bfdd55 (patch) | |
tree | 66d550082a1a96b11efe0978c664cb73155e64a9 /lib/Plugins | |
parent | 48fd6795c43d425c7d54a7b14cb565ee8092b4d0 (diff) | |
download | abrt-6b77cb82cb7b918660435effb0fe356401bfdd55.tar.gz abrt-6b77cb82cb7b918660435effb0fe356401bfdd55.tar.xz abrt-6b77cb82cb7b918660435effb0fe356401bfdd55.zip |
added new kerneloopsscanner plugin, therefore kerneloops plugin is much more simply now
Diffstat (limited to 'lib/Plugins')
-rw-r--r-- | lib/Plugins/Kerneloops.cpp | 178 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.h | 13 | ||||
-rw-r--r-- | lib/Plugins/Makefile.am | 16 |
3 files changed, 12 insertions, 195 deletions
diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index c868bae3..57482c0e 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 2fa9026b..00b4ea0e 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/Makefile.am b/lib/Plugins/Makefile.am index 396b2054..51436f78 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 |