diff options
Diffstat (limited to 'lib/Plugins')
-rw-r--r-- | lib/Plugins/CCpp.conf | 3 | ||||
-rw-r--r-- | lib/Plugins/CCpp.cpp | 80 | ||||
-rw-r--r-- | lib/Plugins/CCpp.h | 54 | ||||
-rw-r--r-- | lib/Plugins/Mailx.conf | 12 | ||||
-rw-r--r-- | lib/Plugins/Mailx.cpp | 74 | ||||
-rw-r--r-- | lib/Plugins/Mailx.h | 58 | ||||
-rw-r--r-- | lib/Plugins/Makefile.am | 22 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.conf | 5 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.cpp | 255 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.h | 80 |
10 files changed, 643 insertions, 0 deletions
diff --git a/lib/Plugins/CCpp.conf b/lib/Plugins/CCpp.conf new file mode 100644 index 00000000..1d15667b --- /dev/null +++ b/lib/Plugins/CCpp.conf @@ -0,0 +1,3 @@ +# Configuration file for CCpp add-on +Enabled = yes +MemoryMap = no
\ No newline at end of file diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp new file mode 100644 index 00000000..54ec0907 --- /dev/null +++ b/lib/Plugins/CCpp.cpp @@ -0,0 +1,80 @@ +/* + DebugDump.cpp + + 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 "CCpp.h" +#include <fstream> +#include <ctype.h> + +#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" +#define CORE_PATTERN CCPP_HOOK_PATH" %p %t %s" + +CLanguageCCpp::CLanguageCCpp() : + m_bMemoryMap(false) +{} + +std::string CLanguageCCpp::GetUUID(void* pData) +{ + if (m_bMemoryMap) + return "UUID a memory map"; + else + return "UUID bez memory map"; +} + +std::string CLanguageCCpp::GetReport(void* pData) +{ + return "reportuju jak blazen"; +} + +void CLanguageCCpp::Init(const map_settings_t& pSettings) +{ + std::ifstream fInCorePattern; + fInCorePattern.open(CORE_PATTERN_IFACE); + if (fInCorePattern.is_open()) + { + getline(fInCorePattern, m_sOldCorePattern); + fInCorePattern.close(); + } + std::ofstream fOutCorePattern; + fOutCorePattern.open(CORE_PATTERN_IFACE); + if (fOutCorePattern.is_open()) + { + fOutCorePattern << CORE_PATTERN << std::endl; + fOutCorePattern.close(); + } + + if (pSettings.find("MemoryMap")!= pSettings.end()) + { + m_bMemoryMap = pSettings.find("MemoryMap")->second == "yes"; + } + +} + + +void CLanguageCCpp::DeInit() +{ + std::ofstream fOutCorePattern; + fOutCorePattern.open(CORE_PATTERN_IFACE); + if (fOutCorePattern.is_open()) + { + fOutCorePattern << m_sOldCorePattern << std::endl; + fOutCorePattern.close(); + } +} diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h new file mode 100644 index 00000000..904ac7c5 --- /dev/null +++ b/lib/Plugins/CCpp.h @@ -0,0 +1,54 @@ +/* + CCpp.h - header file for C/C++ language plugin + - it can ger UUID and memory maps from core files + + 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. + */ + +#ifndef CCPP_H_ +#define CCPP_H_ + +#include <string> +#include "Plugin.h" +#include "Language.h" + +class CLanguageCCpp : public CLanguage +{ + private: + bool m_bMemoryMap; + std::string m_sOldCorePattern; + public: + CLanguageCCpp(); + virtual ~CLanguageCCpp() {} + std::string GetUUID(void* pData); + std::string GetReport(void* pData); + void Init(const map_settings_t& pSettings); + void DeInit(); +}; + + +PLUGIN_INFO(LANGUAGE, + "CCpp", + "0.0.1", + "Simple C/C++ language plugin.", + "zprikryl@redhat.com", + "https://fedorahosted.org/crash-catcher/wiki"); + +PLUGIN_INIT(CLanguageCCpp); + +#endif /* CCPP */ diff --git a/lib/Plugins/Mailx.conf b/lib/Plugins/Mailx.conf new file mode 100644 index 00000000..2b0be9c9 --- /dev/null +++ b/lib/Plugins/Mailx.conf @@ -0,0 +1,12 @@ +# Configuration to Email reporter plugin + +Enabled = no + +# Parameters +Parameters = + +# Your Email +Email_From = zprikryl@redhat.com + +# Email To +Email_To = jmoskovc@redhat.com diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp new file mode 100644 index 00000000..7f4b7a76 --- /dev/null +++ b/lib/Plugins/Mailx.cpp @@ -0,0 +1,74 @@ +/* + Mailx.cpp + + 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 "Mailx.h" +#include <stdio.h> + +#define MAILX_COMMAND "mailx" +#define MAILX_SUBJECT "CrashCatcher automated bug report" + +CMailx::CMailx() : + m_sEmailFrom(""), + m_sEmailTo(""), + m_sParameters() +{} + + +void CMailx::SendEmail(const std::string& pText) +{ + FILE* command; + std::string mailx_command = MAILX_COMMAND + m_sParameters + + " -s " + MAILX_SUBJECT + + " -r " + m_sEmailTo + " " + m_sEmailFrom; + + command = popen(mailx_command.c_str(), "w"); + if (!command) + { + throw std::string("CMailx::SendEmail: Can not execute mailx."); + } + if (fputs(pText.c_str(), command) == -1) + { + throw std::string("CMailx::SendEmail: Can not send data."); + } + pclose(command); +} + + +void CMailx::Report(const std::string& pDebugDumpPath) +{ + SendEmail("Nejakej zbesilej report."); +} + +void CMailx::Init(const map_settings_t& pSettings) +{ + if (pSettings.find("Email_From")!= pSettings.end()) + { + m_sEmailFrom = pSettings.find("Email_From")->second; + } + if (pSettings.find("Email_To")!= pSettings.end()) + { + m_sEmailFrom = pSettings.find("Email_To")->second; + } + if (pSettings.find("Parameters")!= pSettings.end()) + { + m_sParameters = pSettings.find("Parameters")->second; + } +} diff --git a/lib/Plugins/Mailx.h b/lib/Plugins/Mailx.h new file mode 100644 index 00000000..e1463ea0 --- /dev/null +++ b/lib/Plugins/Mailx.h @@ -0,0 +1,58 @@ +/* + Mailx.h - header file for Mailx reporter plugin + - it simple sends an email to specific address via mailx command + + 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. + */ + +#ifndef MAILX_H_ +#define MAILX_H_ + +#include <string> +#include "Plugin.h" +#include "Reporter.h" + +class CMailx : public CReporter +{ + private: + std::string m_sEmailFrom; + std::string m_sEmailTo; + std::string m_sParameters; + + void SendEmail(const std::string& pText); + + public: + CMailx(); + virtual ~CMailx() {} + void Init(const map_settings_t& pSettings); + void DeInit() {} + void Report(const std::string& pDebugDumpPath); +}; + + +PLUGIN_INFO(REPORTER, + "Mailx", + "0.0.1", + "Sends an email with a report via mailx command", + "zprikryl@redhat.com", + "https://fedorahosted.org/crash-catcher/wiki"); + +PLUGIN_INIT(CMailx); + + +#endif /* MAILX_H_ */ diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am new file mode 100644 index 00000000..02ccafbe --- /dev/null +++ b/lib/Plugins/Makefile.am @@ -0,0 +1,22 @@ +AM_CPPFLAGS = -I$(srcdir)/../MiddleWare +pluginslibdir=$(PLUGINS_LIB_DIR) +pluginslib_LTLIBRARIES = libCCpp.la libMailx.la libSQLite3.la + +pluginsconfdir=$(PLUGINS_CONF_DIR) +pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf + +# CCpp +libCCpp_la_SOURCES = CCpp.cpp CCpp.h +libCCpp_la_LDFLAGS = -version-info 0:1:0 +libCCpp_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" + +# Mailx +libMailx_la_SOURCES = Mailx.cpp Mailx.h +libMailx_la_LDFLAGS = -version-info 0:1:0 + +# SQLite3 +libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h +libSQLite3_la_LDFLAGS = -version-info 0:1:0 +libSQLite3_la_LIBADD = $(SQLITE3_LIBS) +libSQLite3_la_CPPFLAGS = -I$(srcdir)/../MiddleWare $(SQLITE3_CFLAGS) + diff --git a/lib/Plugins/SQLite3.conf b/lib/Plugins/SQLite3.conf new file mode 100644 index 00000000..663bbf81 --- /dev/null +++ b/lib/Plugins/SQLite3.conf @@ -0,0 +1,5 @@ +# Configuration file for database plugin SQLite3 + +Enabled = yes +# DB path +DBPath = /tmp/CCDB diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp new file mode 100644 index 00000000..05beb1b0 --- /dev/null +++ b/lib/Plugins/SQLite3.cpp @@ -0,0 +1,255 @@ +/* + DebugDump.h - header file for the library caring of writing new reports + to the specific directory + + 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 <sqlite3.h> +#include "SQLite3.h" +#include <string> + + +#define TABLE_NAME "CrashCatcher" + +CSQLite3::CSQLite3() : + m_sDBPath(""), + m_pDB(NULL) +{} + +bool CSQLite3::IsReported(const std::string& pUUID) +{ + vector_database_rows_t table; + GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "TABLE_NAME" WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';", table); + if(table.empty()) + { + return false; + } + return true; +} + +void CSQLite3::Exec(const std::string& pCommand) +{ + char *err; + int ret = sqlite3_exec(m_pDB, pCommand.c_str(), 0, 0, &err); + if (ret != SQLITE_OK) + { + throw std::string("SQLite3::Exec(): Error on: " + pCommand + " " + err); + } +} + +void CSQLite3::GetTable(const std::string& pCommand, vector_database_rows_t& pTable) +{ + + char **table; + int ncol, nrow; + char *err; + int ret = sqlite3_get_table(m_pDB, pCommand.c_str(), &table, &nrow, &ncol, &err); + if (ret != SQLITE_OK) + { + throw std::string("SQLite3::GetTable(): Error on: " + pCommand + " " + err); + } + pTable.clear(); + int ii; + for (ii = 0; ii < nrow; ii++) + { + int jj; + database_row_t row; + for (jj = 0; jj < ncol; jj++) + { + switch(jj) + { + case 0: row.m_sUUID = table[jj + ncol]; + break; + case 1: row.m_sDebugDumpPath = table[jj + ncol]; + break; + case 2: row.m_sArchitecture = table[jj + ncol]; + break; + case 3: row.m_sKernel = table[jj + ncol]; + break; + case 4: row.m_sExecutable = table[jj + ncol]; + break; + case 5: row.m_sPackage = table[jj + ncol]; + break; + case 6: row.m_sUID = table[jj + ncol]; + break; + case 7: row.m_sTime = table[jj + ncol]; + break; + case 8: row.m_sCount = table[jj + ncol]; + break; + case 9: row.m_sReported = table[jj + ncol]; + break; + case 10: row.m_sBackTrace = table[jj + ncol]; + break; + case 11: row.m_sTextData1 = table[jj + ncol]; + break; + default: + break; + } + } + pTable.push_back(row); + } + sqlite3_free_table(table); +} + + +void CSQLite3::Connect() +{ + int ret = sqlite3_open_v2(m_sDBPath.c_str(), + &m_pDB, + SQLITE_OPEN_READWRITE, + NULL); + + if(ret == SQLITE_CANTOPEN) + { + Create(); + } + else if (ret != SQLITE_OK) + { + throw std::string("SQLite3::Connect(): Could not open database.") + sqlite3_errmsg(m_pDB); + } +} + +void CSQLite3::Create() +{ + int ret = sqlite3_open_v2(m_sDBPath.c_str(), + &m_pDB, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, + NULL); + if(ret != SQLITE_OK) + { + throw std::string("SQLite3::Create(): Could not create database.") + sqlite3_errmsg(m_pDB); + } + + Exec("CREATE TABLE "TABLE_NAME"(" + DATABASE_COLUMN_UUID" VARCHAR NOT NULL PRIMARY KEY," + DATABASE_COLUMN_DEBUG_DUMP_PATH" VARCHAR NOT NULL," + DATABASE_COLUMN_ARCHITECTURE" VARCHAR(16) NOT NULL," + DATABASE_COLUMN_KERNEL" VARCHAR(32) NOT NULL," + DATABASE_COLUMN_EXECUTABLE" VARCHAR NOT NULL," + DATABASE_COLUMN_PACKAGE" VARCHAR(64) NOT NULL," + DATABASE_COLUMN_UID" VARCHAR(64) NOT NULL," + DATABASE_COLUMN_TIME" VARCHAR(32) NOT NULL," + DATABASE_COLUMN_COUNT" INT(10) NOT NULL DEFAULT 1," + DATABASE_COLUMN_REPORTED" INT(10) NOT NULL DEFAULT 0," + DATABASE_COLUMN_BACKTRACE" VARCHAR DEFAULT \"\"," + DATABASE_COLUMN_TEXTDATA1" VARCHAR DEFAULT \"\"" + ");"); +} + +void CSQLite3::DisConnect() +{ + sqlite3_close(m_pDB); +} + +void CSQLite3::Insert(const std::string& pUUID, + const std::string& pDebugDumpPath, + const std::string& pArch, + const std::string& pKernel, + const std::string& pExecutable, + const std::string& pPackage, + const std::string& pUID, + const std::string& pTime) +{ + if (!IsReported(pUUID)) + { + Exec("INSERT INTO "TABLE_NAME"(" + DATABASE_COLUMN_UUID"," + DATABASE_COLUMN_DEBUG_DUMP_PATH"," + DATABASE_COLUMN_ARCHITECTURE"," + DATABASE_COLUMN_KERNEL"," + DATABASE_COLUMN_EXECUTABLE"," + DATABASE_COLUMN_PACKAGE"," + DATABASE_COLUMN_UID"," + DATABASE_COLUMN_TIME")" + " VALUES ('"+pUUID+"'" + "'"+pDebugDumpPath+"'" + "'"+pArch+"'" + "'"+pKernel+"'" + "'"+pExecutable+"'" + "'"+pPackage+"'" + "'"+pUID+"'" + "'"+pTime+"'" + ");"); + } + else + { + Exec("UPDATE "TABLE_NAME" " + "SET "DATABASE_COLUMN_COUNT" = "DATABASE_COLUMN_COUNT" + 1 " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + } +} + +void CSQLite3::Delete(const std::string& pUUID) +{ + if (IsReported(pUUID)) + { + Exec("DELETE FROM "TABLE_NAME + " WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + } +} + +void CSQLite3::InsertBackTrace(const std::string& pUUID, + const std::string& pBackTrace) +{ + if (IsReported(pUUID)) + { + Exec("UPDATE "TABLE_NAME + "SET "DATABASE_COLUMN_BACKTRACE" = "+pBackTrace+ + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + } +} + +void CSQLite3::InsertTextData1(const std::string& pUUID, + const std::string& pData) +{ + if (IsReported(pUUID)) + { + Exec("UPDATE "TABLE_NAME + "SET "DATABASE_COLUMN_TEXTDATA1" = "+pData+ + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + } +} + +const vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) +{ + vector_database_rows_t table; + if (pUID == "0") + { + GetTable("SELECT * FROM "TABLE_NAME";", table); + Exec("UPDATE "TABLE_NAME" SET "DATABASE_COLUMN_REPORTED" = 1;"); + } + else + { + GetTable("SELECT * FROM "TABLE_NAME + " WHERE "DATABASE_COLUMN_UID" = '"+pUID+"';", + table); + Exec("UPDATE "TABLE_NAME + " SET "DATABASE_COLUMN_REPORTED" = 1 " + " WHERE "DATABASE_COLUMN_UID" = '"+pUID+"';"); + } + return table; +} + +void CSQLite3::Init(const map_settings_t& pSettings) +{ + if (pSettings.find("DBPath")!= pSettings.end()) + { + m_sDBPath = pSettings.find("DBPath")->second; + } +} diff --git a/lib/Plugins/SQLite3.h b/lib/Plugins/SQLite3.h new file mode 100644 index 00000000..5270988e --- /dev/null +++ b/lib/Plugins/SQLite3.h @@ -0,0 +1,80 @@ +/* + DebugDump.h - header file for the library caring of writing new reports + to the specific directory + + 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. + */ + +#ifndef SQLITE3_H_ +#define SQLITE3_H_ + +#include "Plugin.h" +#include "Database.h" + +class CSQLite3 : public CDatabase +{ + private: + + std::string m_sDBPath; + sqlite3* m_pDB; + + void Create(); + void Exec(const std::string& pCommand); + void GetTable(const std::string& pCommand, vector_database_rows_t& pTable); + bool IsReported(const std::string& pUUID); + + public: + CSQLite3(); + virtual ~CSQLite3() {} + + void Connect(); + void DisConnect(); + + void Insert(const std::string& pUUID, + const std::string& pDebugDumpPath, + const std::string& pArch, + const std::string& pKernel, + const std::string& pExecutable, + const std::string& pPackage, + const std::string& pUID, + const std::string& pTime); + + void InsertBackTrace(const std::string& pUUID, + const std::string& pBackTrace); + + void InsertTextData1(const std::string& pUUID, + const std::string& pData); + + void Delete(const std::string& pUUID); + + const vector_database_rows_t GetUIDData(const std::string& pUID); + + void Init(const map_settings_t& pSettings); + void DeInit() {} +}; + +PLUGIN_INFO(DATABASE, + "SQLite3", + "0.0.1", + "SQLite3 database plugin.", + "zprikryl@redhat.com", + "https://fedorahosted.org/crash-catcher/wiki"); + +PLUGIN_INIT(CSQLite3); + +#endif /* SQLITE3_H_ */ |