diff options
48 files changed, 1274 insertions, 878 deletions
@@ -25,7 +25,7 @@ RETVAL=0 check() { # Check that we're a privileged user [ `id -u` = 0 ] || exit 4 - + # Check if abrt is executable test -x /usr/sbin/abrt || exit 5 } @@ -33,14 +33,14 @@ check() { start() { check - + # Check if it is already running if [ ! -f /var/lock/subsys/abrt ]; then - echo -n $"Starting abrt daemon: " - daemon /usr/sbin/abrt - RETVAL=$? - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/abrt - echo + echo -n $"Starting abrt daemon: " + daemon /usr/sbin/abrt + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/abrt + echo fi return $RETVAL } @@ -48,24 +48,24 @@ start() { stop() { check - + echo -n $"Stopping abrt daemon: " killproc /usr/sbin/abrt RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/abrt echo - return $RETVAL + return $RETVAL } restart() { stop start -} +} reload() { restart -} +} case "$1" in start) @@ -24,8 +24,8 @@ BuildRequires: python-devel BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %description -%{name} is a tool to help users to detect defects in applications and -to create a bug report with all informations needed by maintainer to fix it. +%{name} is a tool to help users to detect defects in applications and +to create a bug report with all informations needed by maintainer to fix it. It uses plugin system to extend its functionality. %package libs @@ -59,7 +59,7 @@ Requires: gdb Requires: %{name} = %{version}-%{release} %description addon-ccpp -This package contains hook for C/C++ crashed programs and %{name}'s C/C++ +This package contains hook for C/C++ crashed programs and %{name}'s C/C++ analyzer plugin. %package addon-kerneloops @@ -89,7 +89,7 @@ Group: System Environment/Libraries Requires: %{name} = %{version}-%{release} %description plugin-sqlite3 -This package contains SQLite3 database plugin. It is used for storing the data +This package contains SQLite3 database plugin. It is used for storing the data required for creating a bug report. %package plugin-logger @@ -108,7 +108,7 @@ Requires: mailx %description plugin-mailx The simple reporter plugin, which sends a report via mailx to a specified -email. +email. %package plugin-runapp Summary: %{name}'s runapp plugin diff --git a/configure.ac b/configure.ac index 33e3cd3..8f37811 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ if test -z "$PYTHON"; then echo "*** Essential program python not found" 1>&2 exit 1 fi - + PKG_CHECK_MODULES([SQLITE3], [sqlite3]) PKG_CHECK_MODULES([GTK], [gtk+-2.0]) PKG_CHECK_MODULES([GLIB], [glib-2.0]) @@ -37,22 +37,22 @@ PLUGINS_LIB_DIR='${libdir}/${PACKAGE_NAME}' ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1' DEBUG_DUMPS_DIR='${localstatedir}/cache/${PACKAGE_NAME}' -AC_ARG_WITH(debugdumpsdir, +AC_ARG_WITH(debugdumpsdir, [AS_HELP_STRING([--with-debugdumpdir=DIR], [Directory where debugdumps are created])], [DEBUG_DUMPS_DIR="$withval"]) AC_ARG_ENABLE(socket, - [AC_HELP_STRING([--enable-socket], + [AC_HELP_STRING([--enable-socket], [Enable socket communication. Disable DBus communication])], [ENABLE_SOCKET_OR_DBUS='-DENABLE_SOCKET=1']) AC_ARG_ENABLE(dbus, - [AC_HELP_STRING([--enable-dbus], + [AC_HELP_STRING([--enable-dbus], [Enable DBus communication. Disable socket communication @<:@default@:>@])], [ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1']) - -AC_SUBST(ENABLE_SOCKET_OR_DBUS) + +AC_SUBST(ENABLE_SOCKET_OR_DBUS) AC_SUBST(CONF_DIR) AC_SUBST(VAR_RUN) AC_SUBST(PLUGINS_CONF_DIR) diff --git a/doc/CodingStyle b/doc/CodingStyle index 2cc2cf6..3a254b7 100644 --- a/doc/CodingStyle +++ b/doc/CodingStyle @@ -8,7 +8,7 @@ Coding style used in abrt 1.2 Method ----------- 1.2.1 method starts witch a capital letter -1.2.2 method name can contain only letters +1.2.2 method name can contain only letters 1.2.3 parameter of a method has to start with the letter 'p' 1.3 Attribute @@ -46,8 +46,8 @@ class CAwesomeClass COtherClass* m_pOtherClass; void PrivateFunction(int pParameter); public: - CAwesomeClass(std::string pName) : - m_sName(pName), m_pOtherClass(NULL) + CAwesomeClass(std::string pName) : + m_sName(pName), m_pOtherClass(NULL) {} }; diff --git a/doc/PLUGINS-HOWTO b/doc/PLUGINS-HOWTO index 2ca6b8e..ef0c6ba 100644 --- a/doc/PLUGINS-HOWTO +++ b/doc/PLUGINS-HOWTO @@ -32,7 +32,7 @@ virtual void Run(const std::string& pActiveDir, The first argument is a directory name. It can be either the current debug dump dir or a directory that contains all debug dumps. The second argument is a string with arguments specified for the action. - + Analyzer Plugin --------------- This plugin has to compute the UUID of the crash. Crashes differ, depending on @@ -106,7 +106,7 @@ virtual const vector_database_rows_t GetUIDData(const std::string& pUID) = 0; virtual const database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID) = 0; -- get a database row for the specified user ID and UUID +- get a database row for the specified user ID and UUID The macro PLUGIN_INFO diff --git a/inc/CrashTypesSocket.h b/inc/CrashTypesSocket.h index 45b7b29..df71f4d 100644 --- a/inc/CrashTypesSocket.h +++ b/inc/CrashTypesSocket.h @@ -23,8 +23,6 @@ #define SOCKETCRASHTYPES_H_ #include "CrashTypes.h" -#include <sstream> -#include <stdlib.h> /** * A request GET_CRASH_INFOS has the following form: @@ -72,132 +70,21 @@ #define MESSAGE_CREATE_REPORT "(CREATE_REPORT)" #define MESSAGE_END_MARKER 23 -inline std::string crash_data_to_string(const map_crash_data_t& pCrashData) -{ - std::stringstream sCD; - map_crash_data_t::const_iterator it_cd; - sCD << "(" << pCrashData.size() << ")"; - for(it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) - { - sCD << "(" << it_cd->first.length() << ")"; - sCD << it_cd->first; - sCD << "(" << it_cd->second[CD_TYPE].length() << ")"; - sCD << it_cd->second[CD_TYPE]; - sCD << "(" << it_cd->second[CD_EDITABLE].length() << ")"; - sCD << it_cd->second[CD_EDITABLE]; - sCD << "(" << it_cd->second[CD_CONTENT].length() << ")"; - sCD << it_cd->second[CD_CONTENT]; - } - return sCD.str(); -} - -inline std::string crash_infos_to_string(const vector_crash_infos_t& pCrashInfos) -{ - std::stringstream sCI; - unsigned int ii; - for (ii = 0; ii < pCrashInfos.size(); ii++) - { - sCI << crash_data_to_string(pCrashInfos[ii]); - } - return sCI.str(); -} - +std::string crash_infos_to_string(const vector_crash_infos_t& pCrashInfos); +std::string crash_data_to_string(const map_crash_data_t& pCrashData); inline std::string crash_report_to_string(const map_crash_report_t& pCrashReport) { return crash_data_to_string(pCrashReport); } -inline int get_number_from_string(const std::string& pMessage, int& len) -{ - std::string sNumber = ""; - - int ii = 1; - while (pMessage[ii] != ')') - { - sNumber += pMessage[ii]; - ii++; - if (static_cast<std::string::size_type>(ii) >= pMessage.length()) - { - len = ii; - return -1; - } - } - len = ii + 1; - return atoi(sNumber.c_str()); -} - -//TODO: remove constant 4 and place it in a message -inline map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len) -{ - map_crash_data_t ci; - std::string message = pMessage; - int nSize; - std::string sField; - int nField; - int nCount; - std::string name; - int ii; - - nCount = get_number_from_string(message, ii); - if (ii == -1) - { - len = ii; - return ci; - } - message.erase(0, ii); - len = ii; - nField = 0; - while (nField < nCount * 4) - { - nSize = get_number_from_string(message, ii); - if (ii == -1) - { - len += ii; - ci.clear(); - return ci; - } - sField = message.substr(ii, nSize); - message.erase(0, ii + nSize); - len += ii + nSize; - switch(nField % 4) - { - case 0: - name = sField; - break; - default: - ci[name].push_back(sField); - break; - } - nField++; - } - return ci; -} - -inline vector_crash_infos_t string_to_crash_infos(const std::string& pMessage) -{ - vector_crash_infos_t vci; - std::string message = pMessage; - int len; - - while (message != "") - { - map_crash_info_t crash_info = string_to_crash_data(message, len); - if (crash_info.size() == 0) - { - return vci; - } - vci.push_back(crash_info); - message.erase(0, len); - } - return vci; -} +int get_number_from_string(const std::string& pMessage, int& len); +vector_crash_infos_t string_to_crash_infos(const std::string& pMessage); +map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len); inline map_crash_report_t string_to_crash_report(const std::string& pMessage) { int len; - - map_crash_report_t crash_report = string_to_crash_data(pMessage, len); - return crash_report; + return string_to_crash_data(pMessage, len); } #endif /* SOCKETCRASHTYPES_H_ */ diff --git a/inc/abrtlib.h b/inc/abrtlib.h index ae86a66..29c8b5e 100644 --- a/inc/abrtlib.h +++ b/inc/abrtlib.h @@ -36,6 +36,8 @@ #endif #include <pwd.h> #include <grp.h> +/* C++ bits */ +#include <string> /* Some libc's forget to declare these, do it ourself */ extern char **environ; @@ -103,5 +105,11 @@ void xstat(const char *name, struct stat *stat_buf); void xmove_fd(int from, int to); char* xasprintf(const char *format, ...); +std::string ssprintf(const char *format, ...); + +/* copyfd_XX print read/write errors and return -1 if they occur */ +off_t copyfd_eof(int src_fd, int dst_fd); +off_t copyfd_size(int src_fd, int dst_fd, off_t size); +void copyfd_exact_size(int src_fd, int dst_fd, off_t size); #endif diff --git a/lib/CommLayer/DBusClientProxy.cpp b/lib/CommLayer/DBusClientProxy.cpp new file mode 100644 index 0000000..4f51172 --- /dev/null +++ b/lib/CommLayer/DBusClientProxy.cpp @@ -0,0 +1,238 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 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 "DBusClientProxy.h" +#include <iostream> + +namespace org { +namespace freedesktop { +namespace DBus { + +/* class DaemonWatcher_proxy */ + +/* public: */ + +DaemonWatcher_proxy::DaemonWatcher_proxy() +: ::DBus::InterfaceProxy("org.freedesktop.DBus") +{ + m_pStateChangeHandler_cb_data = NULL; + m_pStateChangeHandler = NULL; + connect_signal(DaemonWatcher_proxy, NameOwnerChanged , _DaemonStateChanged); +} + +void DaemonWatcher_proxy::ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data) +{ + m_pStateChangeHandler_cb_data = cb_data; + m_pStateChangeHandler = pStateChangeHandler; +} + +/* private: */ + +/* unmarshalers (to unpack the DBus message before calling the actual signal handler) + */ +void DaemonWatcher_proxy::_DaemonStateChanged(const ::DBus::SignalMessage &sig) +{ + ::DBus::MessageIter ri = sig.reader(); + std::string name; + std::string old_owner; + std::string new_owner; + ri >> name; + ri >> old_owner; + ri >> new_owner; + if(name.compare("com.redhat.abrt") == 0) + { + if(new_owner.length() > 0) + { + if(m_pStateChangeHandler) + { + m_pStateChangeHandler(true,m_pStateChangeHandler_cb_data); + } + else + { + std::cout << "Daemon appeared!" << std::endl; + } + } + if(new_owner.length() == 0) + { + if(m_pStateChangeHandler) + { + m_pStateChangeHandler(false, m_pStateChangeHandler_cb_data); + } + else + { + std::cout << "Daemon dissapeared!" << std::endl; + } + } + } +} + +} } } /* closing namespaces */ + + +/* class DaemonWatcher */ + +/* public: */ + +DaemonWatcher::DaemonWatcher(DBus::Connection &connection, const char *path, const char *name) +: ::DBus::ObjectProxy(connection, path, name) +{ +} +DaemonWatcher::~DaemonWatcher() +{ + std::cout << "~DaemonWatcher" << std::endl; +} + + +/* class CDBusClient_proxy */ + +/* public: */ + +CDBusClient_proxy::CDBusClient_proxy() +: DBus::InterfaceProxy(CC_DBUS_IFACE) +{ + connect_signal(CDBusClient_proxy, Crash, _Crash_stub); + connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); + m_sConnName = ""; +} + +CDBusClient_proxy::CDBusClient_proxy(::DBus::Connection &pConnection) +: DBus::InterfaceProxy(CC_DBUS_IFACE) +{ + gloop = g_main_loop_new(NULL, false); + //# define connect_signal(interface, signal, callback) + connect_signal(CDBusClient_proxy, Crash, _Crash_stub); + connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); + m_sConnName = pConnection.unique_name(); +} + +/* methods exported by this interface, + * this functions will invoke the corresponding methods on the remote objects + */ + /* + + < + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + ... + > + */ +vector_crash_infos_t CDBusClient_proxy::GetCrashInfos() +{ + DBus::CallMessage call; + DBus::MessageIter wi = call.writer(); + + call.member("GetCrashInfos"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); + + vector_crash_infos_t argout; + ri >> argout; + return argout; +} + +bool CDBusClient_proxy::DeleteDebugDump(const std::string& pUUID) +{ + DBus::CallMessage call; + + DBus::MessageIter wi = call.writer(); + + wi << pUUID; + call.member("DeleteDebugDump"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); + + bool argout; + ri >> argout; + return argout; +} + +map_crash_report_t CDBusClient_proxy::CreateReport(const std::string& pUUID) +{ + m_bJobDone = false; + DBus::CallMessage call; + + DBus::MessageIter wi = call.writer(); + + wi << pUUID; + call.member("CreateReport"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); + ri >> m_iPendingJobID; + //FIXME: what if the report is created before we start the loop? (we miss the signal and get stuck in the loop) + g_main_loop_run(gloop); + return GetJobResult(m_iPendingJobID); +}; + +void CDBusClient_proxy::Report(map_crash_report_t pReport) +{ + DBus::CallMessage call; + + DBus::MessageIter wi = call.writer(); + + wi << pReport; + call.member("Report"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); +} + +map_crash_report_t CDBusClient_proxy::GetJobResult(uint64_t pJobID) +{ + DBus::CallMessage call; + + DBus::MessageIter wi = call.writer(); + + wi << pJobID; + call.member("GetJobResult"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); + map_crash_report_t argout; + ri >> argout; + return argout; +} + +/* signal handlers for this interface + */ +void CDBusClient_proxy::Crash(std::string& value) +{ +} + +/* private: */ + +/* unmarshalers (to unpack the DBus message before calling the actual signal handler) + */ +void CDBusClient_proxy::_Crash_stub(const ::DBus::SignalMessage &sig) +{ + DBus::MessageIter ri = sig.reader(); + + std::string value; ri >> value; + Crash(value); +} + +void CDBusClient_proxy::_JobDone_stub(const ::DBus::SignalMessage &sig) +{ + DBus::MessageIter ri = sig.reader(); + std::string dest; + ri >> dest; + if(m_sConnName == dest) + { + ri >> m_iPendingJobID; + g_main_loop_quit(gloop); + } +} diff --git a/lib/CommLayer/DBusClientProxy.h b/lib/CommLayer/DBusClientProxy.h index 52ba75d..5b5c1fd 100644 --- a/lib/CommLayer/DBusClientProxy.h +++ b/lib/CommLayer/DBusClientProxy.h @@ -1,26 +1,28 @@ -/* - Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) - Copyright (C) 2009 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. +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 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 DBUSCLIENTPROXY_H_ +#define DBUSCLIENTPROXY_H_ + #include <dbus-c++/dbus.h> #include <dbus-c++/glib-integration.h> #include "DBusCommon.h" -#include <iostream> + #define ABRT_NOT_RUNNING 0 #define ABRT_RUNNING 1 @@ -29,68 +31,25 @@ namespace freedesktop { namespace DBus { class DaemonWatcher_proxy - : public ::DBus::InterfaceProxy +: public ::DBus::InterfaceProxy { private: void *m_pStateChangeHandler_cb_data; void (*m_pStateChangeHandler)(bool running, void* data); -public: - DaemonWatcher_proxy() - : ::DBus::InterfaceProxy("org.freedesktop.DBus") - { - m_pStateChangeHandler_cb_data = NULL; - m_pStateChangeHandler = NULL; - connect_signal(DaemonWatcher_proxy, NameOwnerChanged , _DaemonStateChanged); - } +public: + DaemonWatcher_proxy(); + void ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data); - void ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data) - { - m_pStateChangeHandler_cb_data = cb_data; - m_pStateChangeHandler = pStateChangeHandler; - } private: - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) */ - void _DaemonStateChanged(const ::DBus::SignalMessage &sig) - { - ::DBus::MessageIter ri = sig.reader(); - std::string name; - std::string old_owner; - std::string new_owner; - ri >> name; - ri >> old_owner; - ri >> new_owner; - if(name.compare("com.redhat.abrt") == 0){ - if(new_owner.length() > 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(true,m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon appeared!" << std::endl; - } - } - if(new_owner.length() == 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(false, m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon dissapeared!" << std::endl; - } - } - } - } + void _DaemonStateChanged(const ::DBus::SignalMessage &sig); }; } } } + class DaemonWatcher : public org::freedesktop::DBus::DaemonWatcher_proxy, public DBus::IntrospectableProxy, @@ -98,162 +57,52 @@ class DaemonWatcher { public: - DaemonWatcher(DBus::Connection &connection, const char *path, const char *name) - : ::DBus::ObjectProxy(connection, path, name) - { - } - ~DaemonWatcher() - { - std::cout << "~DaemonWatcher" << std::endl; - } + DaemonWatcher(DBus::Connection &connection, const char *path, const char *name); + ~DaemonWatcher(); }; - + class CDBusClient_proxy - : public DBus::InterfaceProxy +: public DBus::InterfaceProxy { private: bool m_bJobDone; uint64_t m_iPendingJobID; GMainLoop *gloop; std::string m_sConnName; -public: - - - CDBusClient_proxy() - : DBus::InterfaceProxy(CC_DBUS_IFACE) - { - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - m_sConnName = ""; - } - - CDBusClient_proxy(::DBus::Connection &pConnection) - : DBus::InterfaceProxy(CC_DBUS_IFACE) - { - gloop = g_main_loop_new(NULL, false); - //# define connect_signal(interface, signal, callback) - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - m_sConnName = pConnection.unique_name(); - } public: + CDBusClient_proxy(); + CDBusClient_proxy(::DBus::Connection &pConnection); +public: /* methods exported by this interface, * this functions will invoke the corresponding methods on the remote objects */ - /* - - < + /* + < <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> ... > - */ - vector_crash_infos_t GetCrashInfos() - { - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - call.member("GetCrashInfos"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - vector_crash_infos_t argout; - ri >> argout; - return argout; - } - - bool DeleteDebugDump(const std::string& pUUID) - { - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("DeleteDebugDump"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - bool argout; - ri >> argout; - return argout; - } - - map_crash_report_t CreateReport(const std::string& pUUID) - { - m_bJobDone = false; - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("CreateReport"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - ri >> m_iPendingJobID; - //FIXME: what if the report is created before we start the loop? (we miss the signal and get stuck in the loop) - g_main_loop_run(gloop); - return GetJobResult(m_iPendingJobID); - }; - - void Report(map_crash_report_t pReport) - { - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pReport; - call.member("Report"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - } - - map_crash_report_t GetJobResult(uint64_t pJobID) - { - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); + */ + vector_crash_infos_t GetCrashInfos(); + bool DeleteDebugDump(const std::string& pUUID); + map_crash_report_t CreateReport(const std::string& pUUID); + void Report(map_crash_report_t pReport); + map_crash_report_t GetJobResult(uint64_t pJobID); - wi << pJobID; - call.member("GetJobResult"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - map_crash_report_t argout; - ri >> argout; - return argout; - } - public: - /* signal handlers for this interface */ - virtual void Crash(std::string& value){} - -private: + virtual void Crash(std::string& value); +private: /* unmarshalers (to unpack the DBus message before calling the actual signal handler) */ - void _Crash_stub(const ::DBus::SignalMessage &sig) - { - DBus::MessageIter ri = sig.reader(); - - std::string value; ri >> value; - Crash(value); - } - - void _JobDone_stub(const ::DBus::SignalMessage &sig) - { - DBus::MessageIter ri = sig.reader(); - std::string dest; - ri >> dest; - if(m_sConnName == dest) - { - ri >> m_iPendingJobID; - g_main_loop_quit(gloop); - } - } + void _Crash_stub(const ::DBus::SignalMessage &sig); + void _JobDone_stub(const ::DBus::SignalMessage &sig); }; + +#endif diff --git a/lib/CommLayer/DBusServerProxy.cpp b/lib/CommLayer/DBusServerProxy.cpp new file mode 100644 index 0000000..6bf0fbd --- /dev/null +++ b/lib/CommLayer/DBusServerProxy.cpp @@ -0,0 +1,206 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 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 "DBusServerProxy.h" +#include <stdlib.h> + +/* public: */ + +CDBusServer_adaptor::CDBusServer_adaptor() +: DBus::InterfaceAdaptor(CC_DBUS_IFACE) +{ + register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub); + register_method(CDBusServer_adaptor, CreateReport, _CreateReport_stub); + register_method(CDBusServer_adaptor, Report, _Report_stub); + register_method(CDBusServer_adaptor, DeleteDebugDump, _DeleteDebugDump_stub); + register_method(CDBusServer_adaptor, GetJobResult, _GetJobResult_stub); + register_method(CDBusServer_adaptor, GetPluginsInfo, _GetPluginsInfo_stub); +} +/* reveal Interface introspection when we stabilize the API */ +/* +DBus::IntrospectedInterface *const CDBusServer_adaptor::introspect() const +{ + static DBus::IntrospectedArgument GetCrashInfos_args[] = + { + //{ "uid", "i", true}, + { "info", "a{ss}", false }, + { 0, 0, 0 } + }; + static DBus::IntrospectedArgument Crash_args[] = + { + { "package", "s", false }, + { 0, 0, 0 } + }; + static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] = + { + { "GetCrashInfos", GetCrashInfos_args }, + { 0, 0 }, + { "GetCrashInfosMap", GetCrashInfos_args }, + { 0, 0 } + }; + static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] = + { + { "Crash", Crash_args }, + { 0, 0 } + }; + static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] = + { + { 0, 0, 0, 0 } + }; + static DBus::IntrospectedInterface CDBusServer_adaptor_interface = + { + "com.redhat.abrt", + CDBusServer_adaptor_methods, + CDBusServer_adaptor_signals, + CDBusServer_adaptor_properties + }; + return &CDBusServer_adaptor_interface; +} +*/ + +/* public: */ + +/* signal emitters for this interface */ + +/* Notify the clients (UI) about a new crash */ +void CDBusServer_adaptor::Crash(const std::string& arg1) +{ + ::DBus::SignalMessage sig("Crash"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); +} + +/* Notify the clients that creating a report has finished */ +void CDBusServer_adaptor::AnalyzeComplete(map_crash_report_t arg1) +{ + ::DBus::SignalMessage sig("AnalyzeComplete"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); +} + +void CDBusServer_adaptor::JobDone(const std::string &pDest, uint64_t job_id) +{ + ::DBus::SignalMessage sig("JobDone"); + ::DBus::MessageIter wi = sig.writer(); + wi << pDest; + wi << job_id; + emit_signal(sig); +} + +void CDBusServer_adaptor::Error(const std::string& arg1) +{ + ::DBus::SignalMessage sig("Error"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); +} + +void CDBusServer_adaptor::Update(const std::string pDest, const std::string& pMessage) +{ + ::DBus::SignalMessage sig("Update"); + ::DBus::MessageIter wi = sig.writer(); + wi << pDest; + wi << pMessage; + emit_signal(sig); +} + +void CDBusServer_adaptor::Warning(const std::string& arg1) +{ + ::DBus::SignalMessage sig("Warning"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); +} + +/* private: */ + +/* unmarshalers (to unpack the DBus message before calling the actual interface method) + */ +DBus::Message CDBusServer_adaptor::_GetCrashInfos_stub(const DBus::CallMessage &call) +{ + DBus::MessageIter ri = call.reader(); + //FIXME: @@@REMOVE!! + vector_crash_infos_t argout1 = GetCrashInfos(call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; +} + +DBus::Message CDBusServer_adaptor::_CreateReport_stub(const DBus::CallMessage &call) +{ + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + uint64_t argout1 = CreateReport_t(argin1, call.sender()); + if(sizeof (uint64_t) != 8) abort (); + //map_crash_report_t argout1 = CreateReport(argin1,call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; +} + +DBus::Message CDBusServer_adaptor::_Report_stub(const DBus::CallMessage &call) +{ + DBus::MessageIter ri = call.reader(); + + map_crash_report_t argin1; ri >> argin1; + bool argout1 = Report(argin1, call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; +} + +DBus::Message CDBusServer_adaptor::_DeleteDebugDump_stub(const DBus::CallMessage &call) +{ + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + bool argout1 = DeleteDebugDump(argin1, call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; +} + +DBus::Message CDBusServer_adaptor::_GetJobResult_stub(const DBus::CallMessage &call) +{ + DBus::MessageIter ri = call.reader(); + uint64_t job_id; + ri >> job_id; + map_crash_report_t report = GetJobResult(job_id, call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << report; + return reply; +} + +DBus::Message CDBusServer_adaptor::_GetPluginsInfo_stub(const DBus::CallMessage &call) +{ + vector_map_string_string_t plugins_info; + plugins_info = GetPluginsInfo(); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << plugins_info; + return reply; +} diff --git a/lib/CommLayer/DBusServerProxy.h b/lib/CommLayer/DBusServerProxy.h index 157a95f..78fb28b 100644 --- a/lib/CommLayer/DBusServerProxy.h +++ b/lib/CommLayer/DBusServerProxy.h @@ -16,83 +16,35 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef DBUSSERVERPROXY_H_ +#define DBUSSERVERPROXY_H_ + #include <dbus-c++/dbus.h> #include <dbus-c++/glib-integration.h> #include "DBusCommon.h" -#include <map> -#include <iostream> -#include <stdlib.h> class CDBusServer_adaptor : public DBus::InterfaceAdaptor { public: - - CDBusServer_adaptor() - : DBus::InterfaceAdaptor(CC_DBUS_IFACE) - { - register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub); - register_method(CDBusServer_adaptor, CreateReport, _CreateReport_stub); - register_method(CDBusServer_adaptor, Report, _Report_stub); - register_method(CDBusServer_adaptor, DeleteDebugDump, _DeleteDebugDump_stub); - register_method(CDBusServer_adaptor, GetJobResult, _GetJobResult_stub); - register_method(CDBusServer_adaptor, GetPluginsInfo, _GetPluginsInfo_stub); - } + CDBusServer_adaptor(); /* reveal Interface introspection when we stabilize the API */ /* - DBus::IntrospectedInterface *const introspect() const - { - static DBus::IntrospectedArgument GetCrashInfos_args[] = - { - //{ "uid", "i", true}, - { "info", "a{ss}", false }, - { 0, 0, 0 } - }; - static DBus::IntrospectedArgument Crash_args[] = - { - { "package", "s", false }, - { 0, 0, 0 } - }; - static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] = - { - { "GetCrashInfos", GetCrashInfos_args }, - { 0, 0 }, - { "GetCrashInfosMap", GetCrashInfos_args }, - { 0, 0 } - }; - static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] = - { - { "Crash", Crash_args }, - { 0, 0 } - }; - static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] = - { - { 0, 0, 0, 0 } - }; - static DBus::IntrospectedInterface CDBusServer_adaptor_interface = - { - "com.redhat.abrt", - CDBusServer_adaptor_methods, - CDBusServer_adaptor_signals, - CDBusServer_adaptor_properties - }; - return &CDBusServer_adaptor_interface; - } + DBus::IntrospectedInterface *const introspect() const; */ -public: +public: /* properties exposed by this interface, use * property() and property(value) to get and set a particular property */ public: - /* methods exported by this interface, * you will have to implement them in your ObjectAdaptor */ 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 uint64_t CreateReport_t(const std::string &pUUID,const std::string &pDBusSender) = 0; + virtual map_crash_report_t CreateReport(const std::string &pUUID, const std::string &pDBusSender) = 0; + virtual uint64_t CreateReport_t(const std::string &pUUID, const std::string &pDBusSender) = 0; virtual bool Report(map_crash_report_t pReport, const std::string &pDBusSender) = 0; virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0; virtual map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pDBusSender) = 0; @@ -102,130 +54,23 @@ public: /* signal emitters for this interface */ /* Notify the clients (UI) about a new crash */ - void Crash(const std::string& arg1) - { - ::DBus::SignalMessage sig("Crash"); - ::DBus::MessageIter wi = sig.writer(); - wi << arg1; - emit_signal(sig); - } + void Crash(const std::string& arg1); /* Notify the clients that creating a report has finished */ - void AnalyzeComplete(map_crash_report_t arg1) - { - ::DBus::SignalMessage sig("AnalyzeComplete"); - ::DBus::MessageIter wi = sig.writer(); - wi << arg1; - emit_signal(sig); - } - - - void JobDone(const std::string &pDest, uint64_t job_id) - { - ::DBus::SignalMessage sig("JobDone"); - ::DBus::MessageIter wi = sig.writer(); - wi << pDest; - wi << job_id; - emit_signal(sig); - } - - void Error(const std::string& arg1) - { - ::DBus::SignalMessage sig("Error"); - ::DBus::MessageIter wi = sig.writer(); - wi << arg1; - emit_signal(sig); - } - - void Update(const std::string pDest, const std::string& pMessage) - { - ::DBus::SignalMessage sig("Update"); - ::DBus::MessageIter wi = sig.writer(); - wi << pDest; - wi << pMessage; - emit_signal(sig); - } - - void Warning(const std::string& arg1) - { - ::DBus::SignalMessage sig("Warning"); - ::DBus::MessageIter wi = sig.writer(); - wi << arg1; - emit_signal(sig); - } + void AnalyzeComplete(map_crash_report_t arg1); + void JobDone(const std::string &pDest, uint64_t job_id); + void Error(const std::string& arg1); + void Update(const std::string pDest, const std::string& pMessage); + void Warning(const std::string& arg1); private: - /* unmarshalers (to unpack the DBus message before calling the actual interface method) */ - DBus::Message _GetCrashInfos_stub(const DBus::CallMessage &call) - { - DBus::MessageIter ri = call.reader(); - //FIXME: @@@REMOVE!! - vector_crash_infos_t argout1 = GetCrashInfos(call.sender()); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << argout1; - return reply; - } - - DBus::Message _CreateReport_stub(const DBus::CallMessage &call) - { - DBus::MessageIter ri = call.reader(); - - std::string argin1; ri >> argin1; - uint64_t argout1 = CreateReport_t(argin1,call.sender()); - if(sizeof (uint64_t) != 8) abort (); - //map_crash_report_t argout1 = CreateReport(argin1,call.sender()); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << argout1; - return reply; - } - - DBus::Message _Report_stub(const DBus::CallMessage &call) - { - DBus::MessageIter ri = call.reader(); - - map_crash_report_t argin1; ri >> argin1; - bool argout1 = Report(argin1, call.sender()); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << argout1; - return reply; - } - - DBus::Message _DeleteDebugDump_stub(const DBus::CallMessage &call) - { - DBus::MessageIter ri = call.reader(); - - std::string argin1; ri >> argin1; - bool argout1 = DeleteDebugDump(argin1,call.sender()); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << argout1; - return reply; - } - - DBus::Message _GetJobResult_stub(const DBus::CallMessage &call) - { - DBus::MessageIter ri = call.reader(); - uint64_t job_id; - ri >> job_id; - map_crash_report_t report = GetJobResult(job_id,call.sender()); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << report; - return reply; - } - - DBus::Message _GetPluginsInfo_stub(const DBus::CallMessage &call) - { - vector_map_string_string_t plugins_info; - plugins_info = GetPluginsInfo(); - DBus::ReturnMessage reply(call); - DBus::MessageIter wi = reply.writer(); - wi << plugins_info; - return reply; - } + DBus::Message _GetCrashInfos_stub(const DBus::CallMessage &call); + DBus::Message _CreateReport_stub(const DBus::CallMessage &call); + DBus::Message _Report_stub(const DBus::CallMessage &call); + DBus::Message _DeleteDebugDump_stub(const DBus::CallMessage &call); + DBus::Message _GetJobResult_stub(const DBus::CallMessage &call); + DBus::Message _GetPluginsInfo_stub(const DBus::CallMessage &call); }; +#endif diff --git a/lib/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am index 5a1fa50..f80683b 100644 --- a/lib/CommLayer/Makefile.am +++ b/lib/CommLayer/Makefile.am @@ -1,20 +1,31 @@ lib_LTLIBRARIES = libABRTCommLayer.la -libABRTCommLayer_la_SOURCES = CommLayerServer.h CommLayerServer.cpp \ - CommLayerServerSocket.h CommLayerServerSocket.cpp \ - CommLayerServerDBus.h CommLayerServerDBus.cpp \ - DBusServerProxy.h Observer.h DBusCommon.h \ - CommLayerInner.h CommLayerInner.cpp \ - DBusClientProxy.h CommLayerClientDBus.h CommLayerClientDBus.cpp - -libABRTCommLayer_la_LIBADD = ../../lib/MiddleWare/libABRTMiddleWare.la $(DL_LIBS) $(DBUSCPP_LIBS) + +libABRTCommLayer_la_SOURCES = \ + CommLayerServer.h CommLayerServer.cpp \ + CommLayerServerSocket.h CommLayerServerSocket.cpp \ + CommLayerServerDBus.h CommLayerServerDBus.cpp \ + DBusServerProxy.h DBusServerProxy.cpp \ + DBusClientProxy.h DBusClientProxy.cpp \ + CommLayerInner.h CommLayerInner.cpp \ + CommLayerClientDBus.h CommLayerClientDBus.cpp \ + Observer.h \ + DBusCommon.h +libABRTCommLayer_la_LIBADD = \ + ../../lib/MiddleWare/libABRTMiddleWare.la \ + $(DL_LIBS) $(DBUSCPP_LIBS) libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 -libABRTCommLayer_la_CPPFLAGS = -Wall -Werror -I$(srcdir)/../../lib/MiddleWare\ - -I$(srcdir)/../../lib/DBus -I$(srcdir)/../../inc\ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ - -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ - -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ - -DCONF_DIR=\"$(CONF_DIR)\" -D_GNU_SOURCE \ - -DVAR_RUN=\"$(VAR_RUN)\" +libABRTCommLayer_la_CPPFLAGS = \ + -Wall -Werror \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/MiddleWare \ + -I$(srcdir)/../../lib/DBus \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ + -D_GNU_SOURCE #check_PROGRAMS = test #test_SOURCES = test.cpp diff --git a/lib/MiddleWare/Makefile.am b/lib/MiddleWare/Makefile.am index 016d6ea..b84dcba 100644 --- a/lib/MiddleWare/Makefile.am +++ b/lib/MiddleWare/Makefile.am @@ -1,20 +1,37 @@ lib_LTLIBRARIES = libABRTMiddleWare.la -libABRTMiddleWare_la_SOURCES = MiddleWare.cpp MiddleWare.h PluginManager.cpp \ - PluginManager.h ABRTPlugin.cpp \ - ABRTPlugin.h DynamicLibrary.cpp \ - DynamicLibrary.h \ - RPM.cpp RPM.h Plugin.h \ - MiddleWareTypes.h Action.h Database.h \ - Reporter.h Analyzer.h -libABRTMiddleWare_la_LIBADD = $(DL_LIBS) ../Utils/libABRTUtils.la $(RPM_LIBS) + +libABRTMiddleWare_la_SOURCES = \ + ABRTPlugin.cpp ABRTPlugin.h \ + DynamicLibrary.cpp DynamicLibrary.h \ + RPM.cpp RPM.h \ + Plugin.h MiddleWareTypes.h Action.h Database.h \ + Reporter.h Analyzer.h +libABRTMiddleWare_la_LIBADD = \ + $(DL_LIBS) \ + ../Utils/libABRTUtils.la \ + $(RPM_LIBS) libABRTMiddleWare_la_LDFLAGS = -version-info 0:1:0 -libABRTMiddleWare_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer $(RPM_CFLAGS) +libABRTMiddleWare_la_CPPFLAGS = \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../Utils \ + -I$(srcdir)/../CommLayer \ + $(RPM_CFLAGS) -check_PROGRAMS = test -test_SOURCES = test.cpp -test_LDADD = ../Utils/libABRTUtils.la libABRTMiddleWare.la $(DL_LIBS) $(RPM_LIBS) ../CommLayer/libABRTCommLayer.la -test_CPPFLAGS = -I$(srcdir)/../Utils -I$(srcdir)/../../inc -I$(srcdir)/../CommLayer\ - -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ - -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DCONF_DIR=\"$(CONF_DIR)\" +# disabled: MiddleWare.* is moved to src/Daemon/ now +# +#check_PROGRAMS = test +# +#test_SOURCES = test.cpp +#test_LDADD = \ +# ../Utils/libABRTUtils.la \ +# ../CommLayer/libABRTCommLayer.la \ +# libABRTMiddleWare.la \ +# $(DL_LIBS) $(RPM_LIBS) +#test_CPPFLAGS = \ +# -I$(srcdir)/../../inc \ +# -I$(srcdir)/../Utils \ +# -I$(srcdir)/../CommLayer\ +# -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ +# -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ +# -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ +# -DCONF_DIR=\"$(CONF_DIR)\" diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 026e15a..a47ca38 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -527,19 +527,20 @@ void CAnalyzerCCpp::Init() } if (m_sOldCorePattern[0] == '|') { - if (m_sOldCorePattern == CORE_PATTERN) - { - log("warning: %s already contains %s, " - "did abrt daemon crash recently?", - CORE_PATTERN_IFACE, CORE_PATTERN); - /* There is no point in "restoring" CORE_PATTERN_IFACE - * to CORE_PATTERN on exit. Will restore to a default value: - */ - m_sOldCorePattern = "core"; - } - log("warning: %s was already set to run a crash analyser (%s), " - "abrt may interfere with it", - CORE_PATTERN_IFACE, CORE_PATTERN); + if (m_sOldCorePattern == CORE_PATTERN) + { + log("warning: %s already contains %s, " + "did abrt daemon crash recently?", + CORE_PATTERN_IFACE, CORE_PATTERN); + /* There is no point in "restoring" CORE_PATTERN_IFACE + * to CORE_PATTERN on exit. Will restore to a default value: + */ + m_sOldCorePattern = "core"; + } else { + log("warning: %s was already set to run a crash analyser (%s), " + "abrt may interfere with it", + CORE_PATTERN_IFACE, CORE_PATTERN); + } } std::ofstream fOutCorePattern; diff --git a/lib/Plugins/FileTransfer.conf b/lib/Plugins/FileTransfer.conf index cf675e4..75e5671 100644 --- a/lib/Plugins/FileTransfer.conf +++ b/lib/Plugins/FileTransfer.conf @@ -1,6 +1,6 @@ # Configuration of the file transfer reporter plugin # it takes one parameter: -# store - just save information about crash +# store - just save information about crash # upload - upload new crash or saved crashes to the specified url # URL to upload the files to diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 00d5803..f696a99 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -62,7 +62,7 @@ void CKerneloopsScanner::SaveOopsToDebugDump() try { - debugDump.Create(path, "0"); + debugDump.Create(path, 0); debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops"); debugDump.SaveText(FILENAME_EXECUTABLE, "kernel"); debugDump.SaveText(FILENAME_KERNEL, oops.m_sVersion); diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 7c1ddbb..a061688 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -31,40 +31,40 @@ install-data-hook: $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf # CCpp -libCCpp_la_SOURCES = CCpp.cpp CCpp.h +libCCpp_la_SOURCES = CCpp.cpp CCpp.h libCCpp_la_LDFLAGS = -avoid-version libCCpp_la_LIBADD = $(NSS_LIBS) libCCpp_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -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 +libKerneloops_la_SOURCES = Kerneloops.cpp Kerneloops.h libKerneloops_la_LDFLAGS = -avoid-version libKerneloops_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils # KerneloopsReporter -libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h +libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h libKerneloopsReporter_la_LDFLAGS = -avoid-version libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # KerneloopsScanner -libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h +libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h libKerneloopsScanner_la_LDFLAGS = -avoid-version libKerneloopsScanner_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" # Mailx -libMailx_la_SOURCES = Mailx.cpp Mailx.h +libMailx_la_SOURCES = Mailx.cpp Mailx.h libMailx_la_LDFLAGS = -avoid-version libMailx_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" # SQLite3 -libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h +libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h libSQLite3_la_LDFLAGS = -avoid-version libSQLite3_la_LIBADD = $(SQLITE3_LIBS) libSQLite3_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"' # Logger -libLogger_la_SOURCES = Logger.cpp Logger.h +libLogger_la_SOURCES = Logger.cpp Logger.h libLogger_la_LDFLAGS = -avoid-version libLogger_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" @@ -77,7 +77,7 @@ libSOSreport_la_SOURCES = SOSreport.cpp SOSreport.h libSOSreport_la_LDFLAGS = -avoid-version # Bugzilla -libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp +libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) $(NSS_LIBS) libBugzilla_la_LDFLAGS = -avoid-version libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" @@ -89,7 +89,7 @@ libPython_la_LDFLAGS = -avoid-version libPython_la_CPPFLAGS = $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils # FileTrasfer -libFileTransfer_la_SOURCES = FileTransfer.cpp FileTransfer.h +libFileTransfer_la_SOURCES = FileTransfer.cpp FileTransfer.h libFileTransfer_la_LDFLAGS = -avoid-version libFileTransfer_la_LIBADD = $(CURL_LIBS) libFileTransfer_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(CURL_CFLAGS) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" diff --git a/lib/Plugins/abrt-Bugzilla.7 b/lib/Plugins/abrt-Bugzilla.7 index c3c0e90..99bb60d 100644 --- a/lib/Plugins/abrt-Bugzilla.7 +++ b/lib/Plugins/abrt-Bugzilla.7 @@ -5,15 +5,15 @@ Bugzilla plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIBugzilla\fP plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIBugzilla\fP plugin for \fIabrt\fP. .P -This plugin is used to report the crash to a Bugzilla instance. The -plugin will determine the package name and distribution version. The +This plugin is used to report the crash to a Bugzilla instance. The +plugin will determine the package name and distribution version. The crash data is attached to the bug report. .SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. +The plugin is invoked in the \fIabrt.conf\fP configuration file. No parameters are necessary. .SH CONFIGURATION The \fIBugzilla.conf\fP configuration file contains several @@ -39,5 +39,5 @@ ActionsAndReporters = Bugzilla .IR abrt.conf (5), .IR abrt-plugins (7) .SH AUTHOR -Written by Zdenek Prikryl <zprikryl@redhat.com>. +Written by Zdenek Prikryl <zprikryl@redhat.com>. Manual page written by Daniel Novotny <dnovotny@redhat.com>. diff --git a/lib/Plugins/abrt-FileTransfer.7 b/lib/Plugins/abrt-FileTransfer.7 index b126c2c..a04dd42 100644 --- a/lib/Plugins/abrt-FileTransfer.7 +++ b/lib/Plugins/abrt-FileTransfer.7 @@ -5,18 +5,18 @@ FileTransfer plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIFileTransfer\fP plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIFileTransfer\fP plugin for \fIabrt\fP. .P This plugin is used to transfer the crash report to another machine using a file transfer protocol. The protocols supported -are FTP, FTPS, HTTP, HTTPS, SCP, SFTP, and TFTP. +are FTP, FTPS, HTTP, HTTPS, SCP, SFTP, and TFTP. .SH INVOCATION .P The plugin is invoked in the \fIabrt.conf\fP file, usually in the \fIActionsAndReporters\fP option and/or the \fI[cron]\fP section. -There are two modes of invocation: +There are two modes of invocation: .P * If you use the parameter \fI"store"\fP, the plugin stores a record of the occurrence of @@ -27,12 +27,12 @@ plugin will iterate through the internal list and will send every recorded crash to the server specified in the \fIFileTransfer.conf\fP configuration file. After that, the internal list is cleared. .P -On a production machine, you probably do not want the daemon to send crash +On a production machine, you probably do not want the daemon to send crash data at times that the machine is busy working. This second mode allows you -to send crash reports at a quieter time (at night, perhaps) that you +to send crash reports at a quieter time (at night, perhaps) that you schedule in the \fI[cron]\fP section of \fIabrt.conf\fP. .SH CONFIGURATION -The \fIFileTransfer.conf\fP configuration file contains +The \fIFileTransfer.conf\fP configuration file contains several entries in the format "Option = Value". The options are: .SS URL The URL of the server, where the crash should @@ -41,7 +41,7 @@ the user name and the password, for example: .br URL = ftp://user:passwd@server.com/path .SS ArchiveType -The type of the archive in which to pack the crash data. +The type of the archive in which to pack the crash data. Currently, \fI.tar.gz\fP, \fI.tar.bz2\fP and \fI.zip\fP are supported. The plugin currently relies on external file archiving commandline utilities, which will create the archive. diff --git a/lib/Plugins/abrt-KerneloopsReporter.7 b/lib/Plugins/abrt-KerneloopsReporter.7 index e0d32c3..98bd387 100644 --- a/lib/Plugins/abrt-KerneloopsReporter.7 +++ b/lib/Plugins/abrt-KerneloopsReporter.7 @@ -5,13 +5,13 @@ KerneloopsReporter plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIKerneloopsReporter\fP +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIKerneloopsReporter\fP plugin for \fIabrt\fP. .P This plugin is used to report the crash to the Kerneloops tracker. .SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. +The plugin is invoked in the \fIabrt.conf\fP configuration file. No parameters are necessary. .SH CONFIGURATION The \fIKerneloopsReporter.conf\fP configuration file contains one entry: diff --git a/lib/Plugins/abrt-KerneloopsScanner.7 b/lib/Plugins/abrt-KerneloopsScanner.7 index d9642a9..ff09484 100644 --- a/lib/Plugins/abrt-KerneloopsScanner.7 +++ b/lib/Plugins/abrt-KerneloopsScanner.7 @@ -5,8 +5,8 @@ KerneloopsScanner plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIKerneloopsScanner\fP +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIKerneloopsScanner\fP plugin for \fIabrt\fP. .P This plugin reads the system log file (default /var/log/messages) @@ -17,12 +17,12 @@ To distinguish between new crashes and crashes that were already reported, the plugin makes its own entry in the log file, which acts as a separator. .SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. +The plugin is invoked in the \fIabrt.conf\fP configuration file. No parameters are necessary. .SH CONFIGURATION The \fIKerneloopsScanner.conf\fP configuration file contains one entry: .SS SysLogFile -The file to scan. The default is +The file to scan. The default is .br SysLogFile = /var/log/messages .SH EXAMPLES diff --git a/lib/Plugins/abrt-Logger.7 b/lib/Plugins/abrt-Logger.7 index 0f814d2..8ae679f 100644 --- a/lib/Plugins/abrt-Logger.7 +++ b/lib/Plugins/abrt-Logger.7 @@ -5,8 +5,8 @@ Logger plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fILogger\fP plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fILogger\fP plugin for \fIabrt\fP. .P This plugin is used to log the crash to a file. @@ -16,7 +16,7 @@ content. It also contains "duplicity check": the ID of the crash, which is used to tell whether the same crash has happened previously. .SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. +The plugin is invoked in the \fIabrt.conf\fP configuration file. No parameters are necessary. .SH CONFIGURATION The \fILogger.conf\fP configuration file contains diff --git a/lib/Plugins/abrt-Mailx.7 b/lib/Plugins/abrt-Mailx.7 index 10d5e4b..90a8bbc 100644 --- a/lib/Plugins/abrt-Mailx.7 +++ b/lib/Plugins/abrt-Mailx.7 @@ -5,8 +5,8 @@ Mailx plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIMailx\fP plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIMailx\fP plugin for \fIabrt\fP. .P This plugin is used to mail the data about the crash @@ -42,7 +42,7 @@ These are snippets from the \fIabrt.conf\fP configuration file. .br ActionsAndReporters = Mailx("[abrt] a crash occurs") .P -2) When a program in a specific package (in this case "httpd") crashes, +2) When a program in a specific package (in this case "httpd") crashes, send a mail about it. .PP [AnalyzerActionsAndReporters] diff --git a/lib/Plugins/abrt-RunApp.7 b/lib/Plugins/abrt-RunApp.7 index 6d75b12..56a8d2b 100644 --- a/lib/Plugins/abrt-RunApp.7 +++ b/lib/Plugins/abrt-RunApp.7 @@ -5,13 +5,13 @@ RunApp plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIRunApp\fP plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fIRunApp\fP plugin for \fIabrt\fP. .P This plugin is used to run a specified application when the crash occurs. .SH INVOCATION -The plugin is invoked in the \fIabrt.conf\fP configuration file. +The plugin is invoked in the \fIabrt.conf\fP configuration file. The first parameter is the command to run. The second, optional parameter specifies an output file, to which the standard output of the program is saved. diff --git a/lib/Plugins/abrt-SQLite3.7 b/lib/Plugins/abrt-SQLite3.7 index 87df539..c2b39d8 100644 --- a/lib/Plugins/abrt-SQLite3.7 +++ b/lib/Plugins/abrt-SQLite3.7 @@ -5,8 +5,8 @@ SQLite3 database plugin for abrt(8) .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fISQLite3\fP database plugin +it collects the crash data and takes action according to +its configuration. This manual page describes the \fISQLite3\fP database plugin for \fIabrt\fP. .P This is a database plugin: \fIabrt\fP needs a database in which to store diff --git a/lib/Plugins/abrt-plugins.7 b/lib/Plugins/abrt-plugins.7 index a7c185c..3a99dcb 100644 --- a/lib/Plugins/abrt-plugins.7 +++ b/lib/Plugins/abrt-plugins.7 @@ -9,10 +9,10 @@ it collects the crash data (core file, application's command line etc.) and takes action according to the type of application that crashed and according to the configuration specified in the .I abrt.conf -configuration file. +configuration file. .P Plugins allow abrt to perform various actions: for example, -to report the crash to Bugzilla, to mail the report, to transfer +to report the crash to Bugzilla, to mail the report, to transfer the report via FTP or SCP, or to run a program that you specify. .P This manual page provides a list of all the manual pages for diff --git a/lib/Python/PyDebugDump.cpp b/lib/Python/PyDebugDump.cpp index b45b84a..0f6de47 100644 --- a/lib/Python/PyDebugDump.cpp +++ b/lib/Python/PyDebugDump.cpp @@ -73,7 +73,7 @@ static PyMethodDef ABRTUtils_functions[] = { static int _wrap_PyCDebugDump__tp_init(PyCDebugDump *self, PyObject *args, PyObject *kwargs) { - const char *keywords[] = {NULL}; + static const char *const keywords[] = {NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "", (char **) keywords)) { return -1; @@ -100,10 +100,10 @@ _wrap_PyCDebugDump_Create(PyCDebugDump *self, PyObject *args, PyObject *kwargs) { PyObject *py_retval; char *pFilename2; - char *pUID2; - const char *keywords[] = {"pFilename", "pUID", NULL}; + int pUID2; + static const char *const keywords[] = {"pFilename", "pUID", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "ss", (char **) keywords, &pFilename2, &pUID2)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "si", (char **) keywords, &pFilename2, &pUID2)) { return NULL; } self->obj->Create(pFilename2, pUID2); @@ -119,7 +119,7 @@ _wrap_PyCDebugDump_SaveText(PyCDebugDump *self, PyObject *args, PyObject *kwargs PyObject *py_retval; char *pName2; char *pData2; - const char *keywords[] = {"pName", "pData", NULL}; + static const char *const keywords[] = {"pName", "pData", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "ss", (char **) keywords, &pName2, &pData2)) { return NULL; diff --git a/lib/Utils/CrashTypesSocket.cpp b/lib/Utils/CrashTypesSocket.cpp new file mode 100644 index 0000000..dccd4b0 --- /dev/null +++ b/lib/Utils/CrashTypesSocket.cpp @@ -0,0 +1,185 @@ +/* + CrashTypesSocket.cpp - functions for socket communication + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 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 "abrtlib.h" +#include "CrashTypesSocket.h" +#include <sstream> + +/** + * A request GET_CRASH_INFOS has the following form: + * message -> MESSAGE_GET_CRASH_INFOS + * + * Example: + * + * (GET_CRASH_INFOS) + * \23 + * + * + * A request DELETE_DEBUG_DUMP and CREATE_REPORT has following form: + * message -> MESSAGE_TYPE data END_MARKER + * MESSAGE_TYPE -> MESSAGE_CREATE_REPORT | MESSAGE_DELETE_DEBUG_DUMP + * data -> UUID + * + * Example: + * (DELETE_DEBUG_DUMP) + * 1135a3f35bccb543 + * \23 + * + * + * A reply to the GET_CRASH_INFOS, CREATE_REPORT and a request REPORT + * has the following form: + * + * message -> MESSAGE_TYPE data END_MARKER + * MESSAGE_TYPE -> MESSAGE_GET_CRASH_INFOS | MESSAGE_REPORT | MESSAGE_CREATE_REPORT + * data -> (count of items) item + * item -> (length of member)member(length of member)memger... + * + * Example: + * + * (REPORT) + * (2) + * (4)aaaa(1)t(1)y(5)hello + * (3)xxx(1)s(1)n(5)world + * \23 + * + * The replies has same header as the requests. + */ + +#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 MESSAGE_END_MARKER 23 + +std::string crash_data_to_string(const map_crash_data_t& pCrashData) +{ + std::stringstream sCD; + map_crash_data_t::const_iterator it_cd; + sCD << "(" << pCrashData.size() << ")"; + for(it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) + { + sCD << "(" << it_cd->first.length() << ")"; + sCD << it_cd->first; + sCD << "(" << it_cd->second[CD_TYPE].length() << ")"; + sCD << it_cd->second[CD_TYPE]; + sCD << "(" << it_cd->second[CD_EDITABLE].length() << ")"; + sCD << it_cd->second[CD_EDITABLE]; + sCD << "(" << it_cd->second[CD_CONTENT].length() << ")"; + sCD << it_cd->second[CD_CONTENT]; + } + return sCD.str(); +} + +std::string crash_infos_to_string(const vector_crash_infos_t& pCrashInfos) +{ + std::stringstream sCI; + unsigned int ii; + for (ii = 0; ii < pCrashInfos.size(); ii++) + { + sCI << crash_data_to_string(pCrashInfos[ii]); + } + return sCI.str(); +} + +int get_number_from_string(const std::string& pMessage, int& len) +{ + std::string sNumber = ""; + + int ii = 1; + while (pMessage[ii] != ')') + { + sNumber += pMessage[ii]; + ii++; + if (static_cast<std::string::size_type>(ii) >= pMessage.length()) + { + len = ii; + return -1; + } + } + len = ii + 1; + return atoi(sNumber.c_str()); +} + +//TODO: remove constant 4 and place it in a message +map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len) +{ + map_crash_data_t ci; + std::string message = pMessage; + int nSize; + std::string sField; + int nField; + int nCount; + std::string name; + int ii; + + nCount = get_number_from_string(message, ii); + if (ii == -1) + { + len = ii; + return ci; + } + message.erase(0, ii); + len = ii; + nField = 0; + while (nField < nCount * 4) + { + nSize = get_number_from_string(message, ii); + if (ii == -1) + { + len += ii; + ci.clear(); + return ci; + } + sField = message.substr(ii, nSize); + message.erase(0, ii + nSize); + len += ii + nSize; + switch(nField % 4) + { + case 0: + name = sField; + break; + default: + ci[name].push_back(sField); + break; + } + nField++; + } + return ci; +} + +vector_crash_infos_t string_to_crash_infos(const std::string& pMessage) +{ + vector_crash_infos_t vci; + std::string message = pMessage; + int len; + + while (message != "") + { + map_crash_info_t crash_info = string_to_crash_data(message, len); + if (crash_info.size() == 0) + { + return vci; + } + vci.push_back(crash_info); + message.erase(0, len); + } + return vci; +} diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 3297579..f63a8c6 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -19,25 +19,15 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "abrtlib.h" #include "DebugDump.h" #include "ABRTException.h" #include <fstream> #include <iostream> #include <sstream> #include <cerrno> -#include <sys/types.h> -#include <sys/stat.h> -#include <dirent.h> #include <sys/utsname.h> -#include <limits.h> -#include <fcntl.h> -#include <ctype.h> -#include <time.h> -#include <unistd.h> #include <magic.h> -#include <string.h> -#include <pwd.h> -#include <stdlib.h> #include "CommLayerInner.h" // BUG? in C/C++, compiler may assume that function address is never NULL @@ -193,7 +183,7 @@ void CDebugDump::UnLock() } } -void CDebugDump::Create(const std::string& pDir, const std::string& pUID) +void CDebugDump::Create(const std::string& pDir, uid_t uid) { if (m_bOpened) { @@ -221,16 +211,16 @@ void CDebugDump::Create(const std::string& pDir, const std::string& pUID) m_bOpened = false; throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot change permissions, dir: " + pDir); } - uid_t uid = atoi(pUID.c_str()); struct passwd* pw = getpwuid(uid); - if (chown(m_sDebugDumpDir.c_str(), uid, pw ? pw->pw_gid : uid) == -1) + gid_t gid = pw ? pw->pw_gid : uid; + if (chown(m_sDebugDumpDir.c_str(), uid, gid) == -1) { - UnLock(); - m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot change ownership, dir: " + pDir); + /* if /var/cache/abrt is writable by all, _aborting_ here is not useful */ + /* let's just warn */ + perror_msg("can't change '%s' ownership to %u:%u", m_sDebugDumpDir.c_str(), (int)uid, (int)gid); } - SaveText(FILENAME_UID, pUID); + SaveText(FILENAME_UID, ssprintf("%u", (int)uid)); SaveKernelArchitectureRelease(); SaveTime(); } @@ -239,7 +229,7 @@ static void DeleteFileDir(const std::string& pDir) { DIR *dir = opendir(pDir.c_str()); if (!dir) - return; + return; struct dirent *dent; while ((dent = readdir(dir)) != NULL) diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 65cc760..1bd8cc7 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -57,7 +57,7 @@ class CDebugDump public: CDebugDump(); void Open(const std::string& pDir); - void Create(const std::string& pDir, const std::string& pUID); + void Create(const std::string& pDir, uid_t pUID); void Delete(); void Close(); diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 60431a5..aa6ddc9 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -1,9 +1,11 @@ lib_LTLIBRARIES = libABRTUtils.la libABRTUtils_la_SOURCES = \ DebugDump.cpp DebugDump.h \ + CrashTypesSocket.cpp \ xfuncs.cpp \ read_write.cpp \ - logging.cpp + logging.cpp \ + copyfd.cpp libABRTUtils_la_LDFLAGS = -version-info 0:1:0 libABRTUtils_la_LIBADD = -lmagic diff --git a/lib/Utils/copyfd.cpp b/lib/Utils/copyfd.cpp new file mode 100644 index 0000000..cda52b0 --- /dev/null +++ b/lib/Utils/copyfd.cpp @@ -0,0 +1,107 @@ +/* + * Utility routines. + * + * Licensed under GPLv2, see file COPYING in this tarball for details. + */ +#include "abrtlib.h" + +#define CONFIG_FEATURE_COPYBUF_KB 4 + +static const char msg_write_error[] = "write error"; +static const char msg_read_error[] = "read error"; + +static off_t full_fd_action(int src_fd, int dst_fd, off_t size) +{ + int status = -1; + off_t total = 0; +#if CONFIG_FEATURE_COPYBUF_KB <= 4 + char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024]; + enum { buffer_size = sizeof(buffer) }; +#else + char *buffer; + int buffer_size; + + /* We want page-aligned buffer, just in case kernel is clever + * and can do page-aligned io more efficiently */ + buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, + /* ignored: */ -1, 0); + buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024; + if (buffer == MAP_FAILED) { + buffer = alloca(4 * 1024); + buffer_size = 4 * 1024; + } +#endif + + if (src_fd < 0) + goto out; + + if (!size) { + size = buffer_size; + status = 1; /* copy until eof */ + } + + while (1) { + ssize_t rd; + + rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size); + + if (!rd) { /* eof - all done */ + status = 0; + break; + } + if (rd < 0) { + perror_msg(msg_read_error); + break; + } + /* dst_fd == -1 is a fake, else... */ + if (dst_fd >= 0) { + ssize_t wr = full_write(dst_fd, buffer, rd); + if (wr < rd) { + perror_msg(msg_write_error); + break; + } + } + total += rd; + if (status < 0) { /* if we aren't copying till EOF... */ + size -= rd; + if (!size) { + /* 'size' bytes copied - all done */ + status = 0; + break; + } + } + } + out: + +#if CONFIG_FEATURE_COPYBUF_KB > 4 + if (buffer_size != 4 * 1024) + munmap(buffer, buffer_size); +#endif + return status ? -1 : total; +} + +off_t copyfd_size(int fd1, int fd2, off_t size) +{ + if (size) { + return full_fd_action(fd1, fd2, size); + } + return 0; +} + +void copyfd_exact_size(int fd1, int fd2, off_t size) +{ + off_t sz = copyfd_size(fd1, fd2, size); + if (sz == size) + return; + if (sz != -1) + error_msg_and_die("short read"); + /* if sz == -1, copyfd_XX already complained */ + xfunc_die(); +} + +off_t copyfd_eof(int fd1, int fd2) +{ + return full_fd_action(fd1, fd2, 0); +} diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index ad67ec6..078c804 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -158,6 +158,35 @@ char* xasprintf(const char *format, ...) return string_ptr; } +std::string ssprintf(const char *format, ...) +{ + va_list p; + int r; + char *string_ptr; + +#if 1 + // GNU extension + va_start(p, format); + r = vasprintf(&string_ptr, format, p); + va_end(p); +#else + // Bloat for systems that haven't got the GNU extension. + va_start(p, format); + r = vsnprintf(NULL, 0, format, p); + va_end(p); + string_ptr = xmalloc(r+1); + va_start(p, format); + r = vsnprintf(string_ptr, r+1, format, p); + va_end(p); +#endif + + if (r < 0) + error_msg_and_die(msg_memory_exhausted); + std::string res = string_ptr; + free(string_ptr); + return res; +} + void xsetenv(const char *key, const char *value) { if (setenv(key, value, 1)) @@ -170,7 +199,6 @@ int xsocket(int domain, int type, int protocol) int r = socket(domain, type, protocol); if (r < 0) { - /* Hijack vaguely related config option */ const char *s = "INET"; if (domain == AF_PACKET) s = "PACKET"; if (domain == AF_NETLINK) s = "NETLINK"; diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp index adcfb47..53f0043 100644 --- a/src/Applet/Applet.cpp +++ b/src/Applet/Applet.cpp @@ -1,20 +1,20 @@ -/* - Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) - Copyright (C) 2009 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. +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 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 "CCApplet.h" diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am index 2665850..f0ec5ed 100644 --- a/src/Applet/Makefile.am +++ b/src/Applet/Makefile.am @@ -1,13 +1,22 @@ bin_PROGRAMS = abrt-applet -abrt_applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h -abrt_applet_CPPFLAGS = -Wall -Werror -I../Daemon/ \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DBIN_DIR=\"$(bindir)\" \ - $(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) $(LIBNOTIFY_CFLAGS)\ - -I$(srcdir)/../../inc -I../../lib/CommLayer \ - -I../../lib/MiddleWare -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -abrt_applet_LDADD = $(DL_LIBS) $(GTK_LIBS) -lglib-2.0 -lgthread-2.0 $(DBUSCPP_LIBS) $(LIBNOTIFY_LIBS) +abrt_applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h +abrt_applet_CPPFLAGS = \ + -Wall -Werror \ + -I../Daemon/ \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/CommLayer \ + -I$(srcdir)/../../lib/MiddleWare \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DBIN_DIR=\"$(bindir)\" \ + $(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) $(LIBNOTIFY_CFLAGS) \ + -I/usr/include/glib-2.0 \ + -I/usr/lib/glib-2.0/include +abrt_applet_LDADD = \ + ../../lib/CommLayer/libABRTCommLayer.la \ + $(DL_LIBS) $(GTK_LIBS) \ + -lglib-2.0 -lgthread-2.0 \ + $(DBUSCPP_LIBS) $(LIBNOTIFY_LIBS) EXTRA_DIST = abrt-applet.desktop diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp index 251407b..aaaef5b 100644 --- a/src/CLI/CLI.cpp +++ b/src/CLI/CLI.cpp @@ -136,7 +136,7 @@ int main(int argc, char** argv) dispatcher.attach(NULL); DBus::default_dispatcher = &dispatcher; DBus::Connection conn = DBus::Connection::SystemBus(); - CCommLayerClientDBus ABRTDaemon(conn, CC_DBUS_PATH, CC_DBUS_NAME); + CCommLayerClientDBus ABRTDaemon(conn, CC_DBUS_PATH, CC_DBUS_NAME); if(!conn.has_name(CC_DBUS_NAME)){ std::cout << "Daemon is not running!" << std::endl; return -1; diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 108db19..c64e22a 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -516,6 +516,7 @@ CCrashWatcher::~CCrashWatcher() /* delete lock file */ unlink(VAR_RUN_LOCK_FILE); } + void CCrashWatcher::FindNewDumps(const std::string& pPath) { Debug("Scanning for unsaved entries..."); diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index 71ed014..420acc4 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -69,7 +69,7 @@ class CCrashWatcher {} } cron_callback_data_t; - + typedef struct SThreadData{ pthread_t thread_id; char* UUID; @@ -77,7 +77,7 @@ class CCrashWatcher char *dest; CCrashWatcher *daemon; } thread_data_t; - + /** * Map to cache the results from CreateReport_t * <UID, <UUID, result>> diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index b6a66f6..41d60a7 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -1,15 +1,29 @@ sbin_PROGRAMS = abrt -abrt_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp \ - DBusCommon.h Settings.h Settings.cpp -abrt_CPPFLAGS = -I$(srcdir)/../../lib/MiddleWare -I$(srcdir)/../../lib/CommLayer\ - -I$(srcdir)/../../inc -I$(srcdir)/../../lib/Utils \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ - -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ - -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ - -DCONF_DIR=\"$(CONF_DIR)\" \ - -DVAR_RUN=\"$(VAR_RUN)\" $(ENABLE_SOCKET_OR_DBUS) -abrt_LDADD = ../../lib/MiddleWare/libABRTMiddleWare.la ../../lib/CommLayer/libABRTCommLayer.la $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) +abrt_SOURCES = \ + PluginManager.cpp PluginManager.h \ + MiddleWare.cpp MiddleWare.h \ + CrashWatcher.cpp CrashWatcher.h \ + Daemon.cpp \ + DBusCommon.h \ + Settings.h Settings.cpp +abrt_CPPFLAGS = \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/MiddleWare \ + -I$(srcdir)/../../lib/CommLayer \ + -I$(srcdir)/../../lib/Utils \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ + $(ENABLE_SOCKET_OR_DBUS) +abrt_LDADD = \ + ../../lib/MiddleWare/libABRTMiddleWare.la \ + ../../lib/CommLayer/libABRTCommLayer.la \ + $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) + dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ dist_dbusabrtconf_DATA = dbus-abrt.conf diff --git a/lib/MiddleWare/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 7f1250c..2a8688e 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -19,6 +19,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "abrtlib.h" #include "MiddleWare.h" #include "DebugDump.h" #include "ABRTException.h" diff --git a/lib/MiddleWare/MiddleWare.h b/src/Daemon/MiddleWare.h index 8b7376d..050844c 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/src/Daemon/MiddleWare.h @@ -39,19 +39,20 @@ class CMiddleWare /** * An emun contains all return codes. */ - typedef enum { MW_ERROR, /**< Common error.*/ - MW_OK, /**< No error.*/ - MW_BLACKLISTED, /**< Package is blacklisted.*/ - MW_CORRUPTED, /**< Debugdump directory is corrupted.*/ - MW_PACKAGE_ERROR, /**< Cannot determine package name.*/ - MW_GPG_ERROR, /**< Package is not signed properly.*/ - MW_REPORTED, /**< Crash is already reported.*/ - MW_OCCURED, /**< Crash occurred in the past, but it is not reported yet.*/ - MW_IN_DB, /**< Debugdump directory is already saved in a database.*/ - MW_IN_DB_ERROR, /**< Error while working with a database.*/ - MW_FILE_ERROR /**< Error when trying open debugdump directory or - when trying open file in debug dump directory..*/ - } mw_result_t; + typedef enum { + MW_ERROR, /**< Common error.*/ + MW_OK, /**< No error.*/ + MW_BLACKLISTED, /**< Package is blacklisted.*/ + MW_CORRUPTED, /**< Debugdump directory is corrupted.*/ + MW_PACKAGE_ERROR, /**< Cannot determine package name.*/ + MW_GPG_ERROR, /**< Package is not signed properly.*/ + MW_REPORTED, /**< Crash is already reported.*/ + MW_OCCURED, /**< Crash occurred in the past, but it is not reported yet.*/ + MW_IN_DB, /**< Debugdump directory is already saved in a database.*/ + MW_IN_DB_ERROR, /**< Error while working with a database.*/ + MW_FILE_ERROR /**< Error when trying open debugdump directory or + when trying open file in debug dump directory..*/ + } mw_result_t; private: typedef set_strings_t set_blacklist_t; diff --git a/lib/MiddleWare/PluginManager.cpp b/src/Daemon/PluginManager.cpp index 81207f9..b0ba0db 100644 --- a/lib/MiddleWare/PluginManager.cpp +++ b/src/Daemon/PluginManager.cpp @@ -28,9 +28,14 @@ #include <sys/types.h> /** - * Text reprezentation of plugin types. + * Text representation of plugin types. */ -static const char* const plugin_type_str_t[] = { "Analyzer", "Action", "Reporter", "Database" }; +static const char* const plugin_type_str_t[] = { + "Analyzer", + "Action", + "Reporter", + "Database" +}; CPluginManager::CPluginManager( @@ -52,10 +57,11 @@ void CPluginManager::LoadPlugins() { while ((dent = readdir(dir)) != NULL) { + // FIXME: need to handle DT_UNKNOWN too if (dent->d_type == DT_REG) { std::string name = dent->d_name; - std::string extension = name.substr(name.length()-sizeof(PLUGINS_LIB_EXTENSION)+1); + std::string extension = name.substr(name.length() - sizeof(PLUGINS_LIB_EXTENSION) + 1); if (extension == PLUGINS_LIB_EXTENSION) { name.erase(0, sizeof(PLUGINS_LIB_PREFIX) - 1); @@ -71,11 +77,11 @@ void CPluginManager::LoadPlugins() void CPluginManager::UnLoadPlugins() { map_abrt_plugins_t::iterator it_p; - while ((it_p = m_mapABRTPlugins.begin()) != m_mapABRTPlugins.end()) - { - std::string pluginName = it_p->first; - UnLoadPlugin(pluginName); - } + while ((it_p = m_mapABRTPlugins.begin()) != m_mapABRTPlugins.end()) + { + std::string pluginName = it_p->first; + UnLoadPlugin(pluginName); + } } void CPluginManager::LoadPlugin(const std::string& pName) @@ -118,7 +124,6 @@ void CPluginManager::UnLoadPlugin(const std::string& pName) } } - void CPluginManager::RegisterPlugin(const std::string& pName) { if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end()) @@ -176,7 +181,7 @@ CAnalyzer* CPluginManager::GetAnalyzer(const std::string& pName) throw CABRTException(EXCEP_PLUGIN, "CPluginManager::GetAnalyzer():" "Plugin: '"+pName+"' is not analyzer plugin."); } - return dynamic_cast<CAnalyzer*>(m_mapPlugins[pName]); + return (CAnalyzer*)(m_mapPlugins[pName]); } CReporter* CPluginManager::GetReporter(const std::string& pName) @@ -191,7 +196,7 @@ CReporter* CPluginManager::GetReporter(const std::string& pName) throw CABRTException(EXCEP_PLUGIN, "CPluginManager::GetReporter():" "Plugin: '"+pName+"' is not reporter plugin."); } - return dynamic_cast<CReporter*>(m_mapPlugins[pName]); + return (CReporter*)(m_mapPlugins[pName]); } CAction* CPluginManager::GetAction(const std::string& pName) @@ -206,7 +211,7 @@ CAction* CPluginManager::GetAction(const std::string& pName) throw CABRTException(EXCEP_PLUGIN, "CPluginManager::GetAction():" "Plugin: '"+pName+"' is not action plugin."); } - return dynamic_cast<CAction*>(m_mapPlugins[pName]); + return (CAction*)(m_mapPlugins[pName]); } CDatabase* CPluginManager::GetDatabase(const std::string& pName) @@ -221,7 +226,7 @@ CDatabase* CPluginManager::GetDatabase(const std::string& pName) throw CABRTException(EXCEP_PLUGIN, "CPluginManager::GetDatabase():" "Plugin: '"+pName+"' is not database plugin."); } - return dynamic_cast<CDatabase*>(m_mapPlugins[pName]); + return (CDatabase*)(m_mapPlugins[pName]); } plugin_type_t CPluginManager::GetPluginType(const std::string& pName) @@ -252,7 +257,6 @@ vector_map_string_string_t CPluginManager::GetPluginsInfo() plugin_info["WWW"] = it_abrt_plugin->second->GetWWW(); plugin_info["GTKBuilder"] = it_abrt_plugin->second->GetGTKBuilder(); ret.push_back(plugin_info); - } return ret; } diff --git a/lib/MiddleWare/PluginManager.h b/src/Daemon/PluginManager.h index 0be90d4..53ec77c 100644 --- a/lib/MiddleWare/PluginManager.h +++ b/src/Daemon/PluginManager.h @@ -40,61 +40,61 @@ */ class CPluginManager { - private: - typedef std::map<std::string, CABRTPlugin*> map_abrt_plugins_t; - typedef std::map<std::string, CPlugin*> map_plugins_t; + private: + typedef std::map<std::string, CABRTPlugin*> map_abrt_plugins_t; + typedef std::map<std::string, CPlugin*> map_plugins_t; - /** - * Loaded plugins. A key is a plugin name. - */ - map_abrt_plugins_t m_mapABRTPlugins; - /** - * Registered plugins. A key is a plugin name. - */ - map_plugins_t m_mapPlugins; - /** - * Plugins configuration directory (e.g. /etc/abrt/plugins, ...). - */ - std::string m_sPluginsConfDir; - /** - * Plugins library directory (e.g. /usr/lib/abrt/plugins, ...). - */ - std::string m_sPluginsLibDir; + /** + * Loaded plugins. A key is a plugin name. + */ + map_abrt_plugins_t m_mapABRTPlugins; + /** + * Registered plugins. A key is a plugin name. + */ + map_plugins_t m_mapPlugins; + /** + * Plugins configuration directory (e.g. /etc/abrt/plugins, ...). + */ + std::string m_sPluginsConfDir; + /** + * Plugins library directory (e.g. /usr/lib/abrt/plugins, ...). + */ + std::string m_sPluginsLibDir; - public: - /** - * A constructor. - * @param pPluginsConfDir A plugins configuration directory. - * @param pPluginsLibDir A plugins library directory. - */ - CPluginManager(const std::string& pPluginsConfDir, - const std::string& pPluginsLibDir); - /** - * A destructor. - */ - ~CPluginManager(); - /** - * A method, which loads all plugins in plugins library direcotry. - */ - void LoadPlugins(); - /** - * A method, which unregister and unload all loaded plugins. - */ - void UnLoadPlugins(); - /** - * A method, which loads particular plugin. - * @param pName A plugin name. - */ - void LoadPlugin(const std::string& pName); - /** - * A method, which unloads particular plugin. - * @param pName A plugin name. - */ - void UnLoadPlugin(const std::string& pName); - /** - * A method, which registers particular plugin. - * @param pName A plugin name. - */ + public: + /** + * A constructor. + * @param pPluginsConfDir A plugins configuration directory. + * @param pPluginsLibDir A plugins library directory. + */ + CPluginManager(const std::string& pPluginsConfDir, + const std::string& pPluginsLibDir); + /** + * A destructor. + */ + ~CPluginManager(); + /** + * A method, which loads all plugins in plugins library direcotry. + */ + void LoadPlugins(); + /** + * A method, which unregister and unload all loaded plugins. + */ + void UnLoadPlugins(); + /** + * A method, which loads particular plugin. + * @param pName A plugin name. + */ + void LoadPlugin(const std::string& pName); + /** + * A method, which unloads particular plugin. + * @param pName A plugin name. + */ + void UnLoadPlugin(const std::string& pName); + /** + * A method, which registers particular plugin. + * @param pName A plugin name. + */ void RegisterPlugin(const std::string& pName); /** * A method, which unregister particular plugin. @@ -106,31 +106,31 @@ class CPluginManager * @param pName A plugin name. * @return An analyzer plugin. */ - CAnalyzer* GetAnalyzer(const std::string& pName); + CAnalyzer* GetAnalyzer(const std::string& pName); /** * A method, which returns instance of particular reporter plugin. * @param pName A plugin name. * @return A reporter plugin. */ - CReporter* GetReporter(const std::string& pName); + CReporter* GetReporter(const std::string& pName); /** * A method, which returns instance of particular action plugin. * @param pName A plugin name. * @return An action plugin. */ - CAction* GetAction(const std::string& pName); + CAction* GetAction(const std::string& pName); /** * A method, which returns instance of particular database plugin. * @param pName A plugin name. * @return A database plugin. */ - CDatabase* GetDatabase(const std::string& pName); - /** - * A method, which returns type of particular plugin. - * @param pName A plugin name. - * @return A plugin type. - */ - plugin_type_t GetPluginType(const std::string& pName); + CDatabase* GetDatabase(const std::string& pName); + /** + * A method, which returns type of particular plugin. + * @param pName A plugin name. + * @return A plugin type. + */ + plugin_type_t GetPluginType(const std::string& pName); /** * A method, which gets all plugins info (event those plugins which are * disabled). It can be send via DBus to GUI and displayed to an user. diff --git a/src/Daemon/abrt.8 b/src/Daemon/abrt.8 index f3ae127..b106041 100644 --- a/src/Daemon/abrt.8 +++ b/src/Daemon/abrt.8 @@ -27,7 +27,7 @@ to print more debugging information when the daemon is started. When you use some other crash-catching tool, specific for an application or an application type (for example BugBuddy for GNOME applications), crashes of this type will be handled by that tool and -not by \fIabrt\fP. If you want \fIabrt\fP to handle these crashes, +not by \fIabrt\fP. If you want \fIabrt\fP to handle these crashes, turn off the higher-level crash-catching tool. .SH "SEE ALSO" .IR abrt.conf (5), diff --git a/src/Daemon/abrt.conf.5 b/src/Daemon/abrt.conf.5 index edccb59..3b172bc 100644 --- a/src/Daemon/abrt.conf.5 +++ b/src/Daemon/abrt.conf.5 @@ -5,11 +5,11 @@ abrt.conf \- configuration file for abrt .P .I abrt is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to +it collects the crash data and takes action according to its configuration. This manual page describes \fIabrt\fP's configuration file. .P -The configuration file consists of sections, each section contains +The configuration file consists of sections, each section contains several items in the format "Option = Value". A description of each section follows: .SS [Common] @@ -21,7 +21,7 @@ will report crashes only in GPG signed packages. When set to "no", it will report crashes also in unsigned packages. .TP .B OpenGPGPublicKeys = \fIfilename\fP , \fIfilename\fP ... -These are the trusted GPG keys with which packages have to be +These are the trusted GPG keys with which packages have to be signed for .I abrt to report them if "EnableOpenGPG = yes". @@ -35,7 +35,7 @@ will ignore packages in this list and will not handle their crashes. will only load plugins in this list. .TP .B Database = \fIdatabasePlugin\fP -This specifies which database plugin +This specifies which database plugin .I abrt uses to store metadata about the crash. .TP diff --git a/src/Daemon/exported-symbols b/src/Daemon/exported-symbols index 511b598..2810010 100644 --- a/src/Daemon/exported-symbols +++ b/src/Daemon/exported-symbols @@ -1,3 +1,3 @@ -{ - get_commlayer; +{ + get_commlayer; }; diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index 6a8b1d6..b5b576b 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -22,14 +22,6 @@ #include "DebugDump.h" #include "ABRTException.h" -//#include <stdlib.h> -//#include <string.h> -//#include <limits.h> -//#include <stdio.h> -//#include <sys/types.h> -//#include <sys/stat.h> -//#include <unistd.h> -//#include <time.h> #include <syslog.h> #include <string> @@ -39,32 +31,17 @@ #define VAR_RUN_PID_FILE VAR_RUN"/abrt.pid" -static void write_success_log(const char* pid) +static char* get_executable(pid_t pid) { - openlog("abrt", 0, LOG_DAEMON); - syslog(LOG_WARNING, "CCpp Language Hook: Crashed pid: %s", pid); - closelog(); -} - -static void write_faliure_log(const char* msg) -{ - openlog("abrt", 0, LOG_DAEMON); - syslog(LOG_WARNING, "CCpp Language Hook: Exception occur: %s", msg); - closelog(); -} - - -char* get_executable(const char* pid) -{ - char path[PATH_MAX]; - char executable[PATH_MAX]; + char buf[PATH_MAX + 1]; int len; - snprintf(path, sizeof(path), "/proc/%s/exe", pid); - if ((len = readlink(path, executable, PATH_MAX)) != -1) + snprintf(buf, sizeof(buf), "/proc/%u/exe", (int)pid); + len = readlink(buf, buf, sizeof(buf)-1); + if (len >= 0) { - executable[len] = '\0'; - return xstrdup(executable); + buf[len] = '\0'; + return xstrdup(buf); } return NULL; } @@ -72,49 +49,62 @@ char* get_executable(const char* pid) // taken from kernel #define COMMAND_LINE_SIZE 2048 -char* get_cmdline(const char* pid) +static char* get_cmdline(pid_t pid) { char path[PATH_MAX]; char cmdline[COMMAND_LINE_SIZE]; - snprintf(path, sizeof(path), "/proc/%s/cmdline", pid); - FILE* fp = fopen(path, "r"); - int ch; - int ii = 0; - if (fp) + snprintf(path, sizeof(path), "/proc/%u/cmdline", (int)pid); + int dst = 0; + + int fd = open(path, O_RDONLY); + if (fd >= 0) { - while ((ch = fgetc(fp)) != EOF && ii < COMMAND_LINE_SIZE-1) + int len = read(fd, cmdline, sizeof(cmdline) - 1); + if (len >= 0) { - if (ch == 0) + int src = 0; + while (src < len) { - cmdline[ii] = ' '; + char ch = cmdline[src++]; + if (ch == '\0') + { + cmdline[dst++] = ' '; + } + /* TODO: maybe just ch >= ' '? */ + else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + { + cmdline[dst++] = ch; + } } - else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) - { - cmdline[ii] = ch; - } - ii++; } - fclose(fp); + close(fd); } - cmdline[ii] = '\0'; + cmdline[dst] = '\0'; + return xstrdup(cmdline); } -#define PID_MAX 16 - -int daemon_is_ok() +static int daemon_is_ok() { - char pid[PID_MAX]; + char pid[sizeof(pid_t)*3 + 2]; char path[PATH_MAX]; struct stat buff; - FILE* fp = fopen(VAR_RUN_PID_FILE, "r"); - if (fp == NULL) + int fd = open(VAR_RUN_PID_FILE, O_RDONLY); + if (fd < 0) { return 0; } - fgets(pid, sizeof(pid), fp); - fclose(fp); + int len = read(fd, pid, sizeof(pid)-1); + close(fd); + if (len <= 0) + return 0; + pid[len] = '\0'; *strchrnul(pid, '\n') = '\0'; + /* paranoia: we don't want to check /proc//stat or /proc///stat */ + if (pid[0] == '\0' || pid[0] == '/') + return 0; + + /* TODO: maybe readlink and check that it is "xxx/abrt"? */ snprintf(path, sizeof(path), "/proc/%s/stat", pid); if (stat(path, &buff) == -1) { @@ -129,27 +119,33 @@ int main(int argc, char** argv) const char* program_name = argv[0]; if (argc < 4) { - fprintf(stderr, "Usage: %s: <dddir> <pid> <signal> <uid>\n", - program_name); - return -1; + error_msg_and_die("Usage: %s: <dddir> <pid> <signal> <uid>", program_name); } + openlog("abrt", 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; const char* dddir = argv[1]; - const char* pid = argv[2]; - const char* signal = argv[3]; - const char* uid = argv[4]; - - if (strcmp(signal, "3") != 0 && // SIGQUIT - strcmp(signal, "4") != 0 && // SIGILL - strcmp(signal, "6") != 0 && // SIGABRT - strcmp(signal, "8") != 0 && // SIGFPE - strcmp(signal, "11") != 0) // SIGSEGV - { + pid_t pid = atoi(argv[2]); + const char* signal_str = argv[3]; + int signal = atoi(argv[3]); + uid_t uid = atoi(argv[4]); + + if (signal != SIGQUIT + && signal != SIGILL + && signal != SIGABRT + && signal != SIGFPE + && signal != SIGSEGV + ) { + /* not an error, exit silently */ return 0; } + if (pid <= 0 || uid < 0) + { + error_msg_and_die("pid '%s' or uid '%s' are bogus", argv[2], argv[4]); + } if (!daemon_is_ok()) { + /* not an error, exit with exitcode 0 */ log("abrt daemon is not running. If it crashed, " "/proc/sys/kernel/core_pattern contains a stale value, " "consider resetting it to 'core'" @@ -159,68 +155,64 @@ int main(int argc, char** argv) try { - FILE* fp; - CDebugDump dd; - int byte; - char path[PATH_MAX]; - char* executable = NULL; - char* cmdline = NULL; - + char* executable; + char* cmdline; executable = get_executable(pid); cmdline = get_cmdline(pid); - - if (executable == NULL || - cmdline == NULL) + if (executable == NULL || cmdline == NULL) + { + error_msg_and_die("can not get proc info for pid %u", (int)pid); + } + if (strstr(executable, "/abrt")) { - free(executable); - free(cmdline); - throw CABRTException(EXCEP_FATAL, "Can not get proc info."); + /* free(executable); - why bother? */ + /* free(cmdline); */ + error_msg_and_die("pid %u is '%s', not dumping it to avoid abrt recursion", + (int)pid, executable); } - snprintf(path, sizeof(path), "%s/ccpp-%ld-%s", dddir, time(NULL), pid); + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/ccpp-%ld-%u", dddir, (long)time(NULL), (int)pid); + + CDebugDump dd; dd.Create(path, uid); dd.SaveText(FILENAME_ANALYZER, "CCpp"); dd.SaveText(FILENAME_EXECUTABLE, executable); dd.SaveText(FILENAME_CMDLINE, cmdline); - dd.SaveText(FILENAME_REASON, std::string("Process was terminated by signal ") + signal); + dd.SaveText(FILENAME_REASON, std::string("Process was terminated by signal ") + signal_str); snprintf(path + strlen(path), sizeof(path), "/%s", FILENAME_COREDUMP); - if ((fp = fopen(path, "w")) == NULL) + int fd; + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd < 0) { dd.Delete(); dd.Close(); - throw CABRTException(EXCEP_FATAL, std::string("Can not open the file ") + path); + perror_msg_and_die("can't open '%s'", path); } - // TODO: rewrite this - while ((byte = getc(stdin)) != EOF) + if (copyfd_eof(STDIN_FILENO, fd) < 0) { - if (putc(byte, fp) == EOF) - { - fclose(fp); - dd.Delete(); - dd.Close(); - throw CABRTException(EXCEP_FATAL, "Can not write to the file %s."); - } + /* close(fd); - why bother? */ + dd.Delete(); + dd.Close(); + /* copyfd_eof logs the error including errno string, + * but it does not log file name */ + error_msg_and_die("error saving coredump to %s", path); } - - free(executable); - free(cmdline); - fclose(fp); + /* close(fd); - why bother? */ + /* free(executable); */ + /* free(cmdline); */ dd.Close(); - write_success_log(pid); + log("saved core dump of pid %u to %s", (int)pid, path); } catch (CABRTException& e) { - fprintf(stderr, "%s: %s\n", program_name, e.what().c_str()); - write_faliure_log(e.what().c_str()); - return -2; + error_msg_and_die("%s", e.what().c_str()); } catch (std::exception& e) { - fprintf(stderr, "%s: %s\n", program_name, e.what()); - write_faliure_log(e.what()); - return -2; + error_msg_and_die("%s", e.what()); } return 0; } diff --git a/src/Hooks/abrt_exception_handler.py.in b/src/Hooks/abrt_exception_handler.py.in index 148573d..f4ebbb5 100644 --- a/src/Hooks/abrt_exception_handler.py.in +++ b/src/Hooks/abrt_exception_handler.py.in @@ -200,7 +200,7 @@ def handleMyException((etype, value, tb)): progname - the name of the application version - the version of the application """ - + # restore original exception handler sys.excepthook = sys.__excepthook__ # pylint: disable-msg=E1101 |
