summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-06-10 10:06:37 +0200
committerZdenek Prikryl <zprikryl@redhat.com>2009-06-10 10:06:37 +0200
commit5b80ac3bd83483cf937b13b222b55a0980ffdc39 (patch)
treeec7cb1d37cbf740b41263d4e2c6dd14c78f9a229 /lib
parent9eab929557ef4228b3335f4908dd6b4acf9251dc (diff)
abrt can take reporter's configuration file from reporting users's $HOME/.abrt/ directory
Diffstat (limited to 'lib')
-rw-r--r--lib/CommLayer/CommLayerServer.h2
-rw-r--r--lib/CommLayer/CommLayerServerDBus.cpp5
-rw-r--r--lib/CommLayer/CommLayerServerDBus.h2
-rw-r--r--lib/CommLayer/CommLayerServerSocket.cpp44
-rw-r--r--lib/CommLayer/CommLayerServerSocket.h14
-rw-r--r--lib/CommLayer/Observer.h8
-rw-r--r--lib/MiddleWare/MiddleWare.cpp63
-rw-r--r--lib/MiddleWare/MiddleWare.h13
8 files changed, 81 insertions, 70 deletions
diff --git a/lib/CommLayer/CommLayerServer.h b/lib/CommLayer/CommLayerServer.h
index 77cf7ef..6305e48 100644
--- a/lib/CommLayer/CommLayerServer.h
+++ b/lib/CommLayer/CommLayerServer.h
@@ -37,7 +37,7 @@ class CCommLayerServer{
virtual vector_crash_infos_t GetCrashInfos(const std::string &pSender) = 0;
virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pSender) = 0;
- virtual bool Report(map_crash_report_t pReport) = 0;
+ virtual bool Report(map_crash_report_t pReport,const std::string &pSender) = 0;
virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pSender) = 0;
public:
diff --git a/lib/CommLayer/CommLayerServerDBus.cpp b/lib/CommLayer/CommLayerServerDBus.cpp
index 8f4b3bf..cffd012 100644
--- a/lib/CommLayer/CommLayerServerDBus.cpp
+++ b/lib/CommLayer/CommLayerServerDBus.cpp
@@ -47,9 +47,10 @@ map_crash_report_t CCommLayerServerDBus::CreateReport(const std::string &pUUID,c
return crashReport;
}
-bool CCommLayerServerDBus::Report(map_crash_report_t pReport)
+bool CCommLayerServerDBus::Report(map_crash_report_t pReport,const std::string &pSender)
{
- m_pObserver->Report(pReport);
+ unsigned long unix_uid = m_pConn->sender_unix_uid(pSender.c_str());
+ m_pObserver->Report(pReport, to_string(unix_uid));
return true;
}
diff --git a/lib/CommLayer/CommLayerServerDBus.h b/lib/CommLayer/CommLayerServerDBus.h
index 3efe480..86f6860 100644
--- a/lib/CommLayer/CommLayerServerDBus.h
+++ b/lib/CommLayer/CommLayerServerDBus.h
@@ -21,7 +21,7 @@ class CCommLayerServerDBus
virtual vector_crash_infos_t GetCrashInfos(const std::string &pSender);
virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pSender);
- virtual bool Report(map_crash_report_t pReport);
+ virtual bool Report(map_crash_report_t pReport,const std::string &pSender);
virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pSender);
virtual void Crash(const std::string& arg1);
diff --git a/lib/CommLayer/CommLayerServerSocket.cpp b/lib/CommLayer/CommLayerServerSocket.cpp
index 74ba270..12db88c 100644
--- a/lib/CommLayer/CommLayerServerSocket.cpp
+++ b/lib/CommLayer/CommLayerServerSocket.cpp
@@ -1,26 +1,29 @@
#include "CommLayerServerSocket.h"
#include "CommLayerInner.h"
#include "ABRTException.h"
-#include "SocketCrashTypes.h"
+#include "CrashTypesSocket.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <iostream>
#include <sstream>
-
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
void CCommLayerServerSocket::Send(const std::string& pData, GIOChannel *pDestination)
{
ssize_t ret = -1;
- gsize len = 0;
+ gsize len = pData.length();
int offset = 0;
GError *err = NULL;
- gchar* message = new gchar[ pData.length() + 3 ];
- memcpy(message, pData.c_str(), pData.length());
- message[pData.length()] = ' ';
- message[pData.length() + 1] = '\n';
- message[pData.length() + 2] = '\0';
+ gchar* message = new gchar[len + 3];
+ memcpy(message, pData.c_str(), len);
+ message[len] = MESSAGE_END_MARKER;
+ message[len + 1] = '\n';
+ message[len + 2] = '\0';
+ len = 0;
while (len != strlen(message + offset))
{
offset += len;
@@ -80,10 +83,12 @@ gboolean CCommLayerServerSocket::client_socket_cb(GIOChannel *source, GIOConditi
}
message += buff[0];
- if (message.length() > 2 && /*message[message.length() - 2] == 23 &&*/ message[message.length() - 1] == '\n')
+ if (message.length() > 2 &&
+ message[message.length() - 2] == MESSAGE_END_MARKER &&
+ message[message.length() - 1] == '\n')
{
receivingMessage = false;
- message = message.substr(0, message.length() - 1);
+ message = message.substr(0, message.length() - 2);
}
}
@@ -111,7 +116,7 @@ gboolean CCommLayerServerSocket::server_socket_cb(GIOChannel *source, GIOConditi
comm_layer_inner_warning("Server can not accept client.");
return TRUE;
}
- comm_layer_inner_debug("New socket klinet connected.");
+ comm_layer_inner_debug("New socket client connected.");
GIOChannel* gSocket = g_io_channel_unix_new(socket);
if (!g_io_add_watch(gSocket,
static_cast<GIOCondition>(G_IO_IN |G_IO_PRI| G_IO_ERR | G_IO_HUP | G_IO_NVAL),
@@ -128,7 +133,7 @@ gboolean CCommLayerServerSocket::server_socket_cb(GIOChannel *source, GIOConditi
void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChannel *pSource)
{
std::string UID = GetSenderUID(g_io_channel_unix_get_fd(pSource));
- //TODO: rewrite to .compare()
+
if (!strncmp(pMessage.c_str(), MESSAGE_GET_CRASH_INFOS, sizeof(MESSAGE_GET_CRASH_INFOS) - 1))
{
vector_crash_infos_t crashInfos = GetCrashInfos(UID);
@@ -137,8 +142,9 @@ void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChan
}
else if (!strncmp(pMessage.c_str(), MESSAGE_REPORT, sizeof(MESSAGE_REPORT) - 1))
{
- map_crash_report_t report = string_to_crash_report(pMessage);
- Report(report);
+ std::string message = pMessage.substr(sizeof(MESSAGE_REPORT) - 1);
+ map_crash_report_t report = string_to_crash_report(message);
+ Report(report, UID);
}
else if (!strncmp(pMessage.c_str(), MESSAGE_CREATE_REPORT, sizeof(MESSAGE_CREATE_REPORT) - 1))
{
@@ -154,7 +160,7 @@ void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChan
}
else
{
- comm_layer_inner_warning(" Received unknown message type.");
+ comm_layer_inner_warning("Received unknown message type.");
}
}
@@ -168,7 +174,6 @@ CCommLayerServerSocket::CCommLayerServerSocket()
{
throw CABRTException(EXCEP_FATAL, "CCommLayerServerSocket::CCommLayerServerSocket(): Can not create socket.");
}
-
local.sun_family = AF_UNIX;
strcpy(local.sun_path, SOCKET_PATH);
unlink(local.sun_path);
@@ -182,6 +187,9 @@ CCommLayerServerSocket::CCommLayerServerSocket()
throw CABRTException(EXCEP_FATAL, "CCommLayerServerSocket::CCommLayerServerSocket(): Can not listen on the socket.");
}
+ fcntl(m_nSocket, F_SETFD, FD_CLOEXEC);
+ fchmod(m_nSocket, SOCKET_PERMISSION);
+
m_pGSocket = g_io_channel_unix_new(m_nSocket);
if (!g_io_add_watch(m_pGSocket,
static_cast<GIOCondition>(G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
@@ -212,9 +220,9 @@ map_crash_report_t CCommLayerServerSocket::CreateReport(const std::string &pUUID
return crashReport;
}
-bool CCommLayerServerSocket::Report(map_crash_report_t pReport)
+bool CCommLayerServerSocket::Report(map_crash_report_t pReport, const std::string& pSender)
{
- m_pObserver->Report(pReport);
+ m_pObserver->Report(pReport, pSender);
return true;
}
diff --git a/lib/CommLayer/CommLayerServerSocket.h b/lib/CommLayer/CommLayerServerSocket.h
index e816ada..9e165c7 100644
--- a/lib/CommLayer/CommLayerServerSocket.h
+++ b/lib/CommLayer/CommLayerServerSocket.h
@@ -2,11 +2,7 @@
#include <glib.h>
#define SOCKET_PATH "/tmp/abrt.socket"
-
-#define MESSAGE_DELETE_DEBUG_DUMP "(DELETE_DEBUG_DUMP)"
-#define MESSAGE_GET_CRASH_INFOS "(GET_CRASH_INFOS)"
-#define MESSAGE_REPORT "(REPORT)"
-#define MESSAGE_CREATE_REPORT "(CREATE_REPORT)"
+#define SOCKET_PERMISSION 0666
class CCommLayerServerSocket : public CCommLayerServer
{
@@ -29,10 +25,10 @@ class CCommLayerServerSocket : public CCommLayerServer
CCommLayerServerSocket();
virtual ~CCommLayerServerSocket();
- virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender);
- virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender);
- virtual bool Report(map_crash_report_t pReport);
- virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender);
+ virtual vector_crash_infos_t GetCrashInfos(const std::string &pSender);
+ virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pSender);
+ virtual bool Report(map_crash_report_t pReport, const std::string& pSender);
+ virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pSender);
virtual void Crash(const std::string& arg1);
virtual void AnalyzeComplete(map_crash_report_t arg1);
diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h
index d691bca..7803e8a 100644
--- a/lib/CommLayer/Observer.h
+++ b/lib/CommLayer/Observer.h
@@ -12,10 +12,10 @@ class CObserver {
virtual void Debug(const std::string& pMessage) = 0;
virtual void Warning(const std::string& pMessage) = 0;
/* this should be implemented in daemon */
- virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender) = 0;
- virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender) = 0;
- virtual bool Report(map_crash_report_t pReport) = 0;
- virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0;
+ virtual vector_crash_infos_t GetCrashInfos(const std::string &pSender) = 0;
+ virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pSender) = 0;
+ virtual bool Report(map_crash_report_t pReport, const std::string &pSender) = 0;
+ virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pSender) = 0;
};
#endif /* OBSERVER_H_ */
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp
index 9b4b088..78fc541 100644
--- a/lib/MiddleWare/MiddleWare.cpp
+++ b/lib/MiddleWare/MiddleWare.cpp
@@ -27,7 +27,8 @@
CMiddleWare::CMiddleWare(const std::string& pPlugisConfDir,
const std::string& pPlugisLibDir) :
m_pPluginManager(NULL),
- m_bOpenGPGCheck(true)
+ m_bOpenGPGCheck(true),
+ m_sPluginsConfDir(pPlugisConfDir)
{
m_pPluginManager = new CPluginManager(pPlugisConfDir, pPlugisLibDir);
m_pPluginManager->LoadPlugins();
@@ -193,14 +194,8 @@ void CMiddleWare::RunAction(const std::string& pActionDir,
try
{
CAction* action = m_pPluginManager->GetAction(pPluginName);
- if (action)
- {
- action->Run(pActionDir, pPluginArgs);
- }
- else
- {
- throw CABRTException(EXCEP_ERROR, "Plugin '"+pPluginName+"' is not registered.");
- }
+
+ action->Run(pActionDir, pPluginArgs);
}
catch (CABRTException& e)
{
@@ -217,33 +212,36 @@ void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir)
{
try
{
- CReporter* reporter = m_pPluginManager->GetReporter((*it_ar).first);
- CAction* action = m_pPluginManager->GetAction((*it_ar).first);
- if (reporter)
+ if (m_pPluginManager->GetPluginType((*it_ar).first) == REPORTER)
{
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_ar).first);
+
map_crash_report_t crashReport;
DebugDumpToCrashReport(pDebugDumpDir, crashReport);
reporter->Report(crashReport, (*it_ar).second);
}
- else if (action)
+ else if (m_pPluginManager->GetPluginType((*it_ar).first) == ACTION)
{
+ CAction* action = m_pPluginManager->GetAction((*it_ar).first);
action->Run(pDebugDumpDir, (*it_ar).second);
}
- else
- {
- throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_ar).first+"' is not registered.");
- }
}
catch (CABRTException& e)
{
comm_layer_inner_warning("CMiddleWare::RunActionsAndReporters(): " + e.what());
- comm_layer_inner_status("Reporting via '"+(*it_ar).first+"' was not successful: " + e.what());
+ comm_layer_inner_status("Activation of plugin '"+(*it_ar).first+"' was not successful: " + e.what());
}
}
}
void CMiddleWare::Report(const map_crash_report_t& pCrashReport)
{
+ Report(pCrashReport, m_sPluginsConfDir);
+}
+
+void CMiddleWare::Report(const map_crash_report_t& pCrashReport,
+ const std::string& pPluginsConfDir)
+{
if (pCrashReport.find(CD_MWANALYZER) == pCrashReport.end() ||
pCrashReport.find(CD_MWUID) == pCrashReport.end() ||
pCrashReport.find(CD_MWUUID) == pCrashReport.end())
@@ -263,14 +261,20 @@ void CMiddleWare::Report(const map_crash_report_t& pCrashReport)
{
try
{
- CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
- if (reporter)
+ if (m_pPluginManager->GetPluginType((*it_r).first) == REPORTER)
{
- reporter->Report(pCrashReport, (*it_r).second);
- }
- else
- {
- throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_r).first+"' is not registered.");
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
+
+ if (pPluginsConfDir == m_sPluginsConfDir)
+ {
+ reporter->Report(pCrashReport, (*it_r).second);
+ }
+ else
+ {
+ reporter->LoadSettings(pPluginsConfDir + "/" + (*it_r).first + "." + PLUGINS_CONF_EXTENSION);
+ reporter->Report(pCrashReport, (*it_r).second);
+ reporter->LoadSettings(m_sPluginsConfDir + "/" + (*it_r).first + "." + PLUGINS_CONF_EXTENSION);
+ }
}
}
catch (CABRTException& e)
@@ -403,15 +407,12 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st
{
try
{
- CAction* action = m_pPluginManager->GetAction((*it_a).first);
- if (action)
+ if (m_pPluginManager->GetPluginType((*it_a).first) == ACTION)
{
+ CAction* action = m_pPluginManager->GetAction((*it_a).first);
+
action->Run(pDebugDumpDir, (*it_a).second);
}
- else if (m_pPluginManager->GetReporter((*it_a).first) == NULL)
- {
- throw CABRTException(EXCEP_ERROR, "Plugin '"+(*it_a).first+"' is not registered.");
- }
}
catch (CABRTException& e)
{
diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h
index eb12df6..f817f00 100644
--- a/lib/MiddleWare/MiddleWare.h
+++ b/lib/MiddleWare/MiddleWare.h
@@ -59,7 +59,7 @@ class CMiddleWare
std::string m_sDatabase;
map_analyzer_actions_and_reporters_t m_mapAnalyzerActionsAndReporters;
vector_actions_and_reporters_t m_vectorActionsAndReporters;
-
+ std::string m_sPluginsConfDir;
bool m_bOpenGPGCheck;
std::string GetLocalUUID(const std::string& pAnalyzer,
@@ -68,11 +68,14 @@ class CMiddleWare
const std::string& pDebugDumpDir);
void CreateReport(const std::string& pAnalyzer,
const std::string& pDebugDumpDir);
- void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir);
+ void RunAnalyzerActions(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir);
void DebugDumpToCrashReport(const std::string& pDebugDumpDir,
map_crash_report_t& pCrashReport);
- bool IsDebugDumpSaved(const std::string& pUID, const std::string& pDebugDumpDir);
- mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, const std::string& pDebugDumpDir);
+ bool IsDebugDumpSaved(const std::string& pUID,
+ const std::string& pDebugDumpDir);
+ 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,
@@ -99,6 +102,8 @@ class CMiddleWare
void RunActionsAndReporters(const std::string& pDebugDumpDir);
void Report(const map_crash_report_t& pCrashReport);
+ void Report(const map_crash_report_t& pCrashReport,
+ const std::string& pSettingsPath);
void DeleteDebugDumpDir(const std::string& pDebugDumpDir);
std::string DeleteCrashInfo(const std::string& pUUID,
const std::string& pUID);