summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Arapov <aarapov@redhat.com>2009-08-10 23:57:38 +0200
committerAnton Arapov <aarapov@redhat.com>2009-08-10 23:57:38 +0200
commitd4353d69f177b7a0e023cb7a90c3493d2b9efca8 (patch)
tree3f6458ca35b225e14a1210ae9f6164f01913c780
parent6cb98fb02176d0a24474d9843f2648b7ed824a31 (diff)
downloadabrt-d4353d69f177b7a0e023cb7a90c3493d2b9efca8.tar.gz
abrt-d4353d69f177b7a0e023cb7a90c3493d2b9efca8.tar.xz
abrt-d4353d69f177b7a0e023cb7a90c3493d2b9efca8.zip
Kerneloops plugin: style fixes
-rw-r--r--lib/Plugins/KerneloopsReporter.cpp18
-rw-r--r--lib/Plugins/KerneloopsReporter.h6
-rw-r--r--lib/Plugins/KerneloopsScanner.cpp240
-rw-r--r--lib/Plugins/KerneloopsScanner.h38
4 files changed, 153 insertions, 149 deletions
diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp
index acf8f42c..d0aedb7f 100644
--- a/lib/Plugins/KerneloopsReporter.cpp
+++ b/lib/Plugins/KerneloopsReporter.cpp
@@ -32,7 +32,6 @@
#define FILENAME_KERNELOOPS "kerneloops"
/* helpers */
-
static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
{
size *= nmemb;
@@ -89,7 +88,6 @@ static int http_post_to_kerneloops_site(const char *url, const char *oopsdata)
/* class CKerneloopsReporter */
-
CKerneloopsReporter::CKerneloopsReporter() :
m_sSubmitURL("http://submit.kerneloops.org/submitoops.php")
{}
@@ -120,24 +118,24 @@ void CKerneloopsReporter::LoadSettings(const std::string& pPath)
map_plugin_settings_t settings;
plugin_load_settings(pPath, settings);
- SetSettings(settings);
+ SetSettings(settings);
}
void CKerneloopsReporter::SetSettings(const map_plugin_settings_t& pSettings)
{
- if (pSettings.find("SubmitURL") != pSettings.end())
- {
- m_sSubmitURL = pSettings.find("SubmitURL")->second;
- }
+ if (pSettings.find("SubmitURL") != pSettings.end())
+ {
+ m_sSubmitURL = pSettings.find("SubmitURL")->second;
+ }
}
map_plugin_settings_t CKerneloopsReporter::GetSettings()
{
- map_plugin_settings_t ret;
+ map_plugin_settings_t ret;
- ret["SubmitURL"] = m_sSubmitURL;
+ ret["SubmitURL"] = m_sSubmitURL;
- return ret;
+ return ret;
}
PLUGIN_INFO(REPORTER,
diff --git a/lib/Plugins/KerneloopsReporter.h b/lib/Plugins/KerneloopsReporter.h
index 5ef172c2..7dcd0e0c 100644
--- a/lib/Plugins/KerneloopsReporter.h
+++ b/lib/Plugins/KerneloopsReporter.h
@@ -41,10 +41,10 @@ class CKerneloopsReporter : public CReporter
CKerneloopsReporter();
virtual void LoadSettings(const std::string& pPath);
- virtual void SetSettings(const map_plugin_settings_t& pSettings);
- virtual map_plugin_settings_t GetSettings();
+ virtual void SetSettings(const map_plugin_settings_t& pSettings);
+ virtual map_plugin_settings_t GetSettings();
virtual void Report(const map_crash_report_t& pCrashReport,
- const std::string& pArgs);
+ const std::string& pArgs);
};
#endif
diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp
index 12c06667..aa9fa040 100644
--- a/lib/Plugins/KerneloopsScanner.cpp
+++ b/lib/Plugins/KerneloopsScanner.cpp
@@ -13,153 +13,159 @@
#define FILENAME_KERNELOOPS "kerneloops"
void CKerneloopsScanner::Run(const std::string& pActionDir,
- const std::string& pArgs)
+ const std::string& pArgs)
{
- int cnt_FoundOopses;
-
- /* Scan syslog file, on first call only */
- if (!m_bSysLogFileScanned)
- {
- cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str());
- 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 the file where syslog(xxx) stuff ends up.
- */
- openlog("abrt", 0, LOG_KERN);
- syslog(LOG_WARNING, "Kerneloops: Reported %u kernel oopses to Abrt", cnt_FoundOopses);
- closelog();
- }
- m_bSysLogFileScanned = true;
- }
- /* Scan kernel's log buffer */
- cnt_FoundOopses = ScanDmesg();
- if (cnt_FoundOopses > 0)
- SaveOopsToDebugDump();
+ int cnt_FoundOopses;
+
+ /* Scan syslog file, on first call only */
+ if (!m_bSysLogFileScanned)
+ {
+ cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str());
+ 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 the file where syslog(xxx) stuff ends up.
+ */
+ openlog("abrt", 0, LOG_KERN);
+ syslog(
+ LOG_WARNING,
+ "Kerneloops: Reported %u kernel oopses to Abrt",
+ cnt_FoundOopses
+ );
+ closelog();
+ }
+ m_bSysLogFileScanned = true;
+ }
+
+ /* Scan kernel's log buffer */
+ cnt_FoundOopses = ScanDmesg();
+ if (cnt_FoundOopses > 0)
+ SaveOopsToDebugDump();
}
void CKerneloopsScanner::SaveOopsToDebugDump()
{
- comm_layer_inner_status("Creating kernel oops crash reports...");
-
- time_t t = time(NULL);
- CDebugDump debugDump;
- 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();
-
- try
- {
- debugDump.Create(path, 0);
- debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops");
- debugDump.SaveText(FILENAME_EXECUTABLE, "kernel");
- debugDump.SaveText(FILENAME_KERNEL, oops.m_sVersion);
- debugDump.SaveText(FILENAME_PACKAGE, "not_applicable");
- debugDump.SaveText(FILENAME_KERNELOOPS, oops.m_sData);
- debugDump.Close();
- }
- catch (CABRTException& e)
- {
- throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": " + e.what());
- }
- oopsList.pop_back();
- }
+ comm_layer_inner_status("Creating kernel oops crash reports...");
+
+ time_t t = time(NULL);
+ CDebugDump debugDump;
+ 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();
+
+ try
+ {
+ debugDump.Create(path, 0);
+ debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops");
+ debugDump.SaveText(FILENAME_EXECUTABLE, "kernel");
+ debugDump.SaveText(FILENAME_KERNEL, oops.m_sVersion);
+ debugDump.SaveText(FILENAME_PACKAGE, "not_applicable");
+ debugDump.SaveText(FILENAME_KERNELOOPS, oops.m_sData);
+ debugDump.Close();
+ }
+ catch (CABRTException& e)
+ {
+ throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": " + e.what());
+ }
+ oopsList.pop_back();
+ }
}
int CKerneloopsScanner::ScanDmesg()
{
- comm_layer_inner_debug("Scanning dmesg...");
+ comm_layer_inner_debug("Scanning dmesg...");
- int cnt_FoundOopses;
- char *buffer;
- int pagesz = getpagesize();
+ int cnt_FoundOopses;
+ char *buffer;
+ int pagesz = getpagesize();
- buffer = (char*)xzalloc(pagesz + 1);
+ buffer = (char*)xzalloc(pagesz + 1);
- syscall(__NR_syslog, 3, buffer, pagesz);
- cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer) /*, 0*/);
- free(buffer);
+ syscall(__NR_syslog, 3, buffer, pagesz);
+ cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer) /*, 0*/);
+ free(buffer);
- return cnt_FoundOopses;
+ return cnt_FoundOopses;
}
int CKerneloopsScanner::ScanSysLogFile(const char *filename)
{
- comm_layer_inner_debug("Scanning syslog...");
-
- char *buffer;
- struct stat statb;
- int fd;
- int cnt_FoundOopses;
- ssize_t sz;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return 0;
- statb.st_size = 0; /* paranoia */
- if (fstat(fd, &statb) != 0 || statb.st_size < 1)
- return 0;
-
- /*
- * 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 absurd 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.
- */
- sz = statb.st_size + 1024;
- if (statb.st_size > (32*1024*1024 - 1024)) {
- xlseek(fd, -(32*1024*1024 - 1024), SEEK_END);
- sz = 32*1024*1024;
- }
- buffer = (char*)xzalloc(sz);
- sz = full_read(fd, buffer, sz);
- close(fd);
-
- cnt_FoundOopses = 0;
- if (sz > 0)
- cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, sz /*, 1*/);
- free(buffer);
-
- return cnt_FoundOopses;
+ comm_layer_inner_debug("Scanning syslog...");
+
+ char *buffer;
+ struct stat statb;
+ int fd;
+ int cnt_FoundOopses;
+ ssize_t sz;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return 0;
+ statb.st_size = 0; /* paranoia */
+ if (fstat(fd, &statb) != 0 || statb.st_size < 1)
+ return 0;
+
+ /*
+ * 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 absurd 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.
+ */
+ sz = statb.st_size + 1024;
+ if (statb.st_size > (32*1024*1024 - 1024)) {
+ xlseek(fd, -(32*1024*1024 - 1024), SEEK_END);
+ sz = 32*1024*1024;
+ }
+ buffer = (char*)xzalloc(sz);
+ sz = full_read(fd, buffer, sz);
+ close(fd);
+
+ cnt_FoundOopses = 0;
+ if (sz > 0)
+ cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, sz /*, 1*/);
+ free(buffer);
+
+ return cnt_FoundOopses;
}
void CKerneloopsScanner::LoadSettings(const std::string& pPath)
{
- map_plugin_settings_t settings;
- plugin_load_settings(pPath, settings);
+ map_plugin_settings_t settings;
+ plugin_load_settings(pPath, settings);
- SetSettings(settings);
+ SetSettings(settings);
}
void CKerneloopsScanner::SetSettings(const map_plugin_settings_t& pSettings)
{
- if (pSettings.find("SysLogFile") != pSettings.end())
- {
- m_sSysLogFile = pSettings.find("SysLogFile")->second;
- }
+ if (pSettings.find("SysLogFile") != pSettings.end())
+ {
+ m_sSysLogFile = pSettings.find("SysLogFile")->second;
+ }
}
map_plugin_settings_t CKerneloopsScanner::GetSettings()
{
- map_plugin_settings_t ret;
+ map_plugin_settings_t ret;
- ret["SysLogFile"] = m_sSysLogFile;
+ ret["SysLogFile"] = m_sSysLogFile;
- return ret;
+ return ret;
}
PLUGIN_INFO(ACTION,
@@ -176,12 +182,12 @@ extern "C" {
int scan_syslog_file(CKerneloopsScanner *This, const char *filename)
{
- return This->ScanSysLogFile(filename);
+ return This->ScanSysLogFile(filename);
}
void save_oops_to_debug_dump(CKerneloopsScanner *This)
{
- This->SaveOopsToDebugDump();
+ This->SaveOopsToDebugDump();
}
}
diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h
index eba1c00b..830bf62c 100644
--- a/lib/Plugins/KerneloopsScanner.h
+++ b/lib/Plugins/KerneloopsScanner.h
@@ -7,27 +7,27 @@
class CKerneloopsScanner : public CAction
{
- private:
- std::string m_sSysLogFile;
- CSysLog m_pSysLog;
- bool m_bSysLogFileScanned;
+ private:
+ std::string m_sSysLogFile;
+ CSysLog m_pSysLog;
+ bool m_bSysLogFileScanned;
- public:
- /* For standalone oops processor */
- void SaveOopsToDebugDump();
- int ScanDmesg();
- int ScanSysLogFile(const char *filename);
+ public:
+ /* For standalone oops processor */
+ void SaveOopsToDebugDump();
+ int ScanDmesg();
+ int ScanSysLogFile(const char *filename);
- /* Plugin intarface */
- CKerneloopsScanner() :
- m_sSysLogFile("/var/log/messages"),
- m_bSysLogFileScanned(false)
- {}
- virtual void Run(const std::string& pActionDir,
- const std::string& pArgs);
- virtual void LoadSettings(const std::string& pPath);
- virtual void SetSettings(const map_plugin_settings_t& pSettings);
- virtual map_plugin_settings_t GetSettings();
+ /* Plugin interface */
+ CKerneloopsScanner() :
+ m_sSysLogFile("/var/log/messages"),
+ m_bSysLogFileScanned(false)
+ {}
+ virtual void Run(const std::string& pActionDir,
+ const std::string& pArgs);
+ virtual void LoadSettings(const std::string& pPath);
+ virtual void SetSettings(const map_plugin_settings_t& pSettings);
+ virtual map_plugin_settings_t GetSettings();
};
#endif /* KERNELOOPSSCANNER_H_ */