diff options
-rw-r--r-- | inc/ABRTException.h | 26 | ||||
-rw-r--r-- | lib/Plugins/Bugzilla.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/FileTransfer.cpp | 6 | ||||
-rw-r--r-- | lib/Plugins/Firefox.cpp | 4 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsReporter.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/Logger.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/SOSreport.cpp | 7 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.cpp | 8 | ||||
-rw-r--r-- | lib/Plugins/TicketUploader.cpp | 13 | ||||
-rw-r--r-- | lib/Utils/ABRTException.cpp | 15 | ||||
-rw-r--r-- | lib/Utils/DebugDump.cpp | 26 | ||||
-rw-r--r-- | lib/Utils/Makefile.am | 3 | ||||
-rw-r--r-- | lib/Utils/abrt_xmlrpc.cpp | 2 | ||||
-rw-r--r-- | src/Daemon/CommLayerServerSocket.cpp | 2 | ||||
-rw-r--r-- | src/Daemon/PluginManager.cpp | 18 |
16 files changed, 75 insertions, 63 deletions
diff --git a/inc/ABRTException.h b/inc/ABRTException.h index fe7fc01e..dc18132e 100644 --- a/inc/ABRTException.h +++ b/inc/ABRTException.h @@ -1,7 +1,7 @@ #ifndef ABRTEXCEPTION_H_ #define ABRTEXCEPTION_H_ -#include <string> +#include "abrtlib.h" typedef enum { EXCEP_UNKNOW, @@ -21,21 +21,19 @@ typedef enum { class CABRTException /*: public std::exception*/ { private: - std::string m_sWhat; - abrt_exception_t m_Type; + abrt_exception_t m_type; + char *m_what; + + /* Not defined. You can't use it */ + CABRTException& operator= (const CABRTException&); public: - /* virtual ~CABRTException() throw() {} */ - CABRTException(abrt_exception_t pType, const char* pWhat) : - m_sWhat(pWhat), - m_Type(pType) - {} - CABRTException(abrt_exception_t pType, const std::string& pWhat) : - m_sWhat(pWhat), - m_Type(pType) - {} - abrt_exception_t type() { return m_Type; } - const char* what() const { return m_sWhat.c_str(); } + ~CABRTException() { free(m_what); } + CABRTException(abrt_exception_t type, const char* fmt, ...); + CABRTException(const CABRTException& rhs); + + abrt_exception_t type() { return m_type; } + const char* what() const { return m_what; } }; #endif diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index f17f9a74..8a318d30 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -52,7 +52,7 @@ void ctx::login(const char* login, const char* passwd) std::string errmsg = ssprintf("Can't login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", env.fault_string); xmlrpc_env_clean(&env); error_msg("%s", errmsg.c_str()); // show error in daemon log - throw CABRTException(EXCEP_PLUGIN, errmsg); + throw CABRTException(EXCEP_PLUGIN, errmsg.c_str()); } } diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp index 868f54dd..8fff3a93 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -79,12 +79,12 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename) f = fopen(pFilename, "r"); if (!f) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't open archive file '%s'", pFilename)); + throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename); } if (fstat(fileno(f), &buf) == -1) { fclose(f); - throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't stat archive file '%s'", pFilename)); + throw CABRTException(EXCEP_PLUGIN, "Can't stat archive file '%s'", pFilename); } curl = curl_easy_init(); if (!curl) @@ -282,7 +282,7 @@ void CFileTransfer::CreateArchive(const char *pArchiveName, const char *pDir) } else { - throw CABRTException(EXCEP_PLUGIN, "Unknown/unsupported archive type " + m_sArchiveType); + throw CABRTException(EXCEP_PLUGIN, "Unknown/unsupported archive type %s", m_sArchiveType.c_str()); } } diff --git a/lib/Plugins/Firefox.cpp b/lib/Plugins/Firefox.cpp index 68dbd39e..2a35dc1d 100644 --- a/lib/Plugins/Firefox.cpp +++ b/lib/Plugins/Firefox.cpp @@ -100,7 +100,7 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) struct passwd* pw = getpwuid(uid); if (!pw) { - throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": cannot get GID for UID."); + throw CABRTException(EXCEP_PLUGIN, "%s: can't get GID for UID", __func__); } xpipe(pipeout); @@ -662,7 +662,7 @@ Another application is holding the yum lock, cannot continue fclose(pipeout_fp); kill(child, SIGTERM); wait(NULL); - throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": cannot install debuginfos for " + pPackage); + throw CABRTException(EXCEP_PLUGIN, "%s: can't install debuginfos for %s", __func__, pPackage); } #endif } diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index a1fd3f16..376db25a 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -111,7 +111,7 @@ std::string CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, if (ret) { /* FIXME: be more informative */ - throw CABRTException(EXCEP_PLUGIN, std::string("CKerneloopsReporter::Report(): Report has not been sent...")); + throw CABRTException(EXCEP_PLUGIN, "CKerneloopsReporter::Report(): Report has not been sent"); } return "Kernel oops report was uploaded."; } diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 3831f9e6..128e0837 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -109,7 +109,7 @@ void CKerneloopsScanner::SaveOopsToDebugDump() } catch (CABRTException& e) { - throw CABRTException(EXCEP_PLUGIN, std::string(__func__) + ": " + e.what()); + throw CABRTException(EXCEP_PLUGIN, "%s: %s", __func__, e.what()); } oopsList.pop_back(); } diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index 7267b648..9f261a38 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -84,7 +84,7 @@ std::string CLogger::Report(const map_crash_report_t& pCrashReport, return "file://" + m_sLogPath; } - throw CABRTException(EXCEP_PLUGIN, "CLogger::Report(): Cannot open file: " + m_sLogPath); + throw CABRTException(EXCEP_PLUGIN, "Can't open file '%s'", m_sLogPath); } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp index 65d01a72..6f231659 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -104,10 +104,9 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs) if (copy_file(sosreport_filename.c_str(), sosreport_dd_filename.c_str()) < 0) { throw CABRTException(EXCEP_PLUGIN, - ssprintf("Can't copy '%s' to '%s'", - sosreport_filename.c_str(), - sosreport_dd_filename.c_str() - ) + "Can't copy '%s' to '%s'", + sosreport_filename.c_str(), + sosreport_dd_filename.c_str() ); } } diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index 866b9857..d95c273b 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -107,7 +107,7 @@ static void get_table(vector_database_rows_t& pTable, string errstr = ssprintf("Error in SQL:'%s' error: %s", sql, err); free(sql); sqlite3_free(err); - throw CABRTException(EXCEP_PLUGIN, errstr); + throw CABRTException(EXCEP_PLUGIN, errstr.c_str()); } VERB2 log("%d rows returned by SQL:%s", nrow, sql); free(sql); @@ -152,7 +152,7 @@ static void execute_sql(sqlite3 *db, const char *fmt, ...) string errstr = ssprintf("Error in SQL:'%s' error: %s", sql, err); free(sql); sqlite3_free(err); - throw CABRTException(EXCEP_PLUGIN, errstr); + throw CABRTException(EXCEP_PLUGIN, errstr.c_str()); } VERB2 log("%d rows affected by SQL:%s", sqlite3_changes(db), sql); free(sql); @@ -262,7 +262,7 @@ void CSQLite3::Connect() { if (ret != SQLITE_CANTOPEN) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("CheckDB: Can't open database: %s", sqlite3_errmsg(m_pDB))); + throw CABRTException(EXCEP_PLUGIN, "Can't open database: %s", sqlite3_errmsg(m_pDB)); } ret = sqlite3_open_v2(m_sDBPath.c_str(), @@ -272,7 +272,7 @@ void CSQLite3::Connect() ); if (ret != SQLITE_OK) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't create database: %s", sqlite3_errmsg(m_pDB))); + throw CABRTException(EXCEP_PLUGIN, "Can't create database: %s", sqlite3_errmsg(m_pDB)); } } diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index 847efdc0..687e7062 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -117,12 +117,12 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) FILE* f = fopen(pFilename, "r"); if (!f) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't open archive file '%s'", pFilename)); + throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename); } struct stat buf; - if (fstat(fileno(f), &buf) == -1) + if (fstat(fileno(f), &buf) == -1) /* TODO: never fails */ { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't stat archive file '%s'", pFilename)); + throw CABRTException(EXCEP_PLUGIN, "Can't stat archive file '%s'", pFilename); } CURL* curl = curl_easy_init(); if (!curl) @@ -225,10 +225,9 @@ string CTicketUploader::Report(const map_crash_report_t& pCrashReport, if (copy_file(it->second[CD_CONTENT].c_str(), ofile_name.c_str()) < 0) { throw CABRTException(EXCEP_PLUGIN, - ssprintf("Can't copy '%s' to '%s'", - it->second[CD_CONTENT].c_str(), - ofile_name.c_str() - ) + "Can't copy '%s' to '%s'", + it->second[CD_CONTENT].c_str(), + ofile_name.c_str() ); } } diff --git a/lib/Utils/ABRTException.cpp b/lib/Utils/ABRTException.cpp new file mode 100644 index 00000000..aa6c99d9 --- /dev/null +++ b/lib/Utils/ABRTException.cpp @@ -0,0 +1,15 @@ +#include "ABRTException.h" + +CABRTException::CABRTException(abrt_exception_t type, const char* fmt, ...) +{ + m_type = type; + va_list ap; + va_start(ap, fmt); + m_what = xvasprintf(fmt, ap); + va_end(ap); +} + +CABRTException::CABRTException(const CABRTException& rhs): + m_type(rhs.m_type), + m_what(xstrdup(rhs.m_what)) +{} diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 3e226f9a..b1db1698 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -77,7 +77,7 @@ void CDebugDump::Open(const char *pDir) m_sDebugDumpDir = RemoveBackSlashes(pDir); if (!ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, m_sDebugDumpDir + " does not exist"); + throw CABRTException(EXCEP_DD_OPEN, "'%s' does not exist", m_sDebugDumpDir.c_str()); } Lock(); m_bOpened = true; @@ -222,7 +222,7 @@ void CDebugDump::Create(const char *pDir, int64_t uid) m_sDebugDumpDir = RemoveBackSlashes(pDir); if (ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, ssprintf("'%s' already exists", m_sDebugDumpDir.c_str())); + throw CABRTException(EXCEP_DD_OPEN, "'%s' already exists", m_sDebugDumpDir.c_str()); } Lock(); @@ -232,13 +232,13 @@ void CDebugDump::Create(const char *pDir, int64_t uid) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't create dir '%s'", pDir)); + throw CABRTException(EXCEP_DD_OPEN, "Can't create dir '%s'", pDir); } if (chmod(m_sDebugDumpDir.c_str(), 0700) == -1) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't change mode of '%s'", pDir)); + throw CABRTException(EXCEP_DD_OPEN, "Can't change mode of '%s'", pDir); } struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; @@ -272,7 +272,7 @@ static void DeleteFileDir(const char *pDir) if (errno != EISDIR) { closedir(dir); - throw CABRTException(EXCEP_DD_DELETE, ssprintf("Can't remove dir %s", fullPath.c_str())); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove dir %s", fullPath.c_str()); } DeleteFileDir(fullPath.c_str()); } @@ -280,7 +280,7 @@ static void DeleteFileDir(const char *pDir) closedir(dir); if (remove(pDir) == -1) { - throw CABRTException(EXCEP_DD_DELETE, ssprintf("Can't remove dir %s", pDir)); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove dir %s", pDir); } } @@ -325,7 +325,7 @@ static void LoadTextFile(const char *pPath, std::string& pData) FILE *fp = fopen(pPath, "r"); if (!fp) { - throw CABRTException(EXCEP_DD_LOAD, ssprintf("Can't open file '%s'", pPath)); + throw CABRTException(EXCEP_DD_LOAD, "Can't open file '%s'", pPath); } pData = ""; int ch; @@ -348,13 +348,13 @@ static void SaveBinaryFile(const char *pPath, const char* pData, unsigned pSize) int fd = open(pPath, O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd < 0) { - throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't open file '%s'", pPath)); + throw CABRTException(EXCEP_DD_SAVE, "Can't open file '%s'", pPath); } unsigned r = full_write(fd, pData, pSize); close(fd); if (r != pSize) { - throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't save file '%s'", pPath)); + throw CABRTException(EXCEP_DD_SAVE, "Can't save file '%s'", pPath); } } @@ -362,7 +362,7 @@ void CDebugDump::LoadText(const char* pName, std::string& pData) { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::LoadText(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); LoadTextFile(fullPath.c_str(), pData); @@ -372,7 +372,7 @@ void CDebugDump::SaveText(const char* pName, const char* pData) { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::SaveText(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); SaveBinaryFile(fullPath.c_str(), pData, strlen(pData)); @@ -381,7 +381,7 @@ void CDebugDump::SaveBinary(const char* pName, const char* pData, unsigned pSize { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::SaveBinary(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); SaveBinaryFile(fullPath.c_str(), pData, pSize); @@ -400,7 +400,7 @@ void CDebugDump::InitGetNextFile() m_pGetNextFileDir = opendir(m_sDebugDumpDir.c_str()); if (m_pGetNextFileDir == NULL) { - throw CABRTException(EXCEP_DD_OPEN, "Can't open dir " + m_sDebugDumpDir); + throw CABRTException(EXCEP_DD_OPEN, "Can't open dir '%s'", m_sDebugDumpDir.c_str()); } } diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 297007a9..9618751a 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -17,7 +17,8 @@ libABRTUtils_la_SOURCES = \ popen_and_save_output.cpp \ stringops.cpp \ dirsize.cpp \ - DebugDump.h DebugDump.cpp + DebugDump.h DebugDump.cpp \ + ABRTException.cpp libABRTUtils_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../../inc \ diff --git a/lib/Utils/abrt_xmlrpc.cpp b/lib/Utils/abrt_xmlrpc.cpp index 11c431b8..7205316c 100644 --- a/lib/Utils/abrt_xmlrpc.cpp +++ b/lib/Utils/abrt_xmlrpc.cpp @@ -13,7 +13,7 @@ void throw_if_xml_fault_occurred(xmlrpc_env *env) xmlrpc_env_clean(env); // this is needed ONLY if fault_occurred xmlrpc_env_init(env); // just in case user catches ex and _continues_ to use env error_msg("%s", errmsg.c_str()); // show error in daemon log - throw CABRTException(EXCEP_PLUGIN, errmsg); + throw CABRTException(EXCEP_PLUGIN, errmsg.c_str()); } } diff --git a/src/Daemon/CommLayerServerSocket.cpp b/src/Daemon/CommLayerServerSocket.cpp index ee775c6d..80dabb71 100644 --- a/src/Daemon/CommLayerServerSocket.cpp +++ b/src/Daemon/CommLayerServerSocket.cpp @@ -40,7 +40,7 @@ std::string CCommLayerServerSocket::GetSenderUID(int pSenderSocket) socklen_t len = sizeof(creds); if (getsockopt(pSenderSocket, SOL_SOCKET, SO_PEERCRED, &creds, &len) == -1) { - throw CABRTException(EXCEP_ERROR, "CCommLayerServerSocket::GetSenderUID(): Error can get sender uid."); + throw CABRTException(EXCEP_ERROR, "CCommLayerServerSocket::GetSenderUID(): error getting sender uid"); } return to_string(creds.uid); } diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp index 58151b29..82f22e85 100644 --- a/src/Daemon/PluginManager.cpp +++ b/src/Daemon/PluginManager.cpp @@ -286,11 +286,11 @@ CAnalyzer* CPluginManager::GetAnalyzer(const char *pName) map_plugins_t::iterator plugin = m_mapPlugins.find(pName); if (plugin == m_mapPlugins.end()) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not registered", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } if (m_mapABRTPlugins[pName]->GetType() != ANALYZER) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not an analyzer plugin", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not an analyzer plugin", pName); } return (CAnalyzer*)(plugin->second); } @@ -300,11 +300,11 @@ CReporter* CPluginManager::GetReporter(const char *pName) map_plugins_t::iterator plugin = m_mapPlugins.find(pName); if (plugin == m_mapPlugins.end()) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not registered", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } if (m_mapABRTPlugins[pName]->GetType() != REPORTER) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not a reporter plugin", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not a reporter plugin", pName); } return (CReporter*)(plugin->second); } @@ -314,11 +314,11 @@ CAction* CPluginManager::GetAction(const char *pName) map_plugins_t::iterator plugin = m_mapPlugins.find(pName); if (plugin == m_mapPlugins.end()) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not registered", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } if (m_mapABRTPlugins[pName]->GetType() != ACTION) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not an action plugin", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not an action plugin", pName); } return (CAction*)(plugin->second); } @@ -328,11 +328,11 @@ CDatabase* CPluginManager::GetDatabase(const char *pName) map_plugins_t::iterator plugin = m_mapPlugins.find(pName); if (plugin == m_mapPlugins.end()) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not registered", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } if (m_mapABRTPlugins[pName]->GetType() != DATABASE) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not a database plugin", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not a database plugin", pName); } return (CDatabase*)(plugin->second); } @@ -342,7 +342,7 @@ plugin_type_t CPluginManager::GetPluginType(const char *pName) map_plugins_t::iterator plugin = m_mapPlugins.find(pName); if (plugin == m_mapPlugins.end()) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("Plugin '%s' is not registered", pName)); + throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } return m_mapABRTPlugins[pName]->GetType(); } |