diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-23 18:26:33 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-23 18:26:33 +0100 |
commit | 3c3d9ab3a7a804d2b0460240a4c96362a14c13ed (patch) | |
tree | bd84dd3b21b1e1e50cdcdc7dd250400c3fd45427 /src | |
parent | 13997243816d57f77d7a3e36a26dad784e45d5f9 (diff) | |
download | abrt-3c3d9ab3a7a804d2b0460240a4c96362a14c13ed.tar.gz abrt-3c3d9ab3a7a804d2b0460240a4c96362a14c13ed.tar.xz abrt-3c3d9ab3a7a804d2b0460240a4c96362a14c13ed.zip |
remove socket code, it is dead
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/CLI/ABRTSocket.cpp | 155 | ||||
-rw-r--r-- | src/CLI/ABRTSocket.h | 47 | ||||
-rw-r--r-- | src/CLI/Makefile.am | 1 | ||||
-rw-r--r-- | src/Daemon/CommLayerServerSocket.cpp | 269 | ||||
-rw-r--r-- | src/Daemon/CommLayerServerSocket.h | 52 | ||||
-rw-r--r-- | src/Daemon/CrashWatcher.h | 6 | ||||
-rw-r--r-- | src/Daemon/Daemon.cpp | 4 | ||||
-rw-r--r-- | src/Daemon/Makefile.am | 1 |
8 files changed, 1 insertions, 534 deletions
diff --git a/src/CLI/ABRTSocket.cpp b/src/CLI/ABRTSocket.cpp deleted file mode 100644 index 61618c08..00000000 --- a/src/CLI/ABRTSocket.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "ABRTSocket.h" -#include "ABRTException.h" -#include "CrashTypesSocket.h" - -#include <string.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <string.h> - -CABRTSocket::CABRTSocket() : m_nSocket(-1) -{} - -CABRTSocket::~CABRTSocket() -{ - /* Paranoia. In C++, destructor will abort() if it was called while unwinding - * the stack and it throws an exception. - */ - try - { - Disconnect(); - } - catch (...) - { - error_msg_and_die("Internal error"); - } -} - -void CABRTSocket::Send(const std::string& pMessage) -{ - int ret = 0; - int len = pMessage.length(); - int offset = 0; - char* message = new char[len + 3]; - memcpy(message, pMessage.c_str(), len); - message[len] = MESSAGE_END_MARKER; - message[len + 1] = '\n'; - message[len + 2] = '\0'; - - while (ret != strlen(message + offset)) - { - offset += ret; - ret = send(m_nSocket, message + offset, strlen(message + offset), 0); - if (ret == -1) - { - throw CABRTException(EXCEP_FATAL, "CABRTSocket::Send(): Can not send data"); - } - } - delete[] message; -} - -void CABRTSocket::Recv(std::string& pMessage) -{ - std::string message; - bool receivingMessage = true; - char buff[1]; - int ret; - - pMessage = ""; - while (receivingMessage) - { - ret = recv(m_nSocket, buff, 1, 0); - if (ret == -1) - { - throw CABRTException(EXCEP_FATAL, "CABRTSocket::Recv(): Can not recv data"); - } - else if (ret == 0) - { - throw CABRTException(EXCEP_FATAL, "CABRTSocket::Recv(): Connection closed by abrt server"); - } - - message += buff[0]; - - if (message.length() > 2 && - message[message.length() - 2] == MESSAGE_END_MARKER && - message[message.length() - 1] == '\n') - { - receivingMessage = false; - message = message.substr(0, message.length() - 2); - } - } - pMessage = message; -} - - -void CABRTSocket::Connect(const std::string& pPath) -{ - int len; - struct sockaddr_un remote; - if ((m_nSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) - { - throw CABRTException(EXCEP_FATAL, "CABRTSocket::Connect(): Can not create socket"); - } - remote.sun_family = AF_UNIX; - strcpy(remote.sun_path, pPath.c_str()); - len = strlen(remote.sun_path) + sizeof(remote.sun_family); - if (connect(m_nSocket, (struct sockaddr *)&remote, len) == -1) - { - throw CABRTException(EXCEP_FATAL, "CABRTSocket::Connect(): Can not connect to remote"); - } -} - -void CABRTSocket::Disconnect() -{ - if (m_nSocket != -1) - close(m_nSocket); -} - -vector_map_crash_data_t CABRTSocket::GetCrashInfos() -{ - std::string message = MESSAGE_GET_CRASH_INFOS; - Send(message); - Recv(message); - message.erase(0, sizeof(MESSAGE_GET_CRASH_INFOS) - 1); - return string_to_crash_infos(message); -} - -map_crash_data_t CABRTSocket::CreateReport(const std::string &pUUID) -{ - std::string message = MESSAGE_CREATE_REPORT + pUUID; - Send(message); - Recv(message); - message.erase(0, sizeof(MESSAGE_CREATE_REPORT) - 1); - return string_to_crash_report(message); -} - -void CABRTSocket::Report(const map_crash_data_t& pReport) -{ - std::string message = MESSAGE_REPORT + crash_report_to_string(pReport); - Send(message); -} - -void CABRTSocket::DeleteDebugDump(const std::string& pUUID) -{ - std::string message = MESSAGE_DELETE_DEBUG_DUMP + pUUID; - Send(message); -} diff --git a/src/CLI/ABRTSocket.h b/src/CLI/ABRTSocket.h deleted file mode 100644 index f8fb42b8..00000000 --- a/src/CLI/ABRTSocket.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef ABRTSOCKET_H_ -#define ABRTSOCKET_H_ - -#include <string> - -#include "CrashTypes.h" - -class CABRTSocket -{ - private: - int m_nSocket; - - void Send(const char *pMessage); - void Recv(std::string& pMessage); - - public: - CABRTSocket(); - ~CABRTSocket(); - - void Connect(const char *pPath); - void Disconnect(); - - vector_map_crash_data_t GetCrashInfos(); - map_crash_data_t CreateReport(const char *pUUID); - void Report(const map_crash_data_t& pReport); - int32_t DeleteDebugDump(const char *pUUID); -}; - -#endif /* ABRTSOCKET_H_ */ diff --git a/src/CLI/Makefile.am b/src/CLI/Makefile.am index d12b69b1..361b64f7 100644 --- a/src/CLI/Makefile.am +++ b/src/CLI/Makefile.am @@ -1,6 +1,5 @@ bin_PROGRAMS = abrt-cli -# removed: ABRTSocket.h ABRTSocket.cpp abrt_cli_SOURCES = \ CLI.cpp \ run-command.h run-command.cpp \ diff --git a/src/Daemon/CommLayerServerSocket.cpp b/src/Daemon/CommLayerServerSocket.cpp deleted file mode 100644 index 1e8bf6ee..00000000 --- a/src/Daemon/CommLayerServerSocket.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include <sys/socket.h> -#include <sys/un.h> -#include "abrtlib.h" -#include "CommLayerInner.h" -#include "ABRTException.h" -#include "CrashTypesSocket.h" -#include "CrashWatcher.h" -#include "CommLayerServerSocket.h" - -void CCommLayerServerSocket::Send(const std::string& pData, GIOChannel *pDestination) -{ - ssize_t ret = -1; - gsize len = pData.length(); - int offset = 0; - GError *err = NULL; - 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; - ret = g_io_channel_write_chars(pDestination, message + offset, strlen(message + offset), &len, &err); - if (ret == G_IO_STATUS_ERROR) - { - error_msg("Error during sending data"); - } - } - - g_io_channel_flush(pDestination, &err); - delete[] message; -} - -std::string CCommLayerServerSocket::GetSenderUID(int pSenderSocket) -{ - struct ucred creds; - socklen_t len = sizeof(creds); - if (getsockopt(pSenderSocket, SOL_SOCKET, SO_PEERCRED, &creds, &len) == -1) - { - throw CABRTException(EXCEP_ERROR, "CCommLayerServerSocket::GetSenderUID(): error getting sender uid"); - } - return to_string(creds.uid); -} - -gboolean CCommLayerServerSocket::client_socket_cb(GIOChannel *source, GIOCondition condition, gpointer data) -{ - CCommLayerServerSocket* serverSocket = static_cast<CCommLayerServerSocket*>(data); - std::string senderUID = serverSocket->GetSenderUID(g_io_channel_unix_get_fd(source)); - gchar buff[1]; - gsize len; - GIOStatus ret; - GError *err = NULL; - bool receivingMessage = true; - std::string message = ""; - - if (condition & G_IO_HUP || - condition & G_IO_ERR || - condition & G_IO_NVAL) - { - log("Socket client disconnected"); - g_io_channel_unref(serverSocket->m_mapClientChannels[g_io_channel_unix_get_fd(source)]); - serverSocket->m_mapClientChannels.erase(g_io_channel_unix_get_fd(source)); - return FALSE; - } - - // TODO: rewrite this - while (receivingMessage) - { - ret = g_io_channel_read_chars(source, buff, 1, &len, &err); - if (ret == G_IO_STATUS_ERROR) - { - error_msg("Error while reading data from client socket: %s", err->message); - return FALSE; - } - message += buff[0]; - - if (message.length() > 2 && - message[message.length() - 2] == MESSAGE_END_MARKER && - message[message.length() - 1] == '\n') - { - receivingMessage = false; - message = message.substr(0, message.length() - 2); - } - } - - serverSocket->ProcessMessage(message, source); - return TRUE; -} - -gboolean CCommLayerServerSocket::server_socket_cb(GIOChannel *source, GIOCondition condition, gpointer data) -{ - CCommLayerServerSocket* serverSocket = static_cast<CCommLayerServerSocket*>(data); - int socket; - struct sockaddr_un remote; - socklen_t len = sizeof(remote); - - if (condition & G_IO_HUP || - condition & G_IO_ERR || - condition & G_IO_NVAL) - { - error_msg("Server socket error"); - return FALSE; - } - - if ((socket = accept(serverSocket->m_nSocket, (struct sockaddr *)&remote, &len)) == -1) - { - error_msg("Server can not accept client"); - return TRUE; - } - log("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), - static_cast<GIOFunc>(client_socket_cb), - data)) - { - error_msg("Can not init g_io_channel"); - return TRUE; - } - serverSocket->m_mapClientChannels[socket] = gSocket; - return TRUE; -} - -void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChannel *pSource) -{ - std::string UID = GetSenderUID(g_io_channel_unix_get_fd(pSource)); - - if (!strncmp(pMessage.c_str(), MESSAGE_GET_CRASH_INFOS, sizeof(MESSAGE_GET_CRASH_INFOS) - 1)) - { - vector_map_crash_data_t crashInfos = GetCrashInfos(UID); - std::string message = MESSAGE_GET_CRASH_INFOS + crash_infos_to_string(crashInfos); - Send(message, pSource); - } - else if (!strncmp(pMessage.c_str(), MESSAGE_REPORT, sizeof(MESSAGE_REPORT) - 1)) - { - std::string message = pMessage.substr(sizeof(MESSAGE_REPORT) - 1); - map_crash_data_t report = string_to_crash_report(message); - map_plugin_settings_t plugin_settings; - //FIXME: another hack to make this compile -// Report(report, plugin_settings, UID); - } - else if (!strncmp(pMessage.c_str(), MESSAGE_CREATE_REPORT, sizeof(MESSAGE_CREATE_REPORT) - 1)) - { -// std::string UUID = pMessage.substr(sizeof(MESSAGE_CREATE_REPORT) - 1); -// map_crash_data_t crashReport; -// CreateReport(UUID, UID, crashReport); -//use CreateReportThread instead of CreateReport? -// std::string message = MESSAGE_CREATE_REPORT + crash_report_to_string(crashReport); -// Send(message, pSource); - } - else if (!strncmp(pMessage.c_str(), MESSAGE_DELETE_DEBUG_DUMP, sizeof(MESSAGE_DELETE_DEBUG_DUMP) - 1)) - { - std::string UUID = pMessage.substr(sizeof(MESSAGE_DELETE_DEBUG_DUMP) - 1); - DeleteDebugDump(UUID, UID); - } - else - { - error_msg("Received unknown message type"); - } -} - -CCommLayerServerSocket::CCommLayerServerSocket() -: CCommLayerServer() -{ - struct sockaddr_un local; - - unlink(SOCKET_FILE); - m_nSocket = socket(AF_UNIX, SOCK_STREAM, 0); - if (m_nSocket == -1) - { - m_init_error = 1; - perror_msg("CCommLayerServerSocket: can't create AF_UNIX socket"); - return; - } - fcntl(m_nSocket, F_SETFD, FD_CLOEXEC); - - memset(&local, 0, sizeof(local)); - local.sun_family = AF_UNIX; - strcpy(local.sun_path, SOCKET_FILE); - if (bind(m_nSocket, (struct sockaddr *)&local, sizeof(local)) == -1) - { - m_init_error = 1; - perror_msg("CCommLayerServerSocket: can't bind AF_UNIX socket to '%s'", SOCKET_FILE); - return; - } - if (listen(m_nSocket, 5) == -1) - { - m_init_error = 1; - perror_msg("CCommLayerServerSocket: can't listen on AF_UNIX socket"); - return; - } - chmod(SOCKET_FILE, 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), - static_cast<GIOFunc>(server_socket_cb), - this)) - { - m_init_error = 1; - perror_msg("CCommLayerServerSocket: can't hook AF_UNIX socket to glb main loop"); - return; - } -} - -CCommLayerServerSocket::~CCommLayerServerSocket() -{ - g_io_channel_unref(m_pGSocket); - close(m_nSocket); -} - -vector_map_crash_data_t CCommLayerServerSocket::GetCrashInfos(const std::string &pSender) -{ - vector_map_crash_data_t crashInfos; - crashInfos = ::GetCrashInfos(pSender); - return crashInfos; -} - -//reimplement as CreateReportThread(...)? -//map_crash_data_t CCommLayerServerSocket::CreateReport(const std::string &pUUID, const std::string &pSender) -//{ -// map_crash_data_t crashReport; -// crashReport = ::CreateReport(pUUID, pSender); -// return crashReport; -//} - -report_status_t CCommLayerServerSocket::Report(const map_crash_data_t& pReport, const std::string& pSender) -{ - report_status_t rs; - //FIXME: a hack to make this compile, but we don't use sockets anyway - /* we could probably remove the sockets and rely only on dbus, - as it will become mandatory even on servers, but this needs some investigation - and more opinions - */ - //rs = ::Report(pReport, pSettings, pSender); - return rs; -} - -bool CCommLayerServerSocket::DeleteDebugDump(const std::string& pUUID, const std::string& pSender) -{ - ::DeleteDebugDump(pUUID, pSender); - return true; -} - -void CCommLayerServerSocket::Crash(const std::string& arg1) -{ - //Send("(CRASH)New Crash Detected: " + arg1); -} diff --git a/src/Daemon/CommLayerServerSocket.h b/src/Daemon/CommLayerServerSocket.h deleted file mode 100644 index 40f6f892..00000000 --- a/src/Daemon/CommLayerServerSocket.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "CommLayerServer.h" -#include "DBusCommon.h" -#include <glib.h> - -#define SOCKET_FILE VAR_RUN"/abrt.socket" -#define SOCKET_PERMISSION 0666 - -class CCommLayerServerSocket : public CCommLayerServer -{ - private: - typedef std::map<int, GIOChannel*> map_clinet_channels_t; - - int m_nSocket; - GIOChannel* m_pGSocket; - map_clinet_channels_t m_mapClientChannels; - - void Send(const std::string& pData, GIOChannel *pDestination); - - static gboolean server_socket_cb(GIOChannel *source, GIOCondition condition, gpointer data); - static gboolean client_socket_cb(GIOChannel *source, GIOCondition condition, gpointer data); - - std::string GetSenderUID(int pSenderSocket); - void ProcessMessage(const std::string& pMessage, GIOChannel *pSource); - - public: - CCommLayerServerSocket(); - virtual ~CCommLayerServerSocket(); - - virtual vector_map_crash_data_t GetCrashInfos(const char *pSender); - virtual report_status_t Report(const map_crash_data_t& pReport, const char *pSender); - virtual void DeleteDebugDump(const char *pUUID, const char *pSender); - - virtual void Crash(const char *arg1); -}; diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index 015bd70f..276adea8 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -26,11 +26,7 @@ #include "MiddleWare.h" #include "Settings.h" -#ifdef ENABLE_DBUS - #include "CommLayerServerDBus.h" -#elif ENABLE_SOCKET - #include "CommLayerServerSocket.h" -#endif +#include "CommLayerServerDBus.h" #include "CommLayerInner.h" diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 66f1d6e9..143d8b4e 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -849,12 +849,8 @@ int main(int argc, char** argv) /* Note: this already may process a few dbus messages, * therefore it should be the last thing to initialize. */ -#if 1 //def ENABLE_DBUS VERB1 log("Initializing dbus"); g_pCommLayer = new CCommLayerServerDBus(); -#elif ENABLE_SOCKET - g_pCommLayer = new CCommLayerServerSocket(); -#endif if (g_pCommLayer->m_init_error) throw 1; } diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index cb440277..c2347aec 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -2,7 +2,6 @@ bin_SCRIPTS = abrt-debuginfo-install sbin_PROGRAMS = abrtd -# disabled: CommLayerServerSocket.h CommLayerServerSocket.cpp abrtd_SOURCES = \ PluginManager.h PluginManager.cpp \ RPM.h RPM.cpp \ |