diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-06 12:41:24 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-06 12:41:24 +0100 |
commit | c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608 (patch) | |
tree | 237a9d3f821d01932111e9fa59af5d3e44b988c8 /lib | |
parent | 03bbbf8eff11cf68a7e2325ca310e02bf3757193 (diff) | |
download | abrt-c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608.tar.gz abrt-c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608.tar.xz abrt-c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608.zip |
mass replace of const string& params by const char*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Plugins/CCpp.cpp | 25 | ||||
-rw-r--r-- | lib/Plugins/CCpp.h | 6 | ||||
-rw-r--r-- | lib/Plugins/FileTransfer.cpp | 75 | ||||
-rw-r--r-- | lib/Plugins/FileTransfer.h | 10 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.cpp | 4 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.h | 6 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.cpp | 3 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.h | 3 | ||||
-rw-r--r-- | lib/Plugins/Python.cpp | 6 | ||||
-rw-r--r-- | lib/Plugins/Python.h | 6 | ||||
-rw-r--r-- | lib/Plugins/RunApp.cpp | 7 | ||||
-rw-r--r-- | lib/Plugins/RunApp.h | 3 | ||||
-rw-r--r-- | lib/Plugins/SOSreport.cpp | 15 | ||||
-rw-r--r-- | lib/Plugins/SOSreport.h | 3 | ||||
-rw-r--r-- | lib/Utils/Action.h | 6 | ||||
-rw-r--r-- | lib/Utils/Analyzer.h | 6 | ||||
-rw-r--r-- | lib/Utils/CommLayerInner.cpp | 4 | ||||
-rw-r--r-- | lib/Utils/DebugDump.cpp | 153 | ||||
-rw-r--r-- | lib/Utils/DebugDump.h | 10 | ||||
-rw-r--r-- | lib/Utils/Observer.h | 4 |
20 files changed, 127 insertions, 228 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 8a86e144..3a3604b5 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -223,7 +223,7 @@ int rate_backtrace(const std::string & backtrace) return 0; } -static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace) +static void GetBacktrace(const char *pDebugDumpDir, std::string& pBacktrace) { update_client(_("Getting backtrace...")); @@ -258,7 +258,7 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra args[4] = (char*)"-ex"; args[5] = xasprintf("file %s", executable.c_str()); args[6] = (char*)"-ex"; - args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir); args[8] = (char*)"-ex"; args[9] = (char*)"thread apply all backtrace full"; args[10] = NULL; @@ -420,7 +420,7 @@ static void GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& } } -static std::string run_unstrip_n(const std::string& pDebugDumpDir) +static std::string run_unstrip_n(const char *pDebugDumpDir) { std::string UID; { @@ -431,7 +431,7 @@ static std::string run_unstrip_n(const std::string& pDebugDumpDir) char* args[4]; args[0] = (char*)"eu-unstrip"; - args[1] = xasprintf("--core=%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[1] = xasprintf("--core=%s/"FILENAME_COREDUMP, pDebugDumpDir); args[2] = (char*)"-n"; args[3] = NULL; @@ -455,7 +455,7 @@ static bool is_hexstr(const char* str) } return true; } -static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) +static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) { log("Getting module names, file names, build IDs from core file"); std::string unstrip_list = run_unstrip_n(pDebugDumpDir); @@ -648,7 +648,7 @@ Another application is holding the yum lock, cannot continue /* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 * It is slated to be in F12/RHEL6. */ -static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) +static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) { update_client(_("Searching for debug-info packages...")); @@ -673,7 +673,7 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui setsid(); - char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir); /* SELinux guys are not happy with /tmp, using /var/run/abrt */ char *tempdir = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ @@ -787,7 +787,7 @@ static void trim_debuginfo_cache(unsigned max_mb) } } -std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) { log(_("Getting local universal unique identification...")); @@ -806,7 +806,7 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) return CreateHash(package + executable + independentBuildIdPC); } -std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) { log(_("Getting global universal unique identification...")); @@ -851,7 +851,7 @@ static bool DebuginfoCheckPolkit(int uid) return false; } -void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) +void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) { update_client(_("Starting report creation...")); @@ -889,13 +889,12 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) GetBacktrace(pDebugDumpDir, backtrace); dd.Open(pDebugDumpDir); - dd.SaveText(FILENAME_BACKTRACE, build_ids + backtrace); + dd.SaveText(FILENAME_BACKTRACE, (build_ids + backtrace).c_str()); if (m_bMemoryMap) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } - std::string rating = ssprintf("%d", rate_backtrace(backtrace)); - dd.SaveText(FILENAME_RATING, rating); + dd.SaveText(FILENAME_RATING, to_string(rate_backtrace(backtrace)).c_str()); dd.Close(); } diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h index a37ba67c..a768c0a5 100644 --- a/lib/Plugins/CCpp.h +++ b/lib/Plugins/CCpp.h @@ -39,9 +39,9 @@ class CAnalyzerCCpp : public CAnalyzer public: CAnalyzerCCpp(); - virtual std::string GetLocalUUID(const std::string& pDebugDumpDir); - virtual std::string GetGlobalUUID(const std::string& pDebugDumpDir); - virtual void CreateReport(const std::string& pDebugDumpDir, int force); + virtual std::string GetLocalUUID(const char *pDebugDumpDir); + virtual std::string GetGlobalUUID(const char *pDebugDumpDir); + virtual void CreateReport(const char *pDebugDumpDir, int force); virtual void Init(); virtual void DeInit(); virtual void SetSettings(const map_plugin_settings_t& pSettings); diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp index 66427585..75031fcc 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -55,62 +55,42 @@ CFileTransfer::CFileTransfer() { } -void CFileTransfer::SendFile(const std::string& pURL, - const std::string& pFilename) +void CFileTransfer::SendFile(const char *pURL, const char *pFilename) { - if (pURL == "") + int len = strlen(pURL); + if (len == 0) { warn_client(_("FileTransfer: URL not specified")); return; } - int len = pURL.length(); - int i = 0; - std::string protocol; - while (pURL[i] != ':') - { - protocol += pURL[i]; - i++; - if (i == len) - { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): malformed URL, does not contain protocol"); - } - } - - std::string msg = ssprintf(_("Sending archive %s via %s"), pFilename.c_str(), protocol.c_str()); + std::string msg = ssprintf(_("Sending archive %s to %s"), pFilename, pURL); update_client(msg.c_str()); - std::string wholeURL; - if (pURL[len-1] == '/') - { - wholeURL = pURL + pFilename; - } - else - { - wholeURL = pURL + "/" + pFilename; - } + std::string wholeURL = concat_path_file(pURL, pFilename); int result; int count = m_nRetryCount; do { - FILE * f; + FILE *f; struct stat buf; - CURL * curl; + CURL *curl; - f = fopen(pFilename.c_str(), "r"); + f = fopen(pFilename, "r"); if (!f) { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): cannot open archive file "+pFilename); + throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't open archive file '%s'", pFilename)); } if (fstat(fileno(f), &buf) == -1) { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): cannot stat archive file "+pFilename); + fclose(f); + throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't stat archive file '%s'", pFilename)); } curl = curl_easy_init(); if (!curl) { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): Curl library error."); + throw CABRTException(EXCEP_PLUGIN, "Curl library init error"); } /* enable uploading */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); @@ -285,28 +265,27 @@ static void create_tarbz2(const char * archive_name, const char * directory) free(name_without_bz2); } -void CFileTransfer::CreateArchive(const std::string& pArchiveName, - const std::string& pDir) +void CFileTransfer::CreateArchive(const char *pArchiveName, const char *pDir) { if (m_sArchiveType == ".tar") { - create_tar(pArchiveName.c_str(), pDir.c_str()); + create_tar(pArchiveName, pDir); } else if (m_sArchiveType == ".tar.gz") { - create_targz(pArchiveName.c_str(), pDir.c_str()); + create_targz(pArchiveName, pDir); } else if (m_sArchiveType == ".tar.bz2") { - create_tarbz2(pArchiveName.c_str(), pDir.c_str()); + create_tarbz2(pArchiveName, pDir); } else if (m_sArchiveType == ".zip") { - create_zip(pArchiveName.c_str(), pDir.c_str()); + create_zip(pArchiveName, pDir); } else { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::CreateArchive(): unknown/unsupported archive type "+m_sArchiveType); + throw CABRTException(EXCEP_PLUGIN, "Unknown/unsupported archive type " + m_sArchiveType); } } @@ -326,7 +305,7 @@ static std::string DirBase(const std::string& pStr) return result; } -void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs) +void CFileTransfer::Run(const char *pActionDir, const char *pArgs) { fstream dirlist; std::string dirname, archivename; @@ -334,23 +313,23 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs) update_client(_("File Transfer: Creating a report...")); - if (pArgs == "store") + if (strcmp(pArgs, "store") == 0) { /* store pActiveDir for later sending */ dirlist.open(FILETRANSFER_DIRLIST, fstream::out | fstream::app ); - dirlist << pActiveDir << endl; + dirlist << pActionDir << endl; dirlist.close(); } - else if (pArgs == "one") + else if (strcmp(pArgs, "one") == 0) { /* just send one archive */ gethostname(hostname, HBLEN); archivename = std::string(hostname) + "-" - + DirBase(pActiveDir) + m_sArchiveType; + + DirBase(pActionDir) + m_sArchiveType; try { - CreateArchive(archivename, pActiveDir); - SendFile(m_sURL, archivename); + CreateArchive(archivename.c_str(), pActionDir); + SendFile(m_sURL.c_str(), archivename.c_str()); } catch (CABRTException& e) { @@ -377,8 +356,8 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs) + DirBase(dirname) + m_sArchiveType; try { - CreateArchive(archivename, dirname); - SendFile(m_sURL, archivename); + CreateArchive(archivename.c_str(), dirname.c_str()); + SendFile(m_sURL.c_str(), archivename.c_str()); } catch (CABRTException& e) { diff --git a/lib/Plugins/FileTransfer.h b/lib/Plugins/FileTransfer.h index 2f230c65..526fbc3d 100644 --- a/lib/Plugins/FileTransfer.h +++ b/lib/Plugins/FileTransfer.h @@ -35,18 +35,14 @@ class CFileTransfer : public CAction int m_nRetryCount; int m_nRetryDelay; - void CreateArchive(const std::string& pArchiveName, - const std::string& pDir); - - void SendFile(const std::string& pURL, - const std::string& pFilename); + void CreateArchive(const char *pArchiveName, const char *pDir); + void SendFile(const char *pURL, const char *pFilename); public: CFileTransfer(); virtual void SetSettings(const map_plugin_settings_t& pSettings); virtual map_plugin_settings_t GetSettings(); - virtual void Run(const std::string& pActiveDir, - const std::string& pArgs); + virtual void Run(const char *pActionDir, const char *pArgs); }; #endif /* FILETRANSFER_H_ */ diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index e072ada7..f2a8a591 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -32,7 +32,7 @@ #define FILENAME_KERNELOOPS "kerneloops" -std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerKerneloops::GetLocalUUID(const char *pDebugDumpDir) { log(_("Getting local universal unique identification")); @@ -58,7 +58,7 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) return to_string(hash); } -std::string CAnalyzerKerneloops::GetGlobalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerKerneloops::GetGlobalUUID(const char *pDebugDumpDir) { return GetLocalUUID(pDebugDumpDir); } diff --git a/lib/Plugins/Kerneloops.h b/lib/Plugins/Kerneloops.h index c22e7878..cda223d8 100644 --- a/lib/Plugins/Kerneloops.h +++ b/lib/Plugins/Kerneloops.h @@ -37,9 +37,9 @@ class CAnalyzerKerneloops : public CAnalyzer map_plugin_settings_t m_pSettings; public: - virtual std::string GetLocalUUID(const std::string& pDebugDumpDir); - virtual std::string GetGlobalUUID(const std::string& pDebugDumpDir); - virtual void CreateReport(const std::string& pDebugDumpDir, int force) {} + virtual std::string GetLocalUUID(const char *pDebugDumpDir); + virtual std::string GetGlobalUUID(const char *pDebugDumpDir); + virtual void CreateReport(const char *pDebugDumpDir, int force) {} virtual void SetSettings(const map_plugin_settings_t& pSettings); virtual map_plugin_settings_t GetSettings(); }; diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index c7756bad..3572ef26 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -50,8 +50,7 @@ CKerneloopsScanner::CKerneloopsScanner() SaveOopsToDebugDump(); } -void CKerneloopsScanner::Run(const std::string& pActionDir, - const std::string& pArgs) +void CKerneloopsScanner::Run(const char *pActionDir, const char *pArgs) { const char *syslog_file = "/var/log/messages"; map_plugin_settings_t::const_iterator it = m_pSettings.find("SysLogFile"); diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h index 7352393b..a2a4e4b2 100644 --- a/lib/Plugins/KerneloopsScanner.h +++ b/lib/Plugins/KerneloopsScanner.h @@ -49,8 +49,7 @@ class CKerneloopsScanner : public CAction /* Plugin interface */ public: CKerneloopsScanner(); - virtual void Run(const std::string& pActionDir, - const std::string& pArgs); + virtual void Run(const char *pActionDir, const char *pArgs); virtual void SetSettings(const map_plugin_settings_t& pSettings); virtual map_plugin_settings_t GetSettings(); }; diff --git a/lib/Plugins/Python.cpp b/lib/Plugins/Python.cpp index b92d6af5..9fb78808 100644 --- a/lib/Plugins/Python.cpp +++ b/lib/Plugins/Python.cpp @@ -6,7 +6,7 @@ #define FILENAME_BACKTRACE "backtrace" #define PYHOOK_CONFIG "/etc/abrt/pyhook.conf" -static std::string CreateHash(const std::string& pDebugDumpDir) +static std::string CreateHash(const char *pDebugDumpDir) { std::string uuid; CDebugDump dd; @@ -15,11 +15,11 @@ static std::string CreateHash(const std::string& pDebugDumpDir) return uuid; } -std::string CAnalyzerPython::GetLocalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerPython::GetLocalUUID(const char *pDebugDumpDir) { return CreateHash(pDebugDumpDir); } -std::string CAnalyzerPython::GetGlobalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerPython::GetGlobalUUID(const char *pDebugDumpDir) { return GetLocalUUID(pDebugDumpDir); } diff --git a/lib/Plugins/Python.h b/lib/Plugins/Python.h index 532ee8cd..82f52c05 100644 --- a/lib/Plugins/Python.h +++ b/lib/Plugins/Python.h @@ -8,9 +8,9 @@ class CAnalyzerPython : public CAnalyzer { public: - virtual std::string GetLocalUUID(const std::string& pDebugDumpDir); - virtual std::string GetGlobalUUID(const std::string& pDebugDumpDir); - virtual void CreateReport(const std::string& pDebugDumpDir, int force) {} + virtual std::string GetLocalUUID(const char *pDebugDumpDir); + virtual std::string GetGlobalUUID(const char *pDebugDumpDir); + virtual void CreateReport(const char *pDebugDumpDir, int force) {} virtual void Init(); virtual void DeInit(); }; diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp index 51d43466..f816dc23 100644 --- a/lib/Plugins/RunApp.cpp +++ b/lib/Plugins/RunApp.cpp @@ -59,15 +59,14 @@ static void ParseArgs(const char *psArgs, vector_string_t& pArgs) } } -void CActionRunApp::Run(const std::string& pActionDir, - const std::string& pArgs) +void CActionRunApp::Run(const char *pActionDir, const char *pArgs) { update_client(_("Executing RunApp plugin...")); std::string output; vector_string_t args; - ParseArgs(pArgs.c_str(), args); + ParseArgs(pArgs, args); FILE *fp = popen(args[COMMAND].c_str(), "r"); if (fp == NULL) @@ -85,7 +84,7 @@ void CActionRunApp::Run(const std::string& pActionDir, { CDebugDump dd; dd.Open(pActionDir); - dd.SaveText(args[FILENAME].c_str(), output); + dd.SaveText(args[FILENAME].c_str(), output.c_str()); } } diff --git a/lib/Plugins/RunApp.h b/lib/Plugins/RunApp.h index 0e12351e..939feaa5 100644 --- a/lib/Plugins/RunApp.h +++ b/lib/Plugins/RunApp.h @@ -29,8 +29,7 @@ class CActionRunApp : public CAction { public: - virtual void Run(const std::string& pActionDir, - const std::string& pArgs); + virtual void Run(const char *pActionDir, const char *pArgs); }; #endif diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp index 4938f7d7..744550bb 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -114,8 +114,7 @@ static void ParseArgs(const char *psArgs, vector_string_t& pArgs) } } -void CActionSOSreport::Run(const std::string& pActionDir, - const std::string& pArgs) +void CActionSOSreport::Run(const char *pActionDir, const char *pArgs) { update_client(_("Executing SOSreport plugin...")); @@ -128,25 +127,25 @@ void CActionSOSreport::Run(const std::string& pActionDir, std::string command; vector_string_t args; - ParseArgs(pArgs.c_str(), args); + ParseArgs(pArgs, args); if (args.size() == 0 || args[0] == "") { - command = std::string(command_default); + command = command_default; } else { - command = std::string(command_prefix) + ' ' + args[0] + " 2>&1"; + command = ssprintf("%s %s 2>&1", command_prefix, args[0].c_str()); } update_client(_("running sosreport: ") + command); FILE *fp = popen(command.c_str(), "r"); - if (fp == NULL) { - throw CABRTException(EXCEP_PLUGIN, std::string("CActionSOSreport::Run(): cannot execute ") + command); + throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't execute '%s'", command.c_str())); } +//vda TODO: fix this mess std::ostringstream output_stream; __gnu_cxx::stdio_filebuf<char> command_output_buffer(fp, std::ios_base::in); @@ -159,7 +158,7 @@ void CActionSOSreport::Run(const std::string& pActionDir, std::string output = output_stream.str(); std::string sosreport_filename = ParseFilename(output); - std::string sosreport_dd_filename = pActionDir + "/sosreport.tar.bz2"; + std::string sosreport_dd_filename = concat_path_file(pActionDir, "sosreport.tar.bz2"); CDebugDump dd; dd.Open(pActionDir); diff --git a/lib/Plugins/SOSreport.h b/lib/Plugins/SOSreport.h index 98d2b6cd..d4e0d733 100644 --- a/lib/Plugins/SOSreport.h +++ b/lib/Plugins/SOSreport.h @@ -26,8 +26,7 @@ class CActionSOSreport : public CAction { public: - virtual void Run(const std::string& pActionDir, - const std::string& pArgs); + virtual void Run(const char *pActionDir, const char *pArgs); }; #endif diff --git a/lib/Utils/Action.h b/lib/Utils/Action.h index 1286feba..5992cbff 100644 --- a/lib/Utils/Action.h +++ b/lib/Utils/Action.h @@ -22,7 +22,6 @@ #ifndef ACTION_H_ #define ACTION_H_ -#include <string> #include "Plugin.h" /** @@ -40,8 +39,7 @@ class CAction : public CPlugin * @param pActionDir An actual directory. * @param pArgs Plugin's arguments. */ - virtual void Run(const std::string& pActionDir, - const std::string& pArgs) = 0; + virtual void Run(const char *pActionDir, const char *pArgs) = 0; }; -#endif /*ACTION_H_*/ +#endif diff --git a/lib/Utils/Analyzer.h b/lib/Utils/Analyzer.h index e5bda574..9108a914 100644 --- a/lib/Utils/Analyzer.h +++ b/lib/Utils/Analyzer.h @@ -37,20 +37,20 @@ class CAnalyzer : public CPlugin * @param pDebugDumpPath A debugdump dir containing all necessary data. * @return A local UUID. */ - virtual std::string GetLocalUUID(const std::string& pDebugDumpPath) = 0; + virtual std::string GetLocalUUID(const char *pDebugDumpDir) = 0; /** * A method, which gets a global UUID of particular crash. * @param pDebugDumpPath A debugdump dir containing all necessary data. * @return A global UUID. */ - virtual std::string GetGlobalUUID(const std::string& pDebugDumpPath) = 0; + virtual std::string GetGlobalUUID(const char *pDebugDumpDir) = 0; /** * A method, which takes care of getting all additional data needed * for computing UUIDs and creating a report. This report could be send * somewhere afterwards. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ - virtual void CreateReport(const std::string& pDebugDumpPath, int force) = 0; + virtual void CreateReport(const char *pDebugDumpDir, int force) = 0; }; #endif /*ANALYZER_H_*/ diff --git a/lib/Utils/CommLayerInner.cpp b/lib/Utils/CommLayerInner.cpp index b5b8db78..8490e2fa 100644 --- a/lib/Utils/CommLayerInner.cpp +++ b/lib/Utils/CommLayerInner.cpp @@ -45,7 +45,7 @@ void warn_client(const std::string& pMessage) pthread_mutex_unlock(&s_map_mutex); if (peer) - s_pObs->Warning(pMessage, peer, key); + s_pObs->Warning(pMessage.c_str(), peer, key); else /* Bug: someone tries to warn_client() without set_client_name()!? */ log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); } @@ -63,7 +63,7 @@ void update_client(const std::string& pMessage) pthread_mutex_unlock(&s_map_mutex); if (peer) - s_pObs->Status(pMessage, peer, key); + s_pObs->Status(pMessage.c_str(), peer, key); else log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); } diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index b908acc6..276c42f8 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -48,7 +48,7 @@ static std::string RemoveBackSlashes(const char *pDir) } static bool ExistFileDir(const char* pPath); -static void LoadTextFile(const std::string& pPath, std::string& pData); +static void LoadTextFile(const char *pPath, std::string& pData); CDebugDump::CDebugDump() : m_sDebugDumpDir(""), @@ -57,13 +57,13 @@ CDebugDump::CDebugDump() : m_bLocked(false) {} -void CDebugDump::Open(const std::string& pDir) +void CDebugDump::Open(const char *pDir) { if (m_bOpened) { throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened."); } - m_sDebugDumpDir = RemoveBackSlashes(pDir.c_str()); + m_sDebugDumpDir = RemoveBackSlashes(pDir); if (!ExistFileDir(m_sDebugDumpDir.c_str())) { throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): " + m_sDebugDumpDir + " does not exist."); @@ -215,17 +215,17 @@ void CDebugDump::UnLock() } } -void CDebugDump::Create(const std::string& pDir, int64_t uid) +void CDebugDump::Create(const char *pDir, int64_t uid) { if (m_bOpened) { - throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened."); + throw CABRTException(EXCEP_ERROR, "DebugDump is already opened"); } - m_sDebugDumpDir = RemoveBackSlashes(pDir.c_str()); + m_sDebugDumpDir = RemoveBackSlashes(pDir); if (ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+m_sDebugDumpDir+" already exists."); + throw CABRTException(EXCEP_DD_OPEN, ssprintf("'%s' already exists", m_sDebugDumpDir.c_str())); } Lock(); @@ -235,13 +235,13 @@ void CDebugDump::Create(const std::string& pDir, int64_t uid) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot create dir: " + pDir); + throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't create dir '%s'", pDir)); } if (chmod(m_sDebugDumpDir.c_str(), 0700) == -1) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::Create(): Cannot change permissions, dir: " + pDir); + throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't change mode of '%s'", pDir)); } struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; @@ -252,9 +252,10 @@ void CDebugDump::Create(const std::string& pDir, int64_t uid) perror_msg("can't change '%s' ownership to %u:%u", m_sDebugDumpDir.c_str(), (int)uid, (int)gid); } - SaveText(FILENAME_UID, ssprintf("%li", uid)); + SaveText(FILENAME_UID, to_string(uid).c_str()); SaveKernelArchitectureRelease(); - SaveTime(); + time_t t = time(NULL); + SaveText(FILENAME_TIME, to_string(t).c_str()); } static void DeleteFileDir(const std::string& pDir) @@ -274,7 +275,7 @@ static void DeleteFileDir(const std::string& pDir) if (errno != EISDIR) { closedir(dir); - throw CABRTException(EXCEP_DD_DELETE, std::string(__func__) + ": Cannot remove file: " + fullPath); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove file: " + fullPath); } DeleteFileDir(fullPath); } @@ -282,7 +283,7 @@ static void DeleteFileDir(const std::string& pDir) closedir(dir); if (remove(pDir.c_str()) == -1) { - throw CABRTException(EXCEP_DD_DELETE, std::string(__func__) + ": Cannot remove dir: " + pDir); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove dir: " + pDir); } } @@ -371,100 +372,44 @@ void CDebugDump::SaveKernelArchitectureRelease() const char *release_ptr = release.c_str(); unsigned len_1st_str = strchrnul(release_ptr, '\n') - release_ptr; release.erase(len_1st_str); /* usually simply removes trailing '\n' */ - SaveText(FILENAME_RELEASE, release); -} - -void CDebugDump::SaveTime() -{ - time_t t = time(NULL); - SaveText(FILENAME_TIME, to_string(t)); + SaveText(FILENAME_RELEASE, release.c_str()); } -static void LoadTextFile(const std::string& pPath, std::string& pData) +static void LoadTextFile(const char *pPath, std::string& pData) { - std::ifstream fIn; + FILE *fp = fopen(pPath, "r"); + if (!fp) + { + throw CABRTException(EXCEP_DD_LOAD, ssprintf("Can't open file '%s'", pPath)); + } pData = ""; - fIn.open(pPath.c_str()); - if (fIn.is_open()) + int ch; + while ((ch = fgetc(fp)) != EOF) { - // TODO: rewrite this - int ch; - while ((ch = fIn.get())!= EOF) + if (ch == '\0') { - if (ch == 0) - { - pData += " "; - } - else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) - { - pData += ch; - } + pData += ' '; } - fIn.close(); - } - else - { - throw CABRTException(EXCEP_DD_LOAD, std::string(__func__) + ": Cannot open file " + pPath); - } -} - -static void LoadBinaryFile(const std::string& pPath, char** pData, unsigned int* pSize) -{ - std::ifstream fIn; - fIn.open(pPath.c_str(), std::ios::binary | std::ios::ate); - unsigned int size; - if (fIn.is_open()) - { - size = fIn.tellg(); - char *data = new char [size]; - fIn.read(data, size); - - *pData = data; - *pSize = size; - - fIn.close(); - } - else - { - throw CABRTException(EXCEP_DD_LOAD, std::string(__func__) + ": Cannot open file " + pPath); - } -} - -static void SaveTextFile(const std::string& pPath, const std::string& pData) -{ - std::ofstream fOut; - fOut.open(pPath.c_str()); - if (fOut.is_open()) - { - fOut << pData; - if (!fOut.good()) + else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) { - throw CABRTException(EXCEP_DD_SAVE, std::string(__func__) + ": Cannot save file " + pPath); + pData += ch; } - fOut.close(); - } - else - { - throw CABRTException(EXCEP_DD_SAVE, std::string(__func__) + ": Cannot open file " + pPath); } + fclose(fp); } -static void SaveBinaryFile(const std::string& pPath, const char* pData, const unsigned pSize) +static void SaveBinaryFile(const char *pPath, const char* pData, unsigned pSize) { - std::ofstream fOut; - fOut.open(pPath.c_str(), std::ios::binary); - if (fOut.is_open()) + int fd = open(pPath, O_WRONLY | O_TRUNC | O_CREAT, 0666); + if (fd < 0) { - fOut.write(pData, pSize); - if (!fOut.good()) - { - throw CABRTException(EXCEP_DD_SAVE, std::string(__func__) + ": Cannot save file " + pPath); - } - fOut.close(); + throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't open file '%s'", pPath)); } - else + unsigned r = full_write(fd, pData, pSize); + close(fd); + if (r != pSize) { - throw CABRTException(EXCEP_DD_SAVE, std::string(__func__) + ": Cannot open file " + pPath); + throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't save file '%s'", pPath)); } } @@ -474,36 +419,27 @@ void CDebugDump::LoadText(const char* pName, std::string& pData) { throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::LoadText(): DebugDump is not opened."); } - std::string fullPath = m_sDebugDumpDir + "/" + pName; - LoadTextFile(fullPath, pData); -} -void CDebugDump::LoadBinary(const char* pName, char** pData, unsigned int* pSize) -{ - if (!m_bOpened) - { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::LoadBinary(): DebugDump is not opened."); - } - std::string fullPath = m_sDebugDumpDir + "/" + pName; - LoadBinaryFile(fullPath, pData, pSize); + std::string fullPath = m_sDebugDumpDir + '/' + pName; + LoadTextFile(fullPath.c_str(), pData); } -void CDebugDump::SaveText(const char* pName, const std::string& pData) +void CDebugDump::SaveText(const char* pName, const char* pData) { if (!m_bOpened) { throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::SaveText(): DebugDump is not opened."); } std::string fullPath = m_sDebugDumpDir + "/" + pName; - SaveTextFile(fullPath, pData); + SaveBinaryFile(fullPath.c_str(), pData, strlen(pData)); } -void CDebugDump::SaveBinary(const char* pName, const char* pData, const unsigned int pSize) +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."); } std::string fullPath = m_sDebugDumpDir + "/" + pName; - SaveBinaryFile(fullPath, pData, pSize); + SaveBinaryFile(fullPath.c_str(), pData, pSize); } void CDebugDump::InitGetNextFile() @@ -535,7 +471,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool { if (is_regular_file(dent, m_sDebugDumpDir.c_str())) { - std::string fullname = m_sDebugDumpDir + "/" + dent->d_name; + std::string fullname = m_sDebugDumpDir + '/' + dent->d_name; pFileName = dent->d_name; if (IsTextFile(fullname.c_str())) @@ -545,7 +481,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool } else { - pContent = ""; + pContent.clear(); pIsTextFile = false; } return true; @@ -555,4 +491,3 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool m_pGetNextFileDir = NULL; return false; } - diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index 189b42d0..b48a386d 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -51,7 +51,6 @@ class CDebugDump bool m_bLocked; void SaveKernelArchitectureRelease(); - void SaveTime(); void Lock(); void UnLock(); @@ -60,18 +59,17 @@ class CDebugDump CDebugDump(); ~CDebugDump() { Close(); } - void Open(const std::string& pDir); - void Create(const std::string& pDir, int64_t uid); + void Open(const char *pDir); + void Create(const char *pDir, int64_t uid); void Delete(); void Close(); bool Exist(const char* pFileName); void LoadText(const char* pName, std::string& pData); - void LoadBinary(const char* pName, char** pData, unsigned int* pSize); - void SaveText(const char* pName, const std::string& pData); - void SaveBinary(const char* pName, const char* pData, const unsigned int pSize); + void SaveText(const char* pName, const char *pData); + void SaveBinary(const char* pName, const char* pData, unsigned pSize); void InitGetNextFile(); bool GetNextFile(std::string& pFileName, std::string& pContent, bool& pIsTextFile); diff --git a/lib/Utils/Observer.h b/lib/Utils/Observer.h index d6ec6f35..db748659 100644 --- a/lib/Utils/Observer.h +++ b/lib/Utils/Observer.h @@ -8,8 +8,8 @@ class CObserver { public: virtual ~CObserver() {} - 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; + virtual void Status(const char *pMessage, const char* peer, uint64_t pDest) = 0; + virtual void Warning(const char *pMessage, const char* peer, uint64_t pDest) = 0; }; #endif |