summaryrefslogtreecommitdiffstats
path: root/lib/Plugins
diff options
context:
space:
mode:
authorZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-04-08 13:44:35 +0200
committerZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-04-08 13:44:35 +0200
commit234a905fe548f73f5e1df0db5b3490ae9b00a9d5 (patch)
tree70dca16dbb78da5925a626890442b687b04a4f80 /lib/Plugins
parent5c4a18fdd9795abaed59d3f5718d60cecde889ab (diff)
downloadabrt-234a905fe548f73f5e1df0db5b3490ae9b00a9d5.tar.gz
abrt-234a905fe548f73f5e1df0db5b3490ae9b00a9d5.tar.xz
abrt-234a905fe548f73f5e1df0db5b3490ae9b00a9d5.zip
renamed MW library
renamed Utils library added check for plugins init method renamed crash types
Diffstat (limited to 'lib/Plugins')
-rw-r--r--lib/Plugins/CCpp.cpp160
-rw-r--r--lib/Plugins/CCpp.h5
-rw-r--r--lib/Plugins/Kerneloops.cpp5
-rw-r--r--lib/Plugins/KerneloopsReporter.cpp4
-rw-r--r--lib/Plugins/Makefile.am3
5 files changed, 136 insertions, 41 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 7a4fdc3..95a9fff 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -25,7 +25,6 @@
#include "PluginSettings.h"
#include <sstream>
#include <iostream>
-#include <hash_map>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
@@ -33,9 +32,19 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
+#include <iomanip>
+
+#include <nss.h>
+#include <sechash.h>
+#include <prinit.h>
+
#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern"
-#define CORE_PATTERN "|"CCPP_HOOK_PATH" %p %s %u"
+#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u"
+
+#define FILENAME_COREDUMP "coredump"
+#define FILENAME_BACKTRACE "backtrace"
+#define FILENAME_MEMORYMAP "memorymap"
CAnalyzerCCpp::CAnalyzerCCpp() :
m_bMemoryMap(false),
@@ -51,10 +60,34 @@ CAnalyzerCCpp::~CAnalyzerCCpp()
}
}
+std::string CAnalyzerCCpp::CreateHash(const std::string& pInput)
+{
+ std::string ret = "";
+ HASHContext* hc;
+ unsigned char hash[SHA1_LENGTH];
+ unsigned int len;
+
+ hc = HASH_Create(HASH_AlgSHA1);
+ if (!hc)
+ {
+ throw std::string("CAnalyzerCCpp::CreateHash(): cannot initialize hash.");
+ }
+ HASH_Begin(hc);
+ HASH_Update(hc, reinterpret_cast<const unsigned char*>(pInput.c_str()), pInput.length());
+ HASH_End(hc, hash, &len, sizeof(hash));
+ HASH_Destroy(hc);
+
+ unsigned int ii;
+ std::stringstream ss;
+ for (ii = 0; ii < len; ii++)
+ ss << std::setw(2) << std::setfill('0') << std::hex << (hash[ii]&0xff);
+
+ return ss.str();
+}
+
void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage)
{
std::string packageName = pPackage.substr(0, pPackage.rfind("-", pPackage.rfind("-")-1));
- std::cerr << packageName << std::endl;
char buff[1024];
int pipein[2], pipeout[2];
struct timeval delay;
@@ -169,8 +202,8 @@ void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string&
dd.LoadText(FILENAME_UID, UID);
dd.Close();
fTmp << "file " << executable << std::endl;
- fTmp << "core " << pDebugDumpDir << "/" << FILENAME_BINARYDATA1 << std::endl;
- fTmp << "bt" << std::endl;
+ fTmp << "core " << pDebugDumpDir << "/" << FILENAME_COREDUMP << std::endl;
+ fTmp << "bt full" << std::endl;
fTmp << "q" << std::endl;
fTmp.close();
}
@@ -178,8 +211,11 @@ void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string&
{
throw "CAnalyzerCCpp::GetBacktrace(): cannot create gdb script " + tmpFile ;
}
-
- RunGdb(tmpFile, UID, pBacktrace);
+ char* command = (char*)"gdb";
+ char* args[5] = { (char*)"gdb", (char*)"-batch", (char*)"-x", NULL, NULL };
+ args[3] = strdup(tmpFile.c_str());
+ ExecVP(command, args, UID, pBacktrace);
+ free(args[3]);
}
void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace)
@@ -189,13 +225,22 @@ void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::
{
std::string line = "";
int jj = 0;
+ bool in_bracket = false;
- while (pBacktrace[ii] != '\n' && ii < pBacktrace.length())
+ while ((pBacktrace[ii] != '\n' || in_bracket) && ii < pBacktrace.length())
{
+ if (pBacktrace[ii] == '(')
+ {
+ in_bracket = true;
+ }
+ else if (pBacktrace[ii] == ')')
+ {
+ in_bracket = false;
+ }
line += pBacktrace[ii];
ii++;
}
- while (isspace(line[jj]))
+ while (isspace(line[jj]) && jj < line.length())
{
jj++;
}
@@ -203,13 +248,23 @@ void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::
{
while(jj < line.length())
{
- if (isspace(line[jj]))
+ if (isspace(line[jj]) && jj < line.length())
+ {
+ jj++;
+ }
+ else if (line[jj] == '\"')
{
jj++;
+ while (line[jj] != '\"' && jj < line.length())
+ {
+ jj++;
+ }
}
- else if (line[jj] == '0' && line[jj+1] == 'x')
+ else if ((line[jj] == '=' && isdigit(line[jj+1])) ||
+ (line[jj] == '0' && line[jj+1] == 'x') )
{
- while (isalnum(line[jj]))
+ jj += 2;
+ while (isalnum(line[jj]) && jj < line.length())
{
jj++;
}
@@ -225,7 +280,34 @@ void CAnalyzerCCpp::GetIndependentBacktrace(const std::string& pBacktrace, std::
}
}
-void CAnalyzerCCpp::RunGdb(const std::string& pScript, const std::string pUID, std::string& pOutput)
+void CAnalyzerCCpp::GetIndependentBuldIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC)
+{
+ int ii = 0;
+ while (ii < pBuildIdPC.length())
+ {
+ std::string line = "";
+ int jj = 0;
+
+ while (pBuildIdPC[ii] != '\n' && ii < pBuildIdPC.length())
+ {
+ line += pBuildIdPC[ii];
+ ii++;
+ }
+ while (!isspace(line[jj]) && jj < line.length())
+ {
+ jj++;
+ }
+ jj++;
+ while (!isspace(line[jj]) && jj < line.length())
+ {
+ pIndependentBuildIdPC += line[jj];
+ jj++;
+ }
+ ii++;
+ }
+}
+
+void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std::string& pUID, std::string& pOutput)
{
int pipeout[2];
char buff[1024];
@@ -255,7 +337,7 @@ void CAnalyzerCCpp::RunGdb(const std::string& pScript, const std::string pUID, s
seteuid(atoi(pUID.c_str()));
setsid();
- execlp("gdb", "gdb","-batch", "-x", pScript.c_str(), NULL);
+ execvp(pCommand, pArgs);
exit(0);
}
@@ -295,37 +377,40 @@ void CAnalyzerCCpp::RunGdb(const std::string& pScript, const std::string pUID, s
std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir)
{
-
- std::stringstream ss;
- char* core;
- unsigned int size;
- std::string executable;
CDebugDump dd;
-
+ std::string UID;
+ std::string executable;
+ std::string package;
+ std::string buildIdPC;
+ std::string independentBuildIdPC;
+ std::string core = "--core="+ pDebugDumpDir + "/" +FILENAME_COREDUMP;
+ char* command = (char*)"eu-unstrip";
+ char* args[4] = { (char*)"eu-unstrip", NULL, (char*)"-n", NULL };
+ args[1] = strdup(core.c_str());
dd.Open(pDebugDumpDir);
- dd.LoadBinary(FILENAME_BINARYDATA1, &core, &size);
+ dd.LoadText(FILENAME_UID, UID);
dd.LoadText(FILENAME_EXECUTABLE, executable);
+ dd.LoadText(FILENAME_PACKAGE, package);
+ ExecVP(command, args, UID, buildIdPC);
dd.Close();
- // TODO: compute local UUID, remove this hack
- ss << executable << "_" << size;
-
- return ss.str();
+ free(args[1]);
+ GetIndependentBuldIdPC(buildIdPC, independentBuildIdPC);
+ return CreateHash(package + executable + independentBuildIdPC);
}
std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir)
{
- std::stringstream ss;
std::string backtrace;
+ std::string executable;
+ std::string package;
std::string independentBacktrace;
- __gnu_cxx::hash<const char*> hash;
-
CDebugDump dd;
dd.Open(pDebugDumpDir);
- dd.LoadText(FILENAME_TEXTDATA1, backtrace);
+ dd.LoadText(FILENAME_BACKTRACE, backtrace);
+ dd.LoadText(FILENAME_EXECUTABLE, executable);
+ dd.LoadText(FILENAME_PACKAGE, package);
dd.Close();
GetIndependentBacktrace(backtrace, independentBacktrace);
- // TODO: compute global UUID, remove this hack
- ss << hash(independentBacktrace.c_str());
- return ss.str();
+ return CreateHash(package + executable + independentBacktrace);
}
void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir)
@@ -334,7 +419,7 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir)
std::string backtrace;
CDebugDump dd;
dd.Open(pDebugDumpDir);
- if (dd.Exist(FILENAME_TEXTDATA1))
+ if (dd.Exist(FILENAME_BACKTRACE))
{
dd.Close();
return;
@@ -347,10 +432,10 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir)
GetBacktrace(pDebugDumpDir, backtrace);
dd.Open(pDebugDumpDir);
- dd.SaveText(FILENAME_TEXTDATA1, backtrace);
+ dd.SaveText(FILENAME_BACKTRACE, backtrace);
if (m_bMemoryMap)
{
- dd.SaveText(FILENAME_TEXTDATA2, "memory map of the crashed C/C++ application, not implemented yet");
+ dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet");
}
dd.Close();
}
@@ -371,6 +456,10 @@ void CAnalyzerCCpp::Init()
fOutCorePattern << CORE_PATTERN << std::endl;
fOutCorePattern.close();
}
+ if (NSS_NoDB_Init(NULL) != SECSuccess)
+ {
+ throw std::string("CAnalyzerCCpp::CreateHash(): cannot initialize NSS library.");
+ }
}
@@ -383,6 +472,7 @@ void CAnalyzerCCpp::DeInit()
fOutCorePattern << m_sOldCorePattern << std::endl;
fOutCorePattern.close();
}
+ NSS_Shutdown();
}
void CAnalyzerCCpp::LoadSettings(const std::string& pPath)
diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h
index 41a4d5b..1011b70 100644
--- a/lib/Plugins/CCpp.h
+++ b/lib/Plugins/CCpp.h
@@ -36,8 +36,9 @@ class CAnalyzerCCpp : public CAnalyzer
void InstallDebugInfos(const std::string& pPackage);
void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace);
void GetIndependentBacktrace(const std::string& pBacktrace, std::string& pIndependentBacktrace);
- void RunGdb(const std::string& pScript, const std::string pUID, std::string& pOutput);
-
+ void GetIndependentBuldIdPC(const std::string& pBuildIdPC, std::string& pIndependentBuildIdPC);
+ void ExecVP(const char* pCommand, char* const pArgs[], const std::string& pUID, std::string& pOutput);
+ std::string CreateHash(const std::string& pInput);
public:
CAnalyzerCCpp();
virtual ~CAnalyzerCCpp();
diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp
index b743a48..144fac8 100644
--- a/lib/Plugins/Kerneloops.cpp
+++ b/lib/Plugins/Kerneloops.cpp
@@ -40,6 +40,7 @@
#include <asm/unistd.h>
#define MAX(A,B) ((A) > (B) ? (A) : (B))
+#define FILENAME_KERNELOOPS "kerneloops"
CAnalyzerKerneloops::CAnalyzerKerneloops() :
m_sSysLogFile("/var/log/messages")
@@ -60,7 +61,7 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir)
std::stringstream m_sHash;
CDebugDump m_pDebugDump;
m_pDebugDump.Open(pDebugDumpDir);
- m_pDebugDump.LoadText(FILENAME_TEXTDATA1, m_sOops);
+ m_pDebugDump.LoadText(FILENAME_KERNELOOPS, m_sOops);
/* An algorithm proposed by Donald E. Knuth in The Art Of Computer
* Programming Volume 3, under the topic of sorting and search
@@ -110,7 +111,7 @@ void CAnalyzerKerneloops::Report()
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_TEXTDATA1, m_pOops.m_sData);
+ m_pDebugDump.SaveText(FILENAME_KERNELOOPS, m_pOops.m_sData);
m_pDebugDump.Close();
}
catch (std::string sError)
diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp
index 116fc8d..7121910 100644
--- a/lib/Plugins/KerneloopsReporter.cpp
+++ b/lib/Plugins/KerneloopsReporter.cpp
@@ -32,6 +32,8 @@
#include <string.h>
#include <curl/curl.h>
+#define FILENAME_KERNELOOPS "kerneloops"
+
CKerneloopsReporter::CKerneloopsReporter() :
m_sSubmitURL("http://submit.kerneloops.org/submitoops.php")
{}
@@ -66,7 +68,7 @@ void CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport)
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "oopsdata",
- CURLFORM_COPYCONTENTS, pCrashReport.find(FILENAME_TEXTDATA1)->second[CD_CONTENT].c_str(),
+ CURLFORM_COPYCONTENTS, pCrashReport.find(FILENAME_KERNELOOPS)->second[CD_CONTENT].c_str(),
CURLFORM_END);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "pass_on_allowed",
diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am
index 292918e..5475e32 100644
--- a/lib/Plugins/Makefile.am
+++ b/lib/Plugins/Makefile.am
@@ -14,7 +14,8 @@ dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf Kerneloops
# CCpp
libCCpp_la_SOURCES = CCpp.cpp CCpp.h PluginSettings.h
libCCpp_la_LDFLAGS = -avoid-version
-libCCpp_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\"
+libCCpp_la_LIBADD = $(NSS_LIBS)
+libCCpp_la_CPPFLAGS = -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