summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-05-28 14:20:09 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2009-05-28 14:20:09 +0200
commit012b25107c2b9cbc8d5ed37dd495d380bd74671f (patch)
tree58e756f1035ce9d5535c1a414306f84e46c2d498
parent3f914e8ea776aedb460fe0aade02f68c2e9be21d (diff)
parent49fe5dd21d832c7a27739f2885b24dfa638b3244 (diff)
downloadabrt-012b25107c2b9cbc8d5ed37dd495d380bd74671f.tar.gz
abrt-012b25107c2b9cbc8d5ed37dd495d380bd74671f.tar.xz
abrt-012b25107c2b9cbc8d5ed37dd495d380bd74671f.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
-rw-r--r--lib/MiddleWare/MiddleWare.cpp212
-rw-r--r--lib/MiddleWare/MiddleWare.h49
-rw-r--r--lib/MiddleWare/RPM.cpp4
-rw-r--r--lib/Utils/DebugDump.cpp28
-rw-r--r--lib/Utils/DebugDump.h2
-rw-r--r--src/Daemon/CrashWatcher.cpp143
6 files changed, 280 insertions, 158 deletions
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp
index 79e5d170..0cea374a 100644
--- a/lib/MiddleWare/MiddleWare.cpp
+++ b/lib/MiddleWare/MiddleWare.cpp
@@ -53,7 +53,6 @@ void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_c
!dd.Exist(FILENAME_RELEASE) ||
!dd.Exist(FILENAME_EXECUTABLE))
{
- dd.Delete();
dd.Close();
throw CABRTException(EXCEP_ERROR, "CMiddleWare::DebugDumpToCrashReport(): One or more of important file(s)'re missing.");
}
@@ -130,26 +129,28 @@ void CMiddleWare::CreateReport(const std::string& pAnalyzer,
return analyzer->CreateReport(pDebugDumpDir);
}
-int CMiddleWare::CreateCrashReport(const std::string& pUUID,
- const std::string& pUID,
- map_crash_report_t& pCrashReport)
+CMiddleWare::mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_report_t& pCrashReport)
{
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
database_row_t row;
database->Connect();
row = database->GetUUIDData(pUUID, pUID);
database->DisConnect();
+ CDebugDump dd;
if (pUUID == "" || row.m_sUUID != pUUID)
{
- throw CABRTException(EXCEP_ERROR, "CMiddleWare::CreateCrashReport(): UUID '"+pUUID+"' is not in database.");
+ comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): UUID '"+pUUID+"' is not in database.");
+ return MW_IN_DB_ERROR;
}
try
{
std::string analyzer;
std::string gUUID;
- CDebugDump dd;
+
dd.Open(row.m_sDebugDumpDir);
dd.LoadText(FILENAME_ANALYZER, analyzer);
dd.Close();
@@ -170,19 +171,19 @@ int CMiddleWare::CreateCrashReport(const std::string& pUUID,
}
catch (CABRTException& e)
{
- if (e.type() == EXCEP_DD_LOAD)
+ comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): " + e.what());
+ if (e.type() == EXCEP_DD_OPEN)
{
- DeleteCrashInfo(row.m_sUID, row.m_sUUID, true);
+ return MW_ERROR;
}
- else if (e.type() == EXCEP_DD_OPEN)
+ else if (e.type() == EXCEP_DD_LOAD)
{
- DeleteCrashInfo(row.m_sUUID, row.m_sUID, false);
+ return MW_FILE_ERROR;
}
- comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): " + e.what());
- return 0;
+ return MW_CORRUPTED;
}
- return 1;
+ return MW_OK;
}
void CMiddleWare::RunAction(const std::string& pActionDir,
@@ -294,9 +295,8 @@ void CMiddleWare::DeleteDebugDumpDir(const std::string& pDebugDumpDir)
dd.Close();
}
-void CMiddleWare::DeleteCrashInfo(const std::string& pUUID,
- const std::string& pUID,
- const bool bWithDebugDump)
+std::string CMiddleWare::DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID)
{
database_row_t row;
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
@@ -305,10 +305,7 @@ void CMiddleWare::DeleteCrashInfo(const std::string& pUUID,
database->Delete(pUUID, pUID);
database->DisConnect();
- if (bWithDebugDump)
- {
- DeleteDebugDumpDir(row.m_sDebugDumpDir);
- }
+ return row.m_sDebugDumpDir;
}
@@ -335,8 +332,8 @@ bool CMiddleWare::IsDebugDumpSaved(const std::string& pUID,
return found;
}
-int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutable,
- const std::string& pDebugDumpDir)
+CMiddleWare::mw_result_t CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutable,
+ const std::string& pDebugDumpDir)
{
std::string package;
std::string packageName;
@@ -355,22 +352,18 @@ int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutabl
if (packageName == "")
{
comm_layer_inner_debug("Executable doesn't belong to any package - deleting debug dump...");
+ return MW_PACKAGE_ERROR;
}
- else
- {
- comm_layer_inner_debug("Blacklisted package - deleting debug dump...");
- }
- DeleteDebugDumpDir(pDebugDumpDir);
- return 0;
+ comm_layer_inner_debug("Blacklisted package");
+ return MW_BLACKLISTED;
}
if (m_bOpenGPGCheck)
{
if (!m_RPM.CheckFingerprint(packageName) ||
!m_RPM.CheckHash(packageName, pExecutable))
{
- comm_layer_inner_debug("Can not find package - deleting debug dump...");
- DeleteDebugDumpDir(pDebugDumpDir);
- return 0;
+ comm_layer_inner_debug("Can not find package");
+ return MW_GPG_ERROR;
}
}
}
@@ -378,12 +371,25 @@ int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutabl
std::string description = m_RPM.GetDescription(packageName);
CDebugDump dd;
- dd.Open(pDebugDumpDir);
- dd.SaveText(FILENAME_PACKAGE, package);
- dd.SaveText(FILENAME_DESCRIPTION, description);
- dd.Close();
+ try
+ {
+ dd.Open(pDebugDumpDir);
+ dd.SaveText(FILENAME_PACKAGE, package);
+ dd.SaveText(FILENAME_DESCRIPTION, description);
+ dd.Close();
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::SavePackageDescriptionToDebugDump(): " + e.what());
+ if (e.type() == EXCEP_DD_SAVE)
+ {
+ dd.Close();
+ return MW_FILE_ERROR;
+ }
+ return MW_ERROR;
+ }
- return 1;
+ return MW_OK;
}
void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir)
@@ -416,14 +422,14 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st
}
}
-int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID,
- const std::string& pUID,
- const std::string& pTime,
- const std::string& pDebugDumpDir,
- map_crash_info_t& pCrashInfo)
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pTime,
+ const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo)
{
+ mw_result_t res;
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
-
database_row_t row;
database->Connect();
database->Insert(pUUID, pUID, pDebugDumpDir, pTime);
@@ -431,28 +437,26 @@ int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID,
database->DisConnect();
if (row.m_sReported == "1")
{
- comm_layer_inner_debug("Crash is already reported - deleting debug dump...");
- DeleteDebugDumpDir(pDebugDumpDir);
- return 0;
+ comm_layer_inner_debug("Crash is already reported");
+ return MW_REPORTED;
}
-
- pCrashInfo = GetCrashInfo(pUUID, pUID);
+ res = GetCrashInfo(pUUID, pUID, pCrashInfo);
if (row.m_sCount != "1")
{
- comm_layer_inner_debug("Crash is in database already - deleting debug dump...");
- DeleteDebugDumpDir(pDebugDumpDir);
- return 2;
+ comm_layer_inner_debug("Crash is in database already");
+ return MW_OCCURED;
}
- return 1;
+ return res;
}
-int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir)
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir)
{
map_crash_info_t info;
return SaveDebugDump(pDebugDumpDir, info);
}
-int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo)
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo)
{
std::string lUUID;
std::string UID;
@@ -460,6 +464,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_
std::string analyzer;
std::string executable;
CDebugDump dd;
+ mw_result_t res;
try
{
@@ -469,36 +474,37 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_
dd.LoadText(FILENAME_ANALYZER, analyzer);
dd.LoadText(FILENAME_EXECUTABLE, executable);
dd.Close();
-
- if (IsDebugDumpSaved(UID, pDebugDumpDir))
- {
- return 0;
- }
- if (!SavePackageDescriptionToDebugDump(executable, pDebugDumpDir))
- {
- return 0;
- }
-
- lUUID = GetLocalUUID(analyzer, pDebugDumpDir);
-
- return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo);
}
catch (CABRTException& e)
{
- if (e.type() == EXCEP_DD_LOAD ||
- e.type() == EXCEP_DD_SAVE)
+ comm_layer_inner_warning("CMiddleWare::SaveDebugDump(): " + e.what());
+ if (e.type() == EXCEP_DD_SAVE)
{
- DeleteDebugDumpDir(pDebugDumpDir);
+ dd.Close();
+ return MW_FILE_ERROR;
}
- comm_layer_inner_warning("CMiddleWare::SaveDebugDump(): " + e.what());
- return 0;
+ return MW_ERROR;
}
+
+ if (IsDebugDumpSaved(UID, pDebugDumpDir))
+ {
+ return MW_IN_DB;
+ }
+ if ((res = SavePackageDescriptionToDebugDump(executable, pDebugDumpDir)) != MW_OK)
+ {
+ return res;
+ }
+
+ lUUID = GetLocalUUID(analyzer, pDebugDumpDir);
+
+ return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo);
}
-map_crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID,
- const std::string& pUID)
+CMiddleWare::mw_result_t CMiddleWare::GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_info_t& pCrashInfo)
{
- map_crash_info_t crashInfo;
+ pCrashInfo.clear();
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
database_row_t row;
database->Connect();
@@ -506,39 +512,42 @@ map_crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID,
database->DisConnect();
CDebugDump dd;
+ std::string package;
+ std::string executable;
+ std::string description;
+
try
{
dd.Open(row.m_sDebugDumpDir);
+ dd.LoadText(FILENAME_EXECUTABLE, executable);
+ dd.LoadText(FILENAME_PACKAGE, package);
+ dd.LoadText(FILENAME_DESCRIPTION, description);
+ dd.Close();
}
catch (CABRTException& e)
{
- if (e.type() == EXCEP_DD_OPEN)
+ comm_layer_inner_warning("CMiddleWare::GetCrashInfo(): " + e.what());
+ if (e.type() == EXCEP_DD_LOAD)
{
- DeleteCrashInfo(row.m_sUUID, row.m_sUID, false);
+ dd.Close();
+ return MW_FILE_ERROR;
}
- comm_layer_inner_warning("CMiddleWare::GetCrashInfo(): " + e.what());
- return crashInfo;
+ return MW_ERROR;
}
-
- std::string data;
- dd.LoadText(FILENAME_EXECUTABLE, data);
- add_crash_data_to_crash_info(crashInfo, CD_EXECUTABLE, data);
- dd.LoadText(FILENAME_PACKAGE, data);
- add_crash_data_to_crash_info(crashInfo, CD_PACKAGE, data);
- dd.LoadText(FILENAME_DESCRIPTION, data);
- add_crash_data_to_crash_info(crashInfo, CD_DESCRIPTION, data);
- dd.Close();
- add_crash_data_to_crash_info(crashInfo, CD_UUID, row.m_sUUID);
- add_crash_data_to_crash_info(crashInfo, CD_UID, row.m_sUID);
- add_crash_data_to_crash_info(crashInfo, CD_COUNT, row.m_sCount);
- add_crash_data_to_crash_info(crashInfo, CD_TIME, row.m_sTime);
- add_crash_data_to_crash_info(crashInfo, CD_REPORTED, row.m_sReported);
- add_crash_data_to_crash_info(crashInfo, CD_MWDDD, row.m_sDebugDumpDir);
-
- return crashInfo;
+ add_crash_data_to_crash_info(pCrashInfo, CD_EXECUTABLE, executable);
+ add_crash_data_to_crash_info(pCrashInfo, CD_PACKAGE, package);
+ add_crash_data_to_crash_info(pCrashInfo, CD_DESCRIPTION, description);
+ add_crash_data_to_crash_info(pCrashInfo, CD_UUID, row.m_sUUID);
+ add_crash_data_to_crash_info(pCrashInfo, CD_UID, row.m_sUID);
+ add_crash_data_to_crash_info(pCrashInfo, CD_COUNT, row.m_sCount);
+ add_crash_data_to_crash_info(pCrashInfo, CD_TIME, row.m_sTime);
+ add_crash_data_to_crash_info(pCrashInfo, CD_REPORTED, row.m_sReported);
+ add_crash_data_to_crash_info(pCrashInfo, CD_MWDDD, row.m_sDebugDumpDir);
+
+ return MW_OK;
}
-vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID)
+vector_strings_t CMiddleWare::GetUUIDsOfCrash(const std::string& pUID)
{
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
vector_database_rows_t rows;
@@ -546,19 +555,14 @@ vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID)
rows = database->GetUIDData(pUID);
database->DisConnect();
- vector_crash_infos_t infos;
- std::string data;
+ vector_strings_t UUIDs;
int ii;
for (ii = 0; ii < rows.size(); ii++)
{
- map_crash_info_t info = GetCrashInfo(rows[ii].m_sUUID, rows[ii].m_sUID);
- if (info[CD_UUID][CD_CONTENT] != "")
- {
- infos.push_back(info);
- }
+ UUIDs.push_back(rows[ii].m_sUUID);
}
- return infos;
+ return UUIDs;
}
void CMiddleWare::SetOpenGPGCheck(const bool& pCheck)
diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h
index cad737a7..eb12df67 100644
--- a/lib/MiddleWare/MiddleWare.h
+++ b/lib/MiddleWare/MiddleWare.h
@@ -31,6 +31,20 @@
class CMiddleWare
{
+ public:
+
+ typedef enum { MW_ERROR,
+ MW_OK,
+ MW_BLACKLISTED,
+ MW_CORRUPTED,
+ MW_PACKAGE_ERROR,
+ MW_GPG_ERROR,
+ MW_REPORTED,
+ MW_OCCURED,
+ MW_IN_DB,
+ MW_IN_DB_ERROR,
+ MW_FILE_ERROR } mw_result_t;
+
private:
typedef set_strings_t set_blacklist_t;
typedef set_strings_t set_enabled_plugins_t;
@@ -58,14 +72,12 @@ class CMiddleWare
void DebugDumpToCrashReport(const std::string& pDebugDumpDir,
map_crash_report_t& pCrashReport);
bool IsDebugDumpSaved(const std::string& pUID, const std::string& pDebugDumpDir);
- int SavePackageDescriptionToDebugDump(const std::string& pExecutable, const std::string& pDebugDumpDir);
- int SaveDebugDumpToDatabase(const std::string& pUUID,
- const std::string& pUID,
- const std::string& pTime,
- const std::string& pDebugDumpDir,
- map_crash_info_t& pCrashInfo);
- map_crash_info_t GetCrashInfo(const std::string& pUUID,
- const std::string& pUID);
+ mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, const std::string& pDebugDumpDir);
+ mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pTime,
+ const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo);
public:
@@ -77,9 +89,9 @@ class CMiddleWare
void RegisterPlugin(const std::string& pName);
void UnRegisterPlugin(const std::string& pName);
- int CreateCrashReport(const std::string& pUUID,
- const std::string& pUID,
- map_crash_report_t& pCrashReport);
+ mw_result_t CreateCrashReport(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_report_t& pCrashReport);
void RunAction(const std::string& pActionDir,
const std::string& pPluginName,
@@ -88,15 +100,18 @@ class CMiddleWare
void Report(const map_crash_report_t& pCrashReport);
void DeleteDebugDumpDir(const std::string& pDebugDumpDir);
- void DeleteCrashInfo(const std::string& pUUID,
- const std::string& pUID,
- const bool bWithDebugDump = true);
+ std::string DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID);
- int SaveDebugDump(const std::string& pDebugDumpDir);
- int SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo);
+ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir);
+ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo);
- vector_crash_infos_t GetCrashInfos(const std::string& pUID);
+ mw_result_t GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_info_t& pCrashInfo);
+ vector_strings_t GetUUIDsOfCrash(const std::string& pUID);
void SetOpenGPGCheck(const bool& pCheck);
void SetDatabase(const std::string& pDatabase);
diff --git a/lib/MiddleWare/RPM.cpp b/lib/MiddleWare/RPM.cpp
index 4f2f5672..ff41852a 100644
--- a/lib/MiddleWare/RPM.cpp
+++ b/lib/MiddleWare/RPM.cpp
@@ -1,5 +1,5 @@
#include "RPM.h"
-#include <iostream>
+#include "CommLayerInner.h"
CRPM::CRPM()
{
@@ -20,7 +20,7 @@ void CRPM::LoadOpenGPGPublicKey(const std::string& pFileName)
if (pgpReadPkts(pFileName.c_str(), &pkt, &pklen) != PGPARMOR_PUBKEY)
{
free(pkt);
- std::cerr << "CRPM::LoadOpenGPGPublicKey(): Can not load public key " + pFileName << std::endl;
+ comm_layer_inner_warning("CRPM::LoadOpenGPGPublicKey(): Can not load public key " + pFileName);
return;
}
if (pgpPubkeyFingerprint(pkt, pklen, keyID) == 0)
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 1b7fbd1c..0ac9d796 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -61,11 +61,11 @@ void CDebugDump::Open(const std::string& pDir)
{
throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened.");
}
- m_sDebugDumpDir = pDir;
+ m_sDebugDumpDir = RemoveBackSlashes(pDir);
std::string lockPath = m_sDebugDumpDir + "/.lock";
- if (!ExistFileDir(pDir))
+ if (!ExistFileDir(m_sDebugDumpDir))
{
- throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+pDir+" does not exist.");
+ throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+m_sDebugDumpDir+" does not exist.");
}
Lock();
m_bOpened = true;
@@ -181,20 +181,20 @@ void CDebugDump::Create(const std::string& pDir)
throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened.");
}
- m_sDebugDumpDir = pDir;
- std::string lockPath = pDir + ".lock";
- if (ExistFileDir(pDir))
+ m_sDebugDumpDir = RemoveBackSlashes(pDir);
+ std::string lockPath = m_sDebugDumpDir + ".lock";
+ if (ExistFileDir(m_sDebugDumpDir))
{
- throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+pDir+" already exists.");
+ throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+m_sDebugDumpDir+" already exists.");
}
Lock();
m_bOpened = true;
- if (mkdir(pDir.c_str(), 0755) == -1)
+ if (mkdir(m_sDebugDumpDir.c_str(), 0755) == -1)
{
UnLock();
- throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot create dir: " + pDir);
+ throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create():m_sDebugDumpDir Cannot create dir: " + pDir);
}
SaveKernelArchitectureRelease();
@@ -268,6 +268,16 @@ bool CDebugDump::IsTextFile(const std::string& pName)
return isText;
}
+std::string CDebugDump::RemoveBackSlashes(const std::string& pDir)
+{
+ std::string ret = pDir;
+ while (ret[ret.length() - 1] == '/')
+ {
+ ret = ret.substr(0, ret.length() - 2);
+ }
+ return ret;
+}
+
void CDebugDump::Delete()
{
if (!ExistFileDir(m_sDebugDumpDir))
diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h
index 23c1fbdb..98780754 100644
--- a/lib/Utils/DebugDump.h
+++ b/lib/Utils/DebugDump.h
@@ -65,6 +65,8 @@ class CDebugDump
bool IsTextFile(const std::string& pName);
+ std::string RemoveBackSlashes(const std::string& pDir);
+
public:
CDebugDump();
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index ad497c93..9c95d380 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -53,7 +53,7 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
CCrashWatcher *cc = (CCrashWatcher*)daemon;
if (err != G_IO_ERROR_NONE)
{
- g_warning ("Error reading inotify fd: %d\n", err);
+ cc->Warning("Error reading inotify fd.");
return FALSE;
}
/* reconstruct each event and send message to the dbus */
@@ -77,11 +77,26 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
map_crash_info_t crashinfo;
try
{
- if(cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo))
+ CMiddleWare::mw_result_t res;
+ res = cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo);
+ switch (res)
{
- cc->m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]);
- /* send message to dbus */
- cc->m_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT]);
+ case CMiddleWare::MW_OK:
+ cc->m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]);
+ /* send message to dbus */
+ cc->m_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT]);
+ break;
+ case CMiddleWare::MW_BLACKLISTED:
+ case CMiddleWare::MW_CORRUPTED:
+ case CMiddleWare::MW_PACKAGE_ERROR:
+ case CMiddleWare::MW_GPG_ERROR:
+ case CMiddleWare::MW_REPORTED:
+ case CMiddleWare::MW_IN_DB:
+ case CMiddleWare::MW_FILE_ERROR:
+ default:
+ cc->Warning("Corrupted, bad or already saved crash, deleting");
+ cc->m_pMW->DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name);
+ break;
}
}
catch (CABRTException& e)
@@ -202,7 +217,7 @@ void CCrashWatcher::SetUpCron()
int nH = -1;
int nM = -1;
int nS = -1;
- time_t actTime = time(NULL);
+
if (pos != std::string::npos)
{
std::string sH = "";
@@ -364,6 +379,7 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath)
m_pCommLayer = new CCommLayerServerSocket();
#endif
m_pCommLayer = new CCommLayerServerDBus();
+// m_pCommLayer = new CCommLayerServerSocket();
m_pCommLayer->Attach(this);
if((m_nFd = inotify_init()) == -1)
@@ -425,19 +441,37 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath)
map_crash_info_t crashinfo;
try
{
- if(m_pMW->SaveDebugDump(*itt, crashinfo))
+ CMiddleWare::mw_result_t res;
+ res = m_pMW->SaveDebugDump(*itt, crashinfo);
+ switch (res)
{
- Debug("Saved new entry: " + *itt);
- m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]);
+ case CMiddleWare::MW_OK:
+ Debug("Saving into database (" + *itt + ").");
+ m_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]);
+ break;
+ case CMiddleWare::MW_IN_DB:
+ Debug("Already saved in database (" + *itt + ").");
+ break;
+ case CMiddleWare::MW_REPORTED:
+ case CMiddleWare::MW_OCCURED:
+ case CMiddleWare::MW_BLACKLISTED:
+ case CMiddleWare::MW_CORRUPTED:
+ case CMiddleWare::MW_PACKAGE_ERROR:
+ case CMiddleWare::MW_GPG_ERROR:
+ case CMiddleWare::MW_FILE_ERROR:
+ default:
+ Warning("Corrupted, bad or already saved crash, deleting.");
+ m_pMW->DeleteDebugDumpDir(*itt);
+ break;
}
}
catch (CABRTException& e)
{
- std::cerr << e.what() << std::endl;
if (e.type() == EXCEP_FATAL)
{
- exit(-1);
+ throw e;
}
+ Warning(e.what());
}
}
}
@@ -536,17 +570,51 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID)
Debug("Getting crash infos...");
try
{
- retval = m_pMW->GetCrashInfos(pUID);
+ vector_strings_t UUIDs;
+ UUIDs = m_pMW->GetUUIDsOfCrash(pUID);
+
+ unsigned int ii;
+ for (ii = 0; ii < UUIDs.size(); ii++)
+ {
+ CMiddleWare::mw_result_t res;
+ map_crash_info_t info;
+
+ res = m_pMW->GetCrashInfo(UUIDs[ii], pUID, info);
+ switch(res)
+ {
+ case CMiddleWare::MW_OK:
+ retval.push_back(info);
+ break;
+ case CMiddleWare::MW_ERROR:
+ Warning("Can not find debug dump directory for UUID: " + UUIDs[ii] + ", deleting from database");
+ Status("Can not find debug dump directory for UUID: " + UUIDs[ii] + ", deleting from database");
+ m_pMW->DeleteCrashInfo(UUIDs[ii], pUID);
+ break;
+ case CMiddleWare::MW_FILE_ERROR:
+ {
+ std::string debugDumpDir;
+ Warning("Can not open file in debug dump directory for UUID: " + UUIDs[ii] + ", deleting ");
+ Status("Can not open file in debug dump directory for UUID: " + UUIDs[ii] + ", deleting ");
+ debugDumpDir = m_pMW->DeleteCrashInfo(UUIDs[ii], pUID);
+ m_pMW->DeleteDebugDumpDir(debugDumpDir);
+ }
+ break;
+ default:
+ break;
+ }
+ }
}
catch (CABRTException& e)
{
- std::cerr << e.what() << std::endl;
- m_pCommLayer->Error(e.what());
if (e.type() == EXCEP_FATAL)
{
- exit(-1);
+ throw e;
}
+ Warning(e.what());
+ Status(e.what());
}
+
+ //retval = m_pMW->GetCrashInfos(pUID);
//Notify("Sent crash info");
return retval;
}
@@ -557,17 +625,38 @@ map_crash_report_t CCrashWatcher::CreateReport(const std::string &pUUID,const st
Debug("Creating report...");
try
{
- m_pMW->CreateCrashReport(pUUID,pUID,crashReport);
+ CMiddleWare::mw_result_t res;
+ res = m_pMW->CreateCrashReport(pUUID,pUID,crashReport);
+ switch (res)
+ {
+ case CMiddleWare::MW_OK:
+ break;
+ case CMiddleWare::MW_IN_DB_ERROR:
+ Warning("Did not find crash with UUID "+pUUID+" in database.");
+ Status("Did not find crash with UUID "+pUUID+" in database.");
+ break;
+ case CMiddleWare::MW_CORRUPTED:
+ case CMiddleWare::MW_FILE_ERROR:
+ default:
+ {
+ std::string debugDumpDir;
+ Warning("Corrupted crash with UUID "+pUUID+", deleting.");
+ Status("Corrupted crash with UUID "+pUUID+", deleting.");
+ debugDumpDir = m_pMW->DeleteCrashInfo(pUUID, pUID);
+ m_pMW->DeleteDebugDumpDir(debugDumpDir);
+ }
+ break;
+ }
m_pCommLayer->AnalyzeComplete(crashReport);
}
catch (CABRTException& e)
{
- std::cerr << e.what() << std::endl;
- m_pCommLayer->Error(e.what());
if (e.type() == EXCEP_FATAL)
{
- exit(-1);
+ throw e;
}
+ Warning(e.what());
+ Status(e.what());
}
return crashReport;
}
@@ -587,12 +676,12 @@ bool CCrashWatcher::Report(map_crash_report_t pReport)
}
catch (CABRTException& e)
{
- std::cerr << e.what() << std::endl;
- m_pCommLayer->Error(e.what());
if (e.type() == EXCEP_FATAL)
{
- exit(-1);
+ throw e;
}
+ Warning(e.what());
+ Status(e.what());
return false;
}
return true;
@@ -602,16 +691,18 @@ bool CCrashWatcher::DeleteDebugDump(const std::string& pUUID, const std::string&
{
try
{
- m_pMW->DeleteCrashInfo(pUUID,pUID, true);
+ std::string debugDumpDir;
+ debugDumpDir = m_pMW->DeleteCrashInfo(pUUID,pUID);
+ m_pMW->DeleteDebugDumpDir(debugDumpDir);
}
catch (CABRTException& e)
{
- std::cerr << e.what() << std::endl;
- m_pCommLayer->Error(e.what());
if (e.type() == EXCEP_FATAL)
{
- return -1;
+ throw e;
}
+ Warning(e.what());
+ Status(e.what());
return false;
}
return true;