summaryrefslogtreecommitdiffstats
path: root/lib/Plugins/KerneloopsScanner.cpp
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-11-09 13:55:20 +0100
committerKarel Klic <kklic@redhat.com>2009-11-09 13:55:20 +0100
commit19f406b4930c931a932dc6930762e8e12e29ce8b (patch)
treeb08468bf9a010cbce0ecd000a0279222f0d4b4e7 /lib/Plugins/KerneloopsScanner.cpp
parent801ab58f32f2cb7dca3352b721a07c83705a0287 (diff)
parent8fa9a6ecd247454ab758efecf818d8067455c778 (diff)
downloadabrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.gz
abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.tar.xz
abrt-19f406b4930c931a932dc6930762e8e12e29ce8b.zip
merge
Diffstat (limited to 'lib/Plugins/KerneloopsScanner.cpp')
-rw-r--r--lib/Plugins/KerneloopsScanner.cpp72
1 files changed, 33 insertions, 39 deletions
diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp
index 60fa92e..8c8cd4b 100644
--- a/lib/Plugins/KerneloopsScanner.cpp
+++ b/lib/Plugins/KerneloopsScanner.cpp
@@ -31,8 +31,10 @@
#include "DebugDump.h"
#include "ABRTException.h"
#include "CommLayerInner.h"
+#include "KerneloopsSysLog.h"
#include "KerneloopsScanner.h"
+#include <limits.h>
#define FILENAME_KERNELOOPS "kerneloops"
@@ -41,7 +43,6 @@
CKerneloopsScanner::CKerneloopsScanner()
{
int cnt_FoundOopses;
- m_sSysLogFile = "/var/log/messages";
/* Scan dmesg, on first call only */
cnt_FoundOopses = ScanDmesg();
@@ -49,19 +50,23 @@ CKerneloopsScanner::CKerneloopsScanner()
SaveOopsToDebugDump();
}
-void CKerneloopsScanner::Run(const std::string& pActionDir,
- const std::string& pArgs)
+void CKerneloopsScanner::Run(const char *pActionDir, const char *pArgs)
{
- int cnt_FoundOopses;
+ const char *syslog_file = "/var/log/messages";
+ map_plugin_settings_t::const_iterator it = m_pSettings.find("SysLogFile");
+ if (it != m_pSettings.end())
+ {
+ syslog_file = it->second.c_str();
+ }
- cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str());
+ int cnt_FoundOopses = ScanSysLogFile(syslog_file);
if (cnt_FoundOopses > 0) {
SaveOopsToDebugDump();
/*
* This marker in syslog file prevents us from
* re-parsing old oopses (any oops before it is
* ignored by ScanSysLogFile()). The only problem
- * is that we can't be sure here that m_sSysLogFile
+ * is that we can't be sure here that syslog_file
* is the file where syslog(xxx) stuff ends up.
*/
openlog("abrt", 0, LOG_KERN);
@@ -78,26 +83,29 @@ void CKerneloopsScanner::SaveOopsToDebugDump()
{
update_client(_("Creating kernel oops crash reports..."));
+ int countdown = 16; /* do not report hundreds of oopses */
time_t t = time(NULL);
- std::list<COops> oopsList = m_pSysLog.GetOopsList();
- m_pSysLog.ClearOopsList();
-
- while (!oopsList.empty()) {
- char path[PATH_MAX];
- snprintf(path, sizeof(path), "%s/kerneloops-%lu-%lu",
- DEBUG_DUMPS_DIR, (long)t, (long)oopsList.size());
-
- COops oops = oopsList.back();
-
+ vector_string_t oopsList = m_pOopsList;
+ m_pOopsList.clear();
+
+ while (!oopsList.empty() && --countdown != 0) {
+ char path[sizeof(DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu") + 2 * sizeof(long)*3];
+ sprintf(path, DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu",
+ (long)t, (long)oopsList.size());
+
+ std::string oops = oopsList.back();
+ const char *first_line = oops.c_str();
+ char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */
+ *second_line++ = '\0';
try
{
CDebugDump debugDump;
debugDump.Create(path, 0);
debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops");
debugDump.SaveText(FILENAME_EXECUTABLE, "kernel");
- debugDump.SaveText(FILENAME_KERNEL, oops.m_sVersion);
+ debugDump.SaveText(FILENAME_KERNEL, first_line);
debugDump.SaveText(FILENAME_PACKAGE, "not_applicable");
- debugDump.SaveText(FILENAME_KERNELOOPS, oops.m_sData);
+ debugDump.SaveText(FILENAME_KERNELOOPS, second_line);
}
catch (CABRTException& e)
{
@@ -118,7 +126,8 @@ int CKerneloopsScanner::ScanDmesg()
buffer = (char*)xzalloc(pagesz + 1);
syscall(__NR_syslog, 3, buffer, pagesz);
- cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer));
+ m_pOopsList.clear();
+ cnt_FoundOopses = extract_oopses(m_pOopsList, buffer, strlen(buffer));
free(buffer);
return cnt_FoundOopses;
@@ -162,30 +171,15 @@ int CKerneloopsScanner::ScanSysLogFile(const char *filename)
close(fd);
cnt_FoundOopses = 0;
- if (sz > 0)
- cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, sz);
+ if (sz > 0) {
+ m_pOopsList.clear();
+ cnt_FoundOopses = extract_oopses(m_pOopsList, buffer, sz);
+ }
free(buffer);
return cnt_FoundOopses;
}
-void CKerneloopsScanner::SetSettings(const map_plugin_settings_t& pSettings)
-{
- if (pSettings.find("SysLogFile") != pSettings.end())
- {
- m_sSysLogFile = pSettings.find("SysLogFile")->second;
- }
-}
-
-map_plugin_settings_t CKerneloopsScanner::GetSettings()
-{
- map_plugin_settings_t ret;
-
- ret["SysLogFile"] = m_sSysLogFile;
-
- return ret;
-}
-
PLUGIN_INFO(ACTION,
CKerneloopsScanner,
"KerneloopsScanner",
@@ -195,7 +189,7 @@ PLUGIN_INFO(ACTION,
"http://people.redhat.com/aarapov",
"");
-/* for dumpoops tool */
+/* For "dumpoops" tool */
extern "C" {
int scan_syslog_file(CKerneloopsScanner *This, const char *filename)