diff options
| author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-06-10 10:06:37 +0200 |
|---|---|---|
| committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-06-10 10:06:37 +0200 |
| commit | 5b80ac3bd83483cf937b13b222b55a0980ffdc39 (patch) | |
| tree | ec7cb1d37cbf740b41263d4e2c6dd14c78f9a229 /lib/CommLayer | |
| parent | 9eab929557ef4228b3335f4908dd6b4acf9251dc (diff) | |
| download | abrt-5b80ac3bd83483cf937b13b222b55a0980ffdc39.tar.gz abrt-5b80ac3bd83483cf937b13b222b55a0980ffdc39.tar.xz abrt-5b80ac3bd83483cf937b13b222b55a0980ffdc39.zip | |
abrt can take reporter's configuration file from reporting users's $HOME/.abrt/ directory
Diffstat (limited to 'lib/CommLayer')
| -rw-r--r-- | lib/CommLayer/CommLayerServer.h | 2 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerServerDBus.cpp | 5 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerServerDBus.h | 2 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerServerSocket.cpp | 44 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerServerSocket.h | 14 | ||||
| -rw-r--r-- | lib/CommLayer/Observer.h | 8 |
6 files changed, 40 insertions, 35 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_ */ |
