diff options
author | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-04-29 12:46:18 +0200 |
---|---|---|
committer | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-04-29 12:46:18 +0200 |
commit | 1e752b178131fa0268151219deb35e09c40e29bc (patch) | |
tree | 0b6bbed34179f605d7e6759211a010edea19f9d5 | |
parent | 52291c1024050d25967b5640b04d67166b7728d2 (diff) | |
download | abrt-1e752b178131fa0268151219deb35e09c40e29bc.tar.gz abrt-1e752b178131fa0268151219deb35e09c40e29bc.tar.xz abrt-1e752b178131fa0268151219deb35e09c40e29bc.zip |
rework commlayerinner usage
new lock method in debugdump
-rw-r--r-- | lib/CommLayer/CommLayerInner.h | 5 | ||||
-rw-r--r-- | lib/CommLayer/Makefile.am | 2 | ||||
-rw-r--r-- | lib/MiddleWare/Makefile.am | 2 | ||||
-rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 26 | ||||
-rw-r--r-- | lib/MiddleWare/PluginManager.cpp | 16 | ||||
-rw-r--r-- | lib/Plugins/Bugzilla.cpp | 14 | ||||
-rw-r--r-- | lib/Plugins/CCpp.cpp | 26 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.cpp | 10 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsReporter.cpp | 4 | ||||
-rw-r--r-- | lib/Plugins/Logger.cpp | 4 | ||||
-rw-r--r-- | lib/Plugins/Mailx.cpp | 6 | ||||
-rw-r--r-- | lib/Plugins/Makefile.am | 14 | ||||
-rw-r--r-- | lib/Plugins/RunApp.cpp | 4 | ||||
-rw-r--r-- | lib/Utils/DebugDump.cpp | 83 | ||||
-rw-r--r-- | lib/Utils/DebugDump.h | 1 | ||||
-rw-r--r-- | src/Daemon/CrashWatcher.cpp | 6 | ||||
-rw-r--r-- | src/Daemon/Makefile.am | 3 |
17 files changed, 125 insertions, 101 deletions
diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h index 70e1c309..150c7b2e 100644 --- a/lib/CommLayer/CommLayerInner.h +++ b/lib/CommLayer/CommLayerInner.h @@ -102,4 +102,9 @@ class CCommLayerInner } }; +void comm_layer_inner_init(CCommLayerInner *pCommLayerInner); +void comm_layer_inner_debug(const std::string& pMessage); +void comm_layer_inner_warning(const std::string& pMessage); +void comm_layer_inner_status(const std::string& pMessage); + #endif /* COMMLAYERINNER_H_ */ diff --git a/lib/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am index c9cd7484..1e204ff1 100644 --- a/lib/CommLayer/Makefile.am +++ b/lib/CommLayer/Makefile.am @@ -3,7 +3,7 @@ libABRTCommLayer_la_SOURCES = CommLayerServer.h CommLayerServer.cpp \ CommLayerServerSocket.h CommLayerServerSocket.cpp \ CommLayerServerDBus.h CommLayerServerDBus.cpp \ DBusServerProxy.h Observer.h DBusCommon.h \ - CommLayerInner.h + CommLayerInner.h CommLayerInner.cpp libABRTCommLayer_la_LIBADD = ../../lib/MiddleWare/libABRTMiddleWare.la $(DL_LIBS) $(DBUSCPP_LIBS) libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 diff --git a/lib/MiddleWare/Makefile.am b/lib/MiddleWare/Makefile.am index d29b9137..1023aa06 100644 --- a/lib/MiddleWare/Makefile.am +++ b/lib/MiddleWare/Makefile.am @@ -8,7 +8,7 @@ libABRTMiddleWare_la_SOURCES = MiddleWare.cpp MiddleWare.h PluginManager.cpp \ 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 $(RPM_CFLAGS) +libABRTMiddleWare_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer $(RPM_CFLAGS) check_PROGRAMS = test test_SOURCES = test.cpp diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index bed81bbf..03285ee7 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -22,7 +22,7 @@ #include "MiddleWare.h" #include "DebugDump.h" #include "ABRTException.h" -#include <iostream> +#include "CommLayerInner.h" CMiddleWare::CMiddleWare(const std::string& pPlugisConfDir, const std::string& pPlugisLibDir) : @@ -178,7 +178,7 @@ int CMiddleWare::CreateCrashReport(const std::string& pUUID, { DeleteCrashInfo(row.m_sUUID, row.m_sUID, false); } - std::cerr << "CMiddleWare::CreateCrashReport(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): " + e.what()); return 0; } @@ -189,14 +189,7 @@ void CMiddleWare::Report(const std::string& pDebugDumpDir) { map_crash_report_t crashReport; - try - { - DebugDumpToCrashReport(pDebugDumpDir, crashReport); - } - catch (CABRTException& e) - { - std::cerr << "CMiddleWare::Report(): " << e.what() << std::endl; - } + DebugDumpToCrashReport(pDebugDumpDir, crashReport); set_reporters_t::iterator it_r; for (it_r = m_setReporters.begin(); it_r != m_setReporters.end(); it_r++) @@ -208,7 +201,8 @@ void CMiddleWare::Report(const std::string& pDebugDumpDir) } catch (CABRTException& e) { - std::cerr << "CMiddleWare::Report(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::Report(): " + e.what()); + comm_layer_inner_status("Reporting via '"+(*it_r).first+"' was not successful: " + e.what()); } } } @@ -239,7 +233,8 @@ void CMiddleWare::Report(const map_crash_report_t& pCrashReport) } catch (CABRTException& e) { - std::cerr << "CMiddleWare::Report(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::Report(): " + e.what()); + comm_layer_inner_status("Reporting via '"+(*it_r).first+"' was not successful: " + e.what()); } } } @@ -357,7 +352,8 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st } catch (CABRTException& e) { - std::cerr << "CMiddleWare::RunAnalyzerActions(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::RunAnalyzerActions(): " + e.what()); + comm_layer_inner_status("Action performed by '"+(*it_a).first+"' was not successful: " + e.what()); } } } @@ -435,7 +431,7 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_ { DeleteDebugDumpDir(pDebugDumpDir); } - std::cerr << "CMiddleWare::SaveDebugDump(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::SaveDebugDump(): " + e.what()); return 0; } } @@ -461,7 +457,7 @@ map_crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID, { DeleteCrashInfo(row.m_sUUID, row.m_sUID, false); } - std::cerr << "CMiddleWare::GetCrashInfo(): " << e.what() << std::endl; + comm_layer_inner_warning("CMiddleWare::GetCrashInfo(): " + e.what()); return crashInfo; } diff --git a/lib/MiddleWare/PluginManager.cpp b/lib/MiddleWare/PluginManager.cpp index 8b01f478..48560e4d 100644 --- a/lib/MiddleWare/PluginManager.cpp +++ b/lib/MiddleWare/PluginManager.cpp @@ -22,7 +22,7 @@ #include <iostream> #include "PluginManager.h" #include "ABRTException.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include <dirent.h> #include <stdio.h> #include <sys/types.h> @@ -84,7 +84,7 @@ void CPluginManager::LoadPlugin(const std::string& pName) { throw CABRTException(EXCEP_PLUGIN, "CPluginManager::LoadPlugin(): non-compatible plugin"); } - ABRTCommLayer::debug("Plugin " + pName + " (" + abrtPlugin->GetVersion() + ") succesfully loaded."); + comm_layer_inner_debug("Plugin " + pName + " (" + abrtPlugin->GetVersion() + ") succesfully loaded."); m_mapABRTPlugins[pName] = abrtPlugin; } catch (CABRTException& e) @@ -93,8 +93,8 @@ void CPluginManager::LoadPlugin(const std::string& pName) { delete abrtPlugin; } - ABRTCommLayer::warning("CPluginManager::LoadPlugin(): " + e.what()); - ABRTCommLayer::warning("Failed to load plugin " + pName); + comm_layer_inner_warning("CPluginManager::LoadPlugin(): " + e.what()); + comm_layer_inner_warning("Failed to load plugin " + pName); } } } @@ -106,7 +106,7 @@ void CPluginManager::UnLoadPlugin(const std::string& pName) UnRegisterPlugin(pName); delete m_mapABRTPlugins[pName]; m_mapABRTPlugins.erase(pName); - ABRTCommLayer::debug("Plugin " + pName + " sucessfully unloaded."); + comm_layer_inner_debug("Plugin " + pName + " sucessfully unloaded."); } } @@ -126,14 +126,14 @@ void CPluginManager::RegisterPlugin(const std::string& pName) } catch (std::string sError) { - ABRTCommLayer::warning("Can not initialize plugin " + pName + "(" + comm_layer_inner_warning("Can not initialize plugin " + pName + "(" + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + ")"); UnLoadPlugin(pName); return; } m_mapPlugins[pName] = plugin; - ABRTCommLayer::debug("Registred plugin " + pName + "(" + comm_layer_inner_debug("Registred plugin " + pName + "(" + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + ")"); } @@ -149,7 +149,7 @@ void CPluginManager::UnRegisterPlugin(const std::string& pName) m_mapPlugins[pName]->DeInit(); delete m_mapPlugins[pName]; m_mapPlugins.erase(pName); - ABRTCommLayer::debug("UnRegistred plugin " + pName + "(" + comm_layer_inner_debug("UnRegistred plugin " + pName + "(" + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + ")"); } diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 7a56966a..73b5b0e6 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -4,7 +4,7 @@ #include "PluginSettings.h" #include "DebugDump.h" #include "ABRTException.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include <iostream> CReporterBugzilla::CReporterBugzilla() : @@ -35,7 +35,7 @@ void CReporterBugzilla::Login() { rpc->call(m_pXmlrpcClient, m_pCarriageParm); ret = xmlrpc_c::value_struct(rpc->getResult()); - ABRTCommLayer::debug("Login id: " + xmlrpc_c::value_int(ret["id"])); + comm_layer_inner_debug("Login id: " + xmlrpc_c::value_int(ret["id"])); } catch (std::exception& e) { @@ -156,7 +156,7 @@ void CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) { rpc->call(m_pXmlrpcClient, m_pCarriageParm); ret = xmlrpc_c::value_struct(rpc->getResult()); - ABRTCommLayer::debug("New bug id: " + xmlrpc_c::value_int(ret["id"])); + comm_layer_inner_debug("New bug id: " + xmlrpc_c::value_int(ret["id"])); } catch (std::exception& e) { @@ -170,15 +170,15 @@ void CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std std::string package = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; std::string component = package.substr(0, package.rfind("-", package.rfind("-")-1)); std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; - ABRTCommLayer::status("Logging into bugzilla..."); + comm_layer_inner_status("Logging into bugzilla..."); Login(); - ABRTCommLayer::status("Checking for duplicates..."); + comm_layer_inner_status("Checking for duplicates..."); if (!CheckUUIDInBugzilla(component, uuid)) { - ABRTCommLayer::status("Creating new bug..."); + comm_layer_inner_status("Creating new bug..."); NewBug(pCrashReport); } - ABRTCommLayer::status("Logging out..."); + comm_layer_inner_status("Logging out..."); Logout(); } diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index da52d0b2..62c1722e 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -23,10 +23,9 @@ #include "ABRTException.h" #include "DebugDump.h" #include "PluginSettings.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include <fstream> #include <sstream> -#include <iostream> #include <ctype.h> #include <unistd.h> #include <sys/types.h> @@ -86,10 +85,10 @@ std::string CAnalyzerCCpp::CreateHash(const std::string& pInput) return ss.str(); } - +#include <iostream> void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) { - ABRTCommLayer::status("Installing debug infos..."); + comm_layer_inner_status("Installing debug infos..."); std::string packageName = pPackage.substr(0, pPackage.rfind("-", pPackage.rfind("-")-1)); char buff[1024]; @@ -153,11 +152,18 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) else { buff[r] = '\0'; - std::cerr << buff; + comm_layer_inner_debug(buff); if (strstr(buff, packageName.c_str()) != NULL && strstr(buff, "already installed and latest version") != NULL) { - already_installed = true; + char* ii = strstr(buff, packageName.c_str()); + char* jj = strstr(ii, "\n"); + char* kk = strstr(ii, "already installed and latest version"); + + if (jj > kk) + { + already_installed = true; + } } if (already_installed == false && (strstr(buff, "No debuginfo packages available to install") != NULL || @@ -195,7 +201,7 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace) { - ABRTCommLayer::status("Getting backtrace..."); + comm_layer_inner_status("Getting backtrace..."); std::string tmpFile = "/tmp/" + pDebugDumpDir.substr(pDebugDumpDir.rfind("/")); std::ofstream fTmp; @@ -422,7 +428,7 @@ void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std: std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) { - ABRTCommLayer::status("Getting local universal unique identification..."); + comm_layer_inner_status("Getting local universal unique identification..."); CDebugDump dd; std::string UID; @@ -446,7 +452,7 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) } std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) { - ABRTCommLayer::status("Getting global universal unique identification..."); + comm_layer_inner_status("Getting global universal unique identification..."); std::string backtrace; std::string executable; @@ -464,7 +470,7 @@ std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir) { - ABRTCommLayer::status("Starting report creation..."); + comm_layer_inner_status("Starting report creation..."); std::string package; std::string backtrace; diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index 3b8fce6a..c868bae3 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -29,7 +29,7 @@ #include "DebugDump.h" #include "PluginSettings.h" #include "ABRTException.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include <sstream> #include <assert.h> @@ -59,7 +59,7 @@ void CAnalyzerKerneloops::WriteSysLog(int m_nCount) std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) { - ABRTCommLayer::status("Getting local/global universal unique identification..."); + comm_layer_inner_status("Getting local/global universal unique identification..."); std::string m_sOops; std::stringstream m_sHash; @@ -88,7 +88,7 @@ std::string CAnalyzerKerneloops::GetGlobalUUID(const std::string& pDebugDumpDir) void CAnalyzerKerneloops::Report() { - ABRTCommLayer::status("Creating crash reports..."); + comm_layer_inner_status("Creating crash reports..."); CDebugDump m_pDebugDump; char m_sPath[PATH_MAX]; @@ -162,7 +162,7 @@ void CAnalyzerKerneloops::Init() void CAnalyzerKerneloops::ScanDmesg() { - ABRTCommLayer::debug("Scanning dmesg..."); + comm_layer_inner_debug("Scanning dmesg..."); int m_nFoundOopses; char *buffer; @@ -179,7 +179,7 @@ void CAnalyzerKerneloops::ScanDmesg() void CAnalyzerKerneloops::ScanSysLogFile(const char *filename, int issyslog) { - ABRTCommLayer::debug("Scanning syslog..."); + comm_layer_inner_debug("Scanning syslog..."); char *buffer; struct stat statb; diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index cbefe0ed..b0231066 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -26,7 +26,7 @@ #include "KerneloopsReporter.h" #include "PluginSettings.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include <stdlib.h> #include <string.h> @@ -59,7 +59,7 @@ size_t writefunction(void *ptr, size_t size, size_t nmemb, void __attribute((unu void CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { - ABRTCommLayer::status("Creating and submitting a report..."); + comm_layer_inner_status("Creating and submitting a report..."); CURL *handle; struct curl_httppost *post = NULL; diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index 9d972e3f..33ebfa03 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -24,7 +24,7 @@ #include "PluginSettings.h" #include <sstream> #include "DebugDump.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" CLogger::CLogger() : m_sLogPath("/var/log/abrt-logger"), @@ -48,7 +48,7 @@ void CLogger::LoadSettings(const std::string& pPath) void CLogger::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { - ABRTCommLayer::status("Creating a report..."); + comm_layer_inner_status("Creating a report..."); std::stringstream binaryFiles, commonFiles, bigTextFiles, additionalFiles, UUIDFile; std::ofstream fOut; diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp index 069e0133..6e596f25 100644 --- a/lib/Plugins/Mailx.cpp +++ b/lib/Plugins/Mailx.cpp @@ -25,7 +25,7 @@ #include "DebugDump.h" #include "ABRTException.h" #include "PluginSettings.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #define MAILX_COMMAND "/bin/mailx" @@ -41,7 +41,7 @@ CMailx::CMailx() : void CMailx::SendEmail(const std::string& pSubject, const std::string& pText) { - ABRTCommLayer::status("Sending an email..."); + comm_layer_inner_status("Sending an email..."); FILE* command; std::string mailx_command = MAILX_COMMAND + m_sAttachments + @@ -64,7 +64,7 @@ void CMailx::SendEmail(const std::string& pSubject, const std::string& pText) void CMailx::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { - ABRTCommLayer::status("Creating a report..."); + comm_layer_inner_status("Creating a report..."); std::stringstream emailBody; std::stringstream binaryFiles, commonFiles, bigTextFiles, additionalFiles, UUIDFile; diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 3e4aec62..396b2054 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +AM_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer pluginslibdir=$(PLUGINS_LIB_DIR) pluginslib_LTLIBRARIES = libCCpp.la \ libMailx.la \ @@ -17,18 +17,18 @@ dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf Kerneloops libCCpp_la_SOURCES = CCpp.cpp CCpp.h PluginSettings.h libCCpp_la_LDFLAGS = -avoid-version libCCpp_la_LIBADD = $(NSS_LIBS) -libCCpp_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) +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 KerneloopsSysLog.cpp KerneloopsSysLog.h PluginSettings.h libKerneloops_la_LDFLAGS = -avoid-version -libKerneloops_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" -DCCPP_HOOK_PATH=\"${libexecdir}/hookKerneloopsoops\" +libKerneloops_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" -DCCPP_HOOK_PATH=\"${libexecdir}/hookKerneloopsoops\" # KerneloopsReporter libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h PluginSettings.h libKerneloopsReporter_la_LDFLAGS = -avoid-version libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) -libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare $(CURL_CFLAGS) +libKerneloopsReporter_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare $(CURL_CFLAGS) # Mailx libMailx_la_SOURCES = Mailx.cpp Mailx.h PluginSettings.h @@ -38,7 +38,7 @@ libMailx_la_LDFLAGS = -avoid-version libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h PluginSettings.h libSQLite3_la_LDFLAGS = -avoid-version libSQLite3_la_LIBADD = $(SQLITE3_LIBS) -libSQLite3_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) +libSQLite3_la_CPPFLAGS = -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils $(SQLITE3_CFLAGS) # Logger libLogger_la_SOURCES = Logger.cpp Logger.h PluginSettings.h @@ -52,11 +52,11 @@ libRunApp_la_LDFLAGS = -avoid-version libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) libBugzilla_la_LDFLAGS = -avoid-version -libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +libBugzilla_la_CPPFLAGS = $(XMLRPC_CPP_CFLAGS) $(XMLRPC_CLIENT_CPP_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils # Python libPython_la_SOURCES = Python.h Python.cpp #libPython_la_LIBADD = $(NSS_LIBS) libPython_la_LDFLAGS = -avoid-version -libPython_la_CPPFLAGS = $(NSS_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils +libPython_la_CPPFLAGS = $(NSS_CFLAGS) -I$(srcdir)/../CommLayer -I$(srcdir)/../../inc -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp index 5a20283c..4f9d21d0 100644 --- a/lib/Plugins/RunApp.cpp +++ b/lib/Plugins/RunApp.cpp @@ -24,7 +24,7 @@ #include <stdio.h> #include "DebugDump.h" #include "ABRTException.h" -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #define COMMAND 0 #define FILENAME 1 @@ -59,7 +59,7 @@ void CActionRunApp::ParseArgs(const std::string& psArgs, vector_args_t& pArgs) void CActionRunApp::Run(const std::string& pDebugDumpDir, const std::string& pArgs) { - ABRTCommLayer::status("Executing RunApp plugin..."); + comm_layer_inner_status("Executing RunApp plugin..."); char line[1024]; std::string output = ""; diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 421deb6a..46effa99 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -24,6 +24,7 @@ #include <fstream> #include <iostream> #include <sstream> +#include <cerrno> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> @@ -36,11 +37,14 @@ #include <magic.h> #include <string.h> +#define PID_STR_MAX 16 + CDebugDump::CDebugDump() : m_sDebugDumpDir(""), m_bOpened(false), m_bUnlock(true), - m_pGetNextFileDir(NULL) + m_pGetNextFileDir(NULL), + m_nFD(-1) {} void CDebugDump::Open(const std::string& pDir) @@ -81,67 +85,79 @@ bool CDebugDump::ExistFileDir(const std::string& pPath) bool CDebugDump::GetAndSetLock(const std::string& pLockFile, const std::string& pPID) { - std::ifstream fIn; - std::ofstream fOut; - - fIn.open(pLockFile.c_str()); - if (!fIn.is_open()) - { - fOut.open(pLockFile.c_str()); - fOut << pPID; - fOut.close(); - m_bUnlock = true; - return true; - } - else + int fd = open(pLockFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0640); + if (fd == -1 && errno == EEXIST) { - std::string line; - std::stringstream ss; - getline(fIn, line); - if (line == pPID) + char pid[PID_STR_MAX + 1]; + if ((fd = open(pLockFile.c_str(), O_RDONLY)) == -1) + { + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot get lock status"); + } + int r = read(fd, pid, sizeof(pid)); + if (r == -1) + { + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot get a pid"); + } + pid[r > PID_STR_MAX ? PID_STR_MAX : r] = '\0'; + if (pid == pPID) { - fIn.close(); + close(fd); m_bUnlock = false; return true; } - ss << "/proc/" << line << "/"; - if (!ExistFileDir(ss.str())) + if (lockf(fd, F_TEST, 0) == 0) { - fIn.close(); + std::cerr << lockf(fd, F_TEST, 0) << std::endl; + close(fd); remove(pLockFile.c_str()); Delete(); throw CABRTException(EXCEP_ERROR, "CDebugDump::GetAndSetLock(): dead lock found"); } - fIn.close(); + close(fd); return false; } + else if (fd == -1) + { + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot create lock file"); + } + + if (write(fd, pPID.c_str(), pPID.length()) != pPID.length()) + { + close(fd); + remove(pLockFile.c_str()); + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot write a pid"); + } + if (lockf(fd, F_LOCK, 0) == -1) + { + close(fd); + remove(pLockFile.c_str()); + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot get lock file"); + } + m_nFD = fd; + m_bUnlock = true; + return true; } void CDebugDump::Lock() { - int ii = 0; std::string lockFile = m_sDebugDumpDir + ".lock"; pid_t nPID = getpid(); std::stringstream ss; ss << nPID; while (!GetAndSetLock(lockFile, ss.str())) { - usleep(5000); - // 40000 is about 20s, that should be enough. - if (ii > 40000) - { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Lock(): timeout occurs when opening '"+m_sDebugDumpDir+"'"); - } - ii++; + usleep(500000); } } void CDebugDump::UnLock() { - std::string lockPath = m_sDebugDumpDir + ".lock"; + std::string lockFile = m_sDebugDumpDir + ".lock"; if (m_bUnlock) { - remove(lockPath.c_str()); + close(m_nFD); + m_nFD = -1; + remove(lockFile.c_str()); } } @@ -164,6 +180,7 @@ void CDebugDump::Create(const std::string& pDir) if (mkdir(pDir.c_str(), 0755) == -1) { + UnLock(); throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot create dir: " + pDir); } diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 7dd1dcca..73fdeb64 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -43,6 +43,7 @@ class CDebugDump bool m_bOpened; bool m_bUnlock; DIR* m_pGetNextFileDir; + int m_nFD; void SaveKernelArchitectureRelease(); void SaveTime(); diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 0146fab4..2a2f05b6 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -30,7 +30,7 @@ #include <sstream> #include <dirent.h> #include <cstring> -#include "ABRTCommLayer.h" +#include "CommLayerInner.h" #include "ABRTException.h" /* just a helper function @@ -215,7 +215,7 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath) // TODO: initialize object according parameters -w -d // status has to be always created. m_pCommLayerInner = new CCommLayerInner(this, true, true); - ABRTCommLayer::init_comm_layer_inner(m_pCommLayerInner); + comm_layer_inner_init(m_pCommLayerInner); m_pSettings = new CSettings(); m_pSettings->LoadSettings(std::string(CONF_DIR) + "/abrt.conf"); @@ -289,7 +289,7 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) std::cerr << "Saving debugdeump: " << *itt << std::endl; try { - if(m_pMW->SaveDebugDump(*itt, crashinfo) == 0) + if(m_pMW->SaveDebugDump(*itt, crashinfo)) { std::cerr << "Saved new entry: " << *itt << std::endl; m_pMW->Report(*itt); diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index 84013d49..2462b30d 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -1,14 +1,13 @@ sbin_PROGRAMS = abrt abrt_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp DBusServerProxy.h \ DBusCommon.h Settings.h Settings.cpp -abrt_CPPFLAGS = -Wall -Werror -rdynamic -I$(srcdir)/../../lib/MiddleWare -I$(srcdir)/../../lib/CommLayer\ +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)\" abrt_LDADD = ../../lib/MiddleWare/libABRTMiddleWare.la ../../lib/CommLayer/libABRTCommLayer.la $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) -#abrt_LDFLAGS = -Wl,--dynamic-list,exported-symbols dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ dist_dbusabrtconf_DATA = dbus-abrt.conf |