diff options
author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-09-08 17:08:16 +0200 |
---|---|---|
committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-09-08 17:08:16 +0200 |
commit | f02e1d87d46aa6161d0cab5444e0abfa9624b78d (patch) | |
tree | cc1148c8ef544818a7995074e679a987ba325a44 /lib | |
parent | 58d9dfde6ce788c5ffdfe5160d19aaeb8ac7b3a2 (diff) | |
parent | ff2627e7c597e50025ca4d91ff8168eec80f9054 (diff) | |
download | abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.tar.gz abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.tar.xz abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.zip |
Merge branch 'master' of git://git.fedorahosted.org/abrt
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 71 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.h | 4 | ||||
-rw-r--r-- | lib/CommLayer/Observer.h | 4 | ||||
-rw-r--r-- | lib/MiddleWare/Database.h | 4 | ||||
-rw-r--r-- | lib/Plugins/CCpp.cpp | 31 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.cpp | 73 | ||||
-rw-r--r-- | lib/Plugins/SQLite3.h | 7 |
7 files changed, 107 insertions, 87 deletions
diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp index ec4dc904..5450b41c 100644 --- a/lib/CommLayer/CommLayerInner.cpp +++ b/lib/CommLayer/CommLayerInner.cpp @@ -1,50 +1,63 @@ -#include <pthread.h> /* pthread_self() */ +#include <pthread.h> +#include <map> #include "abrtlib.h" #include "CommLayerInner.h" static CObserver *s_pObs; -static pthread_t s_main_id; + +typedef std::map<uint64_t, std::string> map_uint_str_t; +static map_uint_str_t s_mapClientID; +static pthread_mutex_t s_map_mutex; +static bool s_map_mutex_inited; void init_daemon_logging(CObserver *pObs) { s_pObs = pObs; - s_main_id = pthread_self(); + if (!s_map_mutex_inited) + { + pthread_mutex_init(&s_map_mutex, NULL); + s_map_mutex_inited = true; + } +} + +void set_client_name(const char* name) +{ + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + if (!name) + s_mapClientID.erase(key); + else + s_mapClientID[key] = name; + pthread_mutex_unlock(&s_map_mutex); } void warn_client(const std::string& pMessage) { if (!s_pObs) return; - pthread_t self = pthread_self(); - if (self != s_main_id) - { - s_pObs->Warning(pMessage,(uint64_t)self); -//log("w: '%s'", s.c_str()); - } - else - { - s_pObs->Warning(pMessage); -// debug: this should not happen - if it is, we are trying to log to a client -// but we have no job id! -log("W: '%s'", pMessage.c_str()); - } + + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + map_uint_str_t::const_iterator ki = s_mapClientID.find(key); + const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); + pthread_mutex_unlock(&s_map_mutex); + + s_pObs->Warning(pMessage, peer, key); } void update_client(const std::string& pMessage) { if (!s_pObs) return; - pthread_t self = pthread_self(); - if (self != s_main_id) - { - s_pObs->Status(pMessage, (uint64_t)self); -//log("u: '%s'", s.c_str()); - } - else - { - s_pObs->Status(pMessage); -// debug: this should not happen - if it is, we are trying to log to a client -// but we have no job id! -log("U: '%s'", pMessage.c_str()); - } + + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + map_uint_str_t::const_iterator ki = s_mapClientID.find(key); + const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); + pthread_mutex_unlock(&s_map_mutex); + + s_pObs->Status(pMessage, peer, key); } diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h index 2b4f63a3..d161cfc7 100644 --- a/lib/CommLayer/CommLayerInner.h +++ b/lib/CommLayer/CommLayerInner.h @@ -5,6 +5,10 @@ void init_daemon_logging(CObserver *pObs); +/* + * Set client's name (dbus ID). NULL unsets it. + */ +void set_client_name(const char* name); /* Ask a client to warn the user about a non-fatal, but unexpected condition. * In GUI, it will usually be presented as a popup message. */ diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h index 5c983949..421dc0cc 100644 --- a/lib/CommLayer/Observer.h +++ b/lib/CommLayer/Observer.h @@ -9,8 +9,8 @@ class CObserver { public: virtual ~CObserver() {} - virtual void Status(const std::string& pMessage, uint64_t pDest=0) = 0; - virtual void Warning(const std::string& pMessage, uint64_t pDest=0) = 0; + virtual void Status(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; + virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; }; #endif diff --git a/lib/MiddleWare/Database.h b/lib/MiddleWare/Database.h index ce29f18b..0fc31ee7 100644 --- a/lib/MiddleWare/Database.h +++ b/lib/MiddleWare/Database.h @@ -111,7 +111,7 @@ class CDatabase : public CPlugin * @param pUID An UID of an user. * @return A vector of matched rows. */ - virtual const vector_database_rows_t GetUIDData(const std::string& pUID) = 0; + virtual vector_database_rows_t GetUIDData(const std::string& pUID) = 0; /** * A method, which returns one row accordind to UUID of a crash and * UID of an user. If there are no row, empty row is returned. @@ -119,7 +119,7 @@ class CDatabase : public CPlugin * @param pUID An UID of an user. * @return A matched row. */ - virtual const database_row_t GetUUIDData(const std::string& pUUID, + virtual database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID) = 0; }; diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 2d0326c5..995ddbeb 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -428,22 +428,24 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) { update_client(_("Getting local universal unique identification...")); - CDebugDump dd; std::string UID; std::string executable; std::string package; std::string buildIdPC; std::string independentBuildIdPC; - std::string core = "--core="+ pDebugDumpDir + "/" +FILENAME_COREDUMP; + std::string core = "--core=" + pDebugDumpDir + "/"FILENAME_COREDUMP; char* command = (char*)"eu-unstrip"; char* args[4] = { (char*)"eu-unstrip", NULL, (char*)"-n", NULL }; args[1] = (char*)core.c_str(); + + CDebugDump dd; dd.Open(pDebugDumpDir); dd.LoadText(FILENAME_UID, UID); dd.LoadText(FILENAME_EXECUTABLE, executable); dd.LoadText(FILENAME_PACKAGE, package); ExecVP(command, args, atoi(UID.c_str()), buildIdPC); dd.Close(); + GetIndependentBuildIdPC(buildIdPC, independentBuildIdPC); return CreateHash(package + executable + independentBuildIdPC); } @@ -484,14 +486,13 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir) dd.Close(); map_plugin_settings_t settings = GetSettings(); - if( settings["InstallDebuginfo"] == "yes" ) + if (settings["InstallDebuginfo"] == "yes") { InstallDebugInfos(package); } - else { - char buffer[1024]; - snprintf(buffer,1024, _("Skip debuginfo installation for package %s"), package.c_str()); - warn_client(std::string(buffer)); + else + { + warn_client(ssprintf(_("Skip debuginfo installation for package %s"), package.c_str())); } GetBacktrace(pDebugDumpDir, backtrace); @@ -554,17 +555,21 @@ void CAnalyzerCCpp::DeInit() void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { - if (pSettings.find("MemoryMap") != pSettings.end()) + map_plugin_settings_t::const_iterator end = pSettings.end(); + map_plugin_settings_t::const_iterator it = pSettings.find("MemoryMap"); + if (it != end) { - m_bMemoryMap = pSettings.find("MemoryMap")->second == "yes"; + m_bMemoryMap = it->second == "yes"; } - if (pSettings.find("DebugInfo") != pSettings.end()) + it = pSettings.find("DebugInfo"); + if (it != end) { - m_sDebugInfo = pSettings.find("DebugInfo")->second; + m_sDebugInfo = it->second; } - if (pSettings.find("InstallDebuginfo") != pSettings.end()) + it = pSettings.find("InstallDebuginfo"); + if (it != end) { - m_bInstallDebuginfo = pSettings.find("InstallDebuginfo")->second == "yes"; + m_bInstallDebuginfo = it->second == "yes"; } } diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index a57da240..700ac913 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -1,6 +1,5 @@ /* - DebugDump.h - header file for the library caring of writing new reports - to the specific directory + SQLite3.cpp Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) Copyright (C) 2009 RedHat inc. @@ -33,7 +32,7 @@ #define ABRT_TABLE "abrt_v"ABRT_TABLE_VERSION_STR #define SQLITE3_MASTER_TABLE "sqlite_master" -// afret a while, we can drom a support for update, so a table can stay in +// after a while, we can drop support for update, so a table can stay in // normal limits static const char* upate_sql_commands[][ABRT_TABLE_VERSION + 1] = { // v0 -> * @@ -100,9 +99,9 @@ bool CSQLite3::Exist(const std::string& pUUID, const std::string& pUID) GetTable("SELECT "DATABASE_COLUMN_REPORTED" FROM "ABRT_TABLE" WHERE " DATABASE_COLUMN_UUID" = '"+pUUID+"' AND " DATABASE_COLUMN_UID" = '"+pUID+"';", table); - if(table.empty()) + if (table.empty()) { - return false; + return false; } return true; } @@ -113,7 +112,7 @@ void CSQLite3::Exec(const std::string& pCommand) int ret = sqlite3_exec(m_pDB, pCommand.c_str(), 0, 0, &err); if (ret != SQLITE_OK) { - throw CABRTException(EXCEP_PLUGIN, "SQLite3::Exec(): Error on: " + pCommand + " " + err); + throw CABRTException(EXCEP_PLUGIN, "SQLite3::Exec(): Error on: " + pCommand + " " + err); } } @@ -211,7 +210,7 @@ bool CSQLite3::CheckTable() int ret = sqlite3_get_table(m_pDB, command.c_str(), &table, &nrow, &ncol, &err); if (ret != SQLITE_OK) { - throw CABRTException(EXCEP_PLUGIN, "SQLite3::GetTable(): Error on: " + command + " " + err); + throw CABRTException(EXCEP_PLUGIN, "SQLite3::GetTable(): Error on: " + command + " " + err); } if (!nrow || !nrow) { @@ -281,24 +280,24 @@ void CSQLite3::Insert(const std::string& pUUID, { if (!Exist(pUUID, pUID)) { - Exec("INSERT INTO "ABRT_TABLE"(" - DATABASE_COLUMN_UUID"," - DATABASE_COLUMN_UID"," - DATABASE_COLUMN_DEBUG_DUMP_PATH"," - DATABASE_COLUMN_TIME")" - " VALUES ('"+pUUID+"'," - "'"+pUID+"'," - "'"+pDebugDumpPath+"'," - "'"+pTime+"'" - ");"); + Exec("INSERT INTO "ABRT_TABLE"(" + DATABASE_COLUMN_UUID"," + DATABASE_COLUMN_UID"," + DATABASE_COLUMN_DEBUG_DUMP_PATH"," + DATABASE_COLUMN_TIME")" + " VALUES ('"+pUUID+"'," + "'"+pUID+"'," + "'"+pDebugDumpPath+"'," + "'"+pTime+"'" + ");"); } else { - Exec("UPDATE "ABRT_TABLE" " - "SET "DATABASE_COLUMN_COUNT" = "DATABASE_COLUMN_COUNT" + 1, " - DATABASE_COLUMN_TIME" = '"+pTime+"' " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " - "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); + Exec("UPDATE "ABRT_TABLE" " + "SET "DATABASE_COLUMN_COUNT" = "DATABASE_COLUMN_COUNT" + 1, " + DATABASE_COLUMN_TIME" = '"+pTime+"' " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } } @@ -306,14 +305,14 @@ void CSQLite3::Delete(const std::string& pUUID, const std::string& pUID) { if (pUID == "0") { - Exec("DELETE FROM "ABRT_TABLE" " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); + Exec("DELETE FROM "ABRT_TABLE" " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"';"); } else if (Exist(pUUID, pUID)) { - Exec("DELETE FROM "ABRT_TABLE" " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " - "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); + Exec("DELETE FROM "ABRT_TABLE" " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } else { @@ -325,14 +324,14 @@ void CSQLite3::SetReported(const std::string& pUUID, const std::string& pUID, co { if (Exist(pUUID, pUID)) { - Exec("UPDATE "ABRT_TABLE" " - "SET "DATABASE_COLUMN_REPORTED" = 1 " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " - "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); - Exec("UPDATE "ABRT_TABLE" " - "SET "DATABASE_COLUMN_MESSAGE" = '" + pMessage + "' " - "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " - "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); + Exec("UPDATE "ABRT_TABLE" " + "SET "DATABASE_COLUMN_REPORTED" = 1 " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); + Exec("UPDATE "ABRT_TABLE" " + "SET "DATABASE_COLUMN_MESSAGE" = '" + pMessage + "' " + "WHERE "DATABASE_COLUMN_UUID" = '"+pUUID+"' " + "AND "DATABASE_COLUMN_UID" = '"+pUID+"';"); } else { @@ -340,7 +339,7 @@ void CSQLite3::SetReported(const std::string& pUUID, const std::string& pUID, co } } -const vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) +vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) { vector_database_rows_t table; if (pUID == "0") @@ -356,7 +355,7 @@ const vector_database_rows_t CSQLite3::GetUIDData(const std::string& pUID) return table; } -const database_row_t CSQLite3::GetUUIDData(const std::string& pUUID, const std::string& pUID) +database_row_t CSQLite3::GetUUIDData(const std::string& pUUID, const std::string& pUID) { vector_database_rows_t table; diff --git a/lib/Plugins/SQLite3.h b/lib/Plugins/SQLite3.h index 1604d3be..e7ca8ae2 100644 --- a/lib/Plugins/SQLite3.h +++ b/lib/Plugins/SQLite3.h @@ -1,6 +1,5 @@ /* - DebugDump.h - header file for the library caring of writing new reports - to the specific directory + SQLite3.h Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) Copyright (C) 2009 RedHat inc. @@ -55,8 +54,8 @@ class CSQLite3 : public CDatabase virtual void Delete(const std::string& pUUID, const std::string& pUID); virtual void SetReported(const std::string& pUUID, const std::string& pUID, const std::string& pMessage); - virtual const vector_database_rows_t GetUIDData(const std::string& pUID); - virtual const database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID); + virtual vector_database_rows_t GetUIDData(const std::string& pUID); + virtual database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID); virtual void SetSettings(const map_plugin_settings_t& pSettings); virtual map_plugin_settings_t GetSettings(); |