diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-11-06 15:11:55 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-11-06 15:11:55 +0100 |
| commit | 3a62ede25114452938acb8e1a67006633b139efc (patch) | |
| tree | d3a291e5dac5d7ddf14bae4a097ff5b298b71aa5 | |
| parent | fc571a9ac7aaa8802d3e8aacf9aefac12ca3c81c (diff) | |
| parent | 80975b02ec1a2e8dfc6f7ce21e47cf71b16b5a6e (diff) | |
| download | abrt-3a62ede25114452938acb8e1a67006633b139efc.tar.gz abrt-3a62ede25114452938acb8e1a67006633b139efc.tar.xz abrt-3a62ede25114452938acb8e1a67006633b139efc.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
42 files changed, 679 insertions, 835 deletions
@@ -305,6 +305,7 @@ fi %files addon-kerneloops %defattr(-,root,root,-) +%config(noreplace) %{_sysconfdir}/%{name}/plugins/Kerneloops.conf %config(noreplace) %{_sysconfdir}/%{name}/plugins/KerneloopsScanner.conf %{_bindir}/dumpoops %{_libdir}/%{name}/libKerneloops.so* diff --git a/inc/abrtlib.h b/inc/abrtlib.h index 63836ea..d20d067 100644 --- a/inc/abrtlib.h +++ b/inc/abrtlib.h @@ -148,6 +148,8 @@ void xunlink(const char *pathname); off_t copyfd_eof(int src_fd, int dst_fd); off_t copyfd_size(int src_fd, int dst_fd, off_t size); void copyfd_exact_size(int src_fd, int dst_fd, off_t size); +off_t copy_file(const char *src_name, const char *dst_name); + unsigned long long monotonic_ns(void); unsigned long long monotonic_us(void); @@ -199,6 +201,7 @@ char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa); char *encode_base64(const void *src, int length); bool dot_or_dotdot(const char *filename); char *last_char_is(const char *s, int c); +bool string_to_bool(const char *s); /* C++ style stuff */ diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 8362216..a2d65f3 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -95,7 +95,6 @@ static std::string concat_str_vector(char **strings) static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) { int pipeout[2]; - char buff[1024]; pid_t child; struct passwd* pw = getpwuid(uid); @@ -137,6 +136,7 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) close(pipeout[1]); /* write side of the pipe */ int r; + char buff[1024]; while ((r = read(pipeout[0], buff, sizeof(buff) - 1)) > 0) { buff[r] = '\0'; @@ -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(); } @@ -948,6 +947,8 @@ void CAnalyzerCCpp::DeInit() void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { + m_pSettings = pSettings; + map_plugin_settings_t::const_iterator end = pSettings.end(); map_plugin_settings_t::const_iterator it; it = pSettings.find("MemoryMap"); @@ -976,7 +977,7 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) map_plugin_settings_t CAnalyzerCCpp::GetSettings() { - map_plugin_settings_t ret; + map_plugin_settings_t ret = m_pSettings; ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; ret["DebugInfo"] = m_sDebugInfo; diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h index f3f911e..a768c0a 100644 --- a/lib/Plugins/CCpp.h +++ b/lib/Plugins/CCpp.h @@ -35,11 +35,13 @@ class CAnalyzerCCpp : public CAnalyzer unsigned m_nDebugInfoCacheMB; std::string m_sOldCorePattern; std::string m_sDebugInfo; + map_plugin_settings_t m_pSettings; + 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 6642758..856a326 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -42,8 +42,8 @@ #include "ABRTException.h" #include "CommLayerInner.h" - using namespace std; + #define HBLEN 255 #define FILETRANSFER_DIRLIST DEBUG_DUMPS_DIR "/FileTransferDirlist.txt" @@ -55,74 +55,52 @@ 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()); + 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; - } + 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); /* specify target */ curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str()); - /*file handle: passed to the default callback, it will fread() it*/ + /* FILE handle: passed to the default callback, it will fread() it */ curl_easy_setopt(curl, CURLOPT_READDATA, f); - /*get file size*/ curl_easy_setopt(curl, CURLOPT_INFILESIZE, buf.st_size); - /*everything is done here; result 0 means success*/ + /* everything is done here; result 0 means success */ result = curl_easy_perform(curl); - /*goodbye*/ curl_easy_cleanup(curl); fclose(f); } @@ -285,72 +263,72 @@ 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); } } -/*returns the last component of the directory path*/ -static std::string DirBase(const std::string& pStr) +/* Returns the last component of the directory path. + * Careful to not return "" on "/path/path2/", but "path2". + */ +static string DirBase(const char *pStr) { - int i = pStr.length() - 1; - if (i > 0 && pStr[i] == '/') + int end = strlen(pStr); + if (end > 1 && pStr[end-1] == '/') { - i--; + end--; } - std::string result; - for (; i >= 0 && pStr[i] != '/'; i--) + int beg = end; + while (beg > 0 && pStr[beg-1] != '/') { - result = pStr[i] + result; + beg--; } - return result; + return string(pStr + beg, end - beg); } -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; - char hostname[HBLEN]; - update_client(_("File Transfer: Creating a report...")); - if (pArgs == "store") + char hostname[HBLEN]; + gethostname(hostname, HBLEN-1); + hostname[HBLEN-1] = '\0'; + + fstream dirlist; + if (strcmp(pArgs, "store") == 0) { /* store pActiveDir for later sending */ - dirlist.open(FILETRANSFER_DIRLIST, fstream::out | fstream::app ); - dirlist << pActiveDir << endl; + dirlist.open(FILETRANSFER_DIRLIST, fstream::out | fstream::app); + 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; + string archivename = ssprintf("%s-%s%s", hostname, DirBase(pActionDir).c_str(), m_sArchiveType.c_str()); try { - CreateArchive(archivename, pActiveDir); - SendFile(m_sURL, archivename); + CreateArchive(archivename.c_str(), pActionDir); + SendFile(m_sURL.c_str(), archivename.c_str()); } catch (CABRTException& e) { @@ -361,8 +339,6 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs) } else { - gethostname(hostname, HBLEN); - dirlist.open(FILETRANSFER_DIRLIST, fstream::in); if (dirlist.fail()) { @@ -371,14 +347,14 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs) return; } + string dirname; while (getline(dirlist, dirname), dirlist.good()) { - archivename = std::string(hostname) + "-" - + DirBase(dirname) + m_sArchiveType; + string archivename = ssprintf("%s-%s%s", hostname, DirBase(dirname.c_str()).c_str(), m_sArchiveType.c_str()); 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) { @@ -427,7 +403,7 @@ void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings) m_sArchiveType = it->second; if (m_sArchiveType[0] != '.') { - m_sArchiveType = "." + m_sArchiveType; + m_sArchiveType = "." + m_sArchiveType; } } } @@ -435,13 +411,10 @@ void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings) map_plugin_settings_t CFileTransfer::GetSettings() { map_plugin_settings_t ret; - std::stringstream ss; + ret["URL"] = m_sURL; - ss << m_nRetryCount; - ret["RetryCount"] = ss.str(); - ss.str(""); - ss << m_nRetryDelay; - ret["RetryDelay"] = ss.str(); + ret["RetryCount"] = to_string(m_nRetryCount); + ret["RetryDelay"] = to_string(m_nRetryDelay); ret["ArchiveType"] = m_sArchiveType; return ret; diff --git a/lib/Plugins/FileTransfer.h b/lib/Plugins/FileTransfer.h index 2f230c6..526fbc3 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.conf b/lib/Plugins/Kerneloops.conf new file mode 100644 index 0000000..47b242f --- /dev/null +++ b/lib/Plugins/Kerneloops.conf @@ -0,0 +1,2 @@ +# compatibility with kerneloops.org tool +InformAllUsers = yes diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index e01bb42..f2a8a59 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,11 +58,21 @@ 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); } +void CAnalyzerKerneloops::SetSettings(const map_plugin_settings_t& pSettings) +{ + m_pSettings = pSettings; +} + +map_plugin_settings_t CAnalyzerKerneloops::GetSettings() +{ + return m_pSettings; +} + PLUGIN_INFO(ANALYZER, CAnalyzerKerneloops, "Kerneloops", diff --git a/lib/Plugins/Kerneloops.h b/lib/Plugins/Kerneloops.h index edd00d8..cda223d 100644 --- a/lib/Plugins/Kerneloops.h +++ b/lib/Plugins/Kerneloops.h @@ -33,10 +33,15 @@ class CAnalyzerKerneloops : public CAnalyzer { + private: + 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(); }; #endif diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index c57a1ef..712adf0 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -98,12 +98,10 @@ std::string CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { int ret = -1; - map_crash_report_t::const_iterator it; update_client(_("Creating and submitting a report...")); - it = pCrashReport.begin(); - it = pCrashReport.find(FILENAME_KERNELOOPS); + map_crash_report_t::const_iterator it = pCrashReport.find(FILENAME_KERNELOOPS); if (it != pCrashReport.end()) { ret = http_post_to_kerneloops_site( m_sSubmitURL.c_str(), @@ -111,19 +109,18 @@ std::string CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, ); } - if (ret) - { + if (ret) { /* FIXME: be more informative */ - throw CABRTException(EXCEP_PLUGIN, std::string("CKerneloopsReporter::Report(): Report has not been sent...")); + throw CABRTException(EXCEP_PLUGIN, std::string("CKerneloopsReporter::Report(): Report has not been sent...")); } return "Kernel oops report was uploaded to: " + m_sSubmitURL; } void CKerneloopsReporter::SetSettings(const map_plugin_settings_t& pSettings) { - if (pSettings.find("SubmitURL") != pSettings.end()) - { - m_sSubmitURL = pSettings.find("SubmitURL")->second; + map_plugin_settings_t::const_iterator it = pSettings.find("SubmitURL"); + if (it != pSettings.end()) { + m_sSubmitURL = it->second; } } diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 9e1bd53..3572ef2 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -43,7 +43,6 @@ CKerneloopsScanner::CKerneloopsScanner() { int cnt_FoundOopses; - m_sSysLogFile = "/var/log/messages"; /* Scan dmesg, on first call only */ cnt_FoundOopses = ScanDmesg(); @@ -51,19 +50,23 @@ CKerneloopsScanner::CKerneloopsScanner() SaveOopsToDebugDump(); } -void CKerneloopsScanner::Run(const std::string& pActionDir, - const std::string& pArgs) +void CKerneloopsScanner::Run(const char *pActionDir, const char *pArgs) { - int cnt_FoundOopses; + const char *syslog_file = "/var/log/messages"; + map_plugin_settings_t::const_iterator it = m_pSettings.find("SysLogFile"); + if (it != m_pSettings.end()) + { + syslog_file = it->second.c_str(); + } - cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str()); + int cnt_FoundOopses = ScanSysLogFile(syslog_file); if (cnt_FoundOopses > 0) { SaveOopsToDebugDump(); /* * This marker in syslog file prevents us from * re-parsing old oopses (any oops before it is * ignored by ScanSysLogFile()). The only problem - * is that we can't be sure here that m_sSysLogFile + * is that we can't be sure here that syslog_file * is the file where syslog(xxx) stuff ends up. */ openlog("abrt", 0, LOG_KERN); @@ -97,8 +100,7 @@ void CKerneloopsScanner::SaveOopsToDebugDump() try { CDebugDump debugDump; - // UID of kerneloops is -1 - debugDump.Create(path, -1); + debugDump.Create(path, 0); debugDump.SaveText(FILENAME_ANALYZER, "Kerneloops"); debugDump.SaveText(FILENAME_EXECUTABLE, "kernel"); debugDump.SaveText(FILENAME_KERNEL, first_line); @@ -180,20 +182,12 @@ int CKerneloopsScanner::ScanSysLogFile(const char *filename) void CKerneloopsScanner::SetSettings(const map_plugin_settings_t& pSettings) { - map_plugin_settings_t::const_iterator it = pSettings.find("SysLogFile"); - if (it != pSettings.end()) - { - m_sSysLogFile = it->second; - } + m_pSettings = pSettings; } map_plugin_settings_t CKerneloopsScanner::GetSettings() { - map_plugin_settings_t ret; - - ret["SysLogFile"] = m_sSysLogFile; - - return ret; + return m_pSettings; } PLUGIN_INFO(ACTION, diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h index 6ac0461..a2a4e4b 100644 --- a/lib/Plugins/KerneloopsScanner.h +++ b/lib/Plugins/KerneloopsScanner.h @@ -34,7 +34,7 @@ class CKerneloopsScanner : public CAction { private: - std::string m_sSysLogFile; + map_plugin_settings_t m_pSettings; /* For "dumpoops" tool */ public: @@ -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/Makefile.am b/lib/Plugins/Makefile.am index 428c2d6..0502f5e 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -1,30 +1,42 @@ AM_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils pluginslibdir=$(PLUGINS_LIB_DIR) -pluginslib_LTLIBRARIES = libCCpp.la \ - libMailx.la \ - libSQLite3.la \ - libLogger.la \ - libKerneloopsScanner.la\ - libKerneloopsReporter.la\ - libKerneloops.la \ - libRunApp.la \ - libSOSreport.la \ - libBugzilla.la \ - libCatcut.la \ - libTicketUploader.la \ - libPython.la \ - libFileTransfer.la - -dist_pluginslib_DATA = KerneloopsReporter.GTKBuilder Logger.GTKBuilder\ - Mailx.GTKBuilder Bugzilla.GTKBuilder\ - TicketUploader.GTKBuilder Catcut.GTKBuilder - -pluginsconfdir=$(PLUGINS_CONF_DIR) -dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf KerneloopsScanner.conf KerneloopsReporter.conf Bugzilla.conf Catcut.conf TicketUploader.conf FileTransfer.conf - - -man_MANS = abrt-FileTransfer.7 abrt-Bugzilla.7 abrt-KerneloopsReporter.7\ - abrt-KerneloopsScanner.7 abrt-Logger.7 abrt-Mailx.7 abrt-plugins.7\ +pluginslib_LTLIBRARIES = \ + libCCpp.la \ + libMailx.la \ + libSQLite3.la \ + libLogger.la \ + libKerneloopsScanner.la\ + libKerneloopsReporter.la\ + libKerneloops.la \ + libRunApp.la \ + libSOSreport.la \ + libBugzilla.la \ + libCatcut.la \ + libTicketUploader.la \ + libPython.la \ + libFileTransfer.la + +dist_pluginslib_DATA = \ + KerneloopsReporter.GTKBuilder Logger.GTKBuilder \ + Mailx.GTKBuilder Bugzilla.GTKBuilder \ + TicketUploader.GTKBuilder Catcut.GTKBuilder + +pluginsconfdir = $(PLUGINS_CONF_DIR) +dist_pluginsconf_DATA = \ + CCpp.conf \ + Mailx.conf \ + SQLite3.conf \ + Logger.conf \ + Kerneloops.conf \ + KerneloopsScanner.conf \ + KerneloopsReporter.conf \ + Bugzilla.conf \ + Catcut.conf \ + TicketUploader.conf \ + FileTransfer.conf + +man_MANS = abrt-FileTransfer.7 abrt-Bugzilla.7 abrt-KerneloopsReporter.7 \ + abrt-KerneloopsScanner.7 abrt-Logger.7 abrt-Mailx.7 abrt-plugins.7 \ abrt-SQLite3.7 abrt-RunApp.7 abrt-TicketUploader.7 # + abrt-Catcut.7 diff --git a/lib/Plugins/Python.cpp b/lib/Plugins/Python.cpp index 9be76b3..9fb7880 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" -std::string CAnalyzerPython::CreateHash(const std::string& pDebugDumpDir) +static std::string CreateHash(const char *pDebugDumpDir) { std::string uuid; CDebugDump dd; @@ -15,11 +15,11 @@ std::string CAnalyzerPython::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 b54de8d..82f52c0 100644 --- a/lib/Plugins/Python.h +++ b/lib/Plugins/Python.h @@ -8,12 +8,11 @@ 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(); - virtual std::string CreateHash(const std::string& pInput); }; #endif /* PYTHON_H_ */ diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp index 5a5c1d4..f816dc2 100644 --- a/lib/Plugins/RunApp.cpp +++ b/lib/Plugins/RunApp.cpp @@ -29,41 +29,41 @@ #define COMMAND 0 #define FILENAME 1 -void CActionRunApp::ParseArgs(const std::string& psArgs, vector_string_t& pArgs) +/* TODO: do not duplicate: SOSreport.cpp has same function too */ +static void ParseArgs(const char *psArgs, vector_string_t& pArgs) { - unsigned int ii; + unsigned ii; bool is_quote = false; - std::string item = ""; - for (ii = 0; ii < psArgs.length(); ii++) + std::string item; + + for (ii = 0; psArgs[ii]; ii++) { - if (psArgs[ii] == '\"') + if (psArgs[ii] == '"') { - is_quote = is_quote == true ? false : true; + is_quote = !is_quote; } else if (psArgs[ii] == ',' && !is_quote) { pArgs.push_back(item); - item = ""; + item.clear(); } else { item += psArgs[ii]; } } - if (item != "") + + if (item.size() != 0) { pArgs.push_back(item); } } -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...")); - char line[1024]; - std::string output = ""; - + std::string output; vector_string_t args; ParseArgs(pArgs, args); @@ -71,8 +71,9 @@ void CActionRunApp::Run(const std::string& pActionDir, FILE *fp = popen(args[COMMAND].c_str(), "r"); if (fp == NULL) { - throw CABRTException(EXCEP_PLUGIN, "CActionRunApp::Run(): cannot execute " + args[COMMAND]); + throw CABRTException(EXCEP_PLUGIN, "Can't execute " + args[COMMAND]); } + char line[1024]; while (fgets(line, 1024, fp) != NULL) { output += line; @@ -83,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 23315f1..939feaa 100644 --- a/lib/Plugins/RunApp.h +++ b/lib/Plugins/RunApp.h @@ -28,12 +28,8 @@ class CActionRunApp : public CAction { - private: - void ParseArgs(const std::string& psArgs, vector_string_t& pArgs); - 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 ab6125c..da77cce 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -18,41 +18,26 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include <stdio.h> -#include <string.h> #include <ext/stdio_filebuf.h> #include <fstream> #include <sstream> +#include "abrtlib.h" +#include "abrt_types.h" +#include "ABRTException.h" #include "SOSreport.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" -void CActionSOSreport::CopyFile(const std::string& pSourceName, const std::string& pDestName) -{ - std::ifstream source(pSourceName.c_str(), std::fstream::binary); - - if (!source) - { - throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open input sosreport filename:" + pSourceName); - } - std::ofstream dest(pDestName.c_str(),std::fstream::trunc|std::fstream::binary); - if (!dest) - { - throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open output sosreport filename:" + pDestName); - } - dest << source.rdbuf(); -} - -void CActionSOSreport::ErrorCheck(const index_type pI) +static void ErrorCheck(int pos) { - if (pI == std::string::npos) + if (pos < 0) { - throw CABRTException(EXCEP_PLUGIN, std::string("CActionSOSreport::ErrorCheck(): could not find filename in sosreport output")); + throw CABRTException(EXCEP_PLUGIN, "Can't find filename in sosreport output"); } } -std::string CActionSOSreport::ParseFilename(const std::string& pOutput) +static std::string ParseFilename(const std::string& pOutput) { /* the sosreport's filename is embedded in sosreport's output. @@ -63,83 +48,85 @@ std::string CActionSOSreport::ParseFilename(const std::string& pOutput) static const char sosreport_filename_marker[] = "Your sosreport has been generated and saved in:"; - index_type p = pOutput.find(sosreport_filename_marker); + int p = pOutput.find(sosreport_filename_marker); ErrorCheck(p); - p += strlen(sosreport_filename_marker); + p += sizeof(sosreport_filename_marker)-1; - index_type filename_start = pOutput.find_first_not_of(" \n\t", p); + int filename_start = pOutput.find_first_not_of(" \n\t", p); ErrorCheck(p); - index_type line_end = pOutput.find_first_of('\n',filename_start); + int line_end = pOutput.find_first_of('\n',filename_start); ErrorCheck(p); - index_type filename_end = pOutput.find_last_not_of(" \n\t",line_end); + int filename_end = pOutput.find_last_not_of(" \n\t", line_end); ErrorCheck(p); - return pOutput.substr(filename_start,(filename_end-filename_start)+1); + return pOutput.substr(filename_start, filename_end - filename_start + 1); } -void CActionSOSreport::ParseArgs(const std::string& psArgs, vector_args_t& pArgs) +/* TODO: do not duplicate: RunApp.cpp has same function too */ +static void ParseArgs(const char *psArgs, vector_string_t& pArgs) { - unsigned int ii; + unsigned ii; bool is_quote = false; - std::string item = ""; - for (ii = 0; ii < psArgs.length(); ii++) + std::string item; + + for (ii = 0; psArgs[ii]; ii++) { - if (psArgs[ii] == '\"') + if (psArgs[ii] == '"') { - is_quote = is_quote == true ? false : true; + is_quote = !is_quote; } else if (psArgs[ii] == ',' && !is_quote) { pArgs.push_back(item); - item = ""; + item.clear(); } else { item += psArgs[ii]; } } - if (item != "") + + if (item.size() != 0) { pArgs.push_back(item); } } -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...")); - const char command_default[] = "sosreport --batch --no-progressbar --only=anaconda --only=bootloader" + static const char command_default[] = "sosreport --batch --no-progressbar --only=anaconda --only=bootloader" " --only=devicemapper --only=filesys --only=hardware --only=kernel" " --only=libraries --only=memory --only=networking --only=nfsserver" " --only=pam --only=process --only=rpm -k rpm.rpmva=off --only=ssh" " --only=startup --only=yum 2>&1"; - const char command_prefix[] = "sosreport --batch --no-progressbar"; + static const char command_prefix[] = "sosreport --batch --no-progressbar"; std::string command; - vector_args_t args; + vector_string_t 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); @@ -152,13 +139,21 @@ 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); //Not useful //dd.SaveText("sosreportoutput", output); - CopyFile(sosreport_filename,sosreport_dd_filename); + 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() + ) + ); + } } PLUGIN_INFO(ACTION, diff --git a/lib/Plugins/SOSreport.h b/lib/Plugins/SOSreport.h index 1a35287..d4e0d73 100644 --- a/lib/Plugins/SOSreport.h +++ b/lib/Plugins/SOSreport.h @@ -22,24 +22,11 @@ #define SOSREPORT_H_ #include "Action.h" -#include <string> -#include <vector> class CActionSOSreport : public CAction { - private: - typedef std::string::size_type index_type; - - void CopyFile(const std::string& pSourceName, const std::string& pDestName); - void ErrorCheck(const index_type pI); - std::string ParseFilename(const std::string& pOutput); - - typedef std::vector<std::string> vector_args_t; - void ParseArgs(const std::string& psArgs, vector_args_t& pArgs); - 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/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index dc035d3..d55c0a9 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -325,7 +325,7 @@ void CSQLite3::Delete(const std::string& pUUID, const std::string& pUID) void CSQLite3::SetReported(const std::string& pUUID, const std::string& pUID, const std::string& pMessage) { - if(pUID == "0") + if (pUID == "0") { Exec("UPDATE "ABRT_TABLE" " "SET "DATABASE_COLUMN_REPORTED" = 1 " diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index 179ccc0..4aa05b7 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -17,26 +17,20 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - +#include <string> +#include <fstream> +#include <sstream> +#include <curl/curl.h> +#include "abrtlib.h" #include "TicketUploader.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" -#include <stdlib.h> -#include <sys/stat.h> - -#include <string> -#include <fstream> -#include <sstream> -#include <ext/stdio_filebuf.h> -#include <curl/curl.h> +using namespace std; CTicketUploader::CTicketUploader() : - m_sCustomer(""), - m_sTicket(""), - m_sURL(""), m_bEncrypt(false), m_bUpload(false), m_nRetryCount(3), @@ -47,148 +41,93 @@ CTicketUploader::~CTicketUploader() {} - -void CTicketUploader::Error(string func, string msg) +static void Error(const char *msg) { update_client(msg); - throw CABRTException(EXCEP_PLUGIN, func + msg); -} - -void CTicketUploader::CopyFile(const std::string& pSourceName, const std::string& pDestName) -{ - std::ifstream source(pSourceName.c_str(), std::fstream::binary); - - if (!source) - { - throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open input sosreport filename:" + pSourceName); - } - std::ofstream dest(pDestName.c_str(),std::fstream::trunc|std::fstream::binary); - if (!dest) - { - throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open output sosreport filename:" + pDestName); - } - dest << source.rdbuf(); + throw CABRTException(EXCEP_PLUGIN, msg); } -void CTicketUploader::RunCommand(string cmd) +static void RunCommand(const char *cmd) { - int retcode = system(cmd.c_str()); - if (retcode == -1) - { - Error("TicketUploader::RunCommand:", "error: could not start subshell: " + cmd); - } + int retcode = system(cmd); if (retcode) { - std::ostringstream msg; - msg << "error: subshell failed (rc=" << retcode << "):" << cmd; - Error("TicketUploader::RunCommand:", msg.str()); + Error(ssprintf("'%s' exited with %d", cmd, retcode).c_str()); } } -string CTicketUploader::ReadCommand(string cmd) +static string ReadCommand(const char *cmd) { - FILE* fp = popen(cmd.c_str(),"r"); + FILE* fp = popen(cmd, "r"); if (!fp) { - Error("TicketUploader::ReadCommand:", "error: could not start subshell: " + cmd); + Error(ssprintf("error running '%s'", cmd).c_str()); } - __gnu_cxx::stdio_filebuf<char> command_output_buffer(fp, std::ios_base::in); - std::ostringstream output_stream; - output_stream << &command_output_buffer; + string result; + char buff[1024]; + while (fgets(buff, sizeof(buff), fp) != NULL) + { + result += buff; + } int retcode = pclose(fp); if (retcode) { - std::ostringstream msg; - msg << "error: subshell failed (rc=" << retcode << "):" << cmd; - Error("TicketUploader::ReadCommand:", msg.str()); + Error(ssprintf("'%s' exited with %d", cmd, retcode).c_str()); } - return output_stream.str(); + return result; } -void CTicketUploader::WriteCommand(string cmd,string input) +static void WriteCommand(const char *cmd, const char *input) { - FILE* fp = popen(cmd.c_str(),"w"); + FILE* fp = popen(cmd, "w"); if (!fp) { - Error("TicketUploader::WriteCommand:", "error: could not start subshell: " + cmd); + Error(ssprintf("error running '%s'", cmd).c_str()); } - size_t input_length = input.length(); - size_t check = fwrite(input.c_str(),1,input_length,fp); - if (input_length != check) - { - Error("TicketUploader::WriteCommand:", "error: could not send input to subshell: " + cmd); - } + /* Hoping it's not too big to get us forever blocked... */ + fputs(input, fp); int retcode = pclose(fp); if (retcode) { - std::ostringstream msg; - msg << "error: subshell failed (rc=" << retcode << "):" << cmd; - Error("TicketUploader::ReadCommand:", msg.str()); + Error(ssprintf("'%s' exited with %d", cmd, retcode).c_str()); } - } -void CTicketUploader::SendFile(const std::string& pURL, - const std::string& pFilename) +void CTicketUploader::SendFile(const char *pURL, const char *pFilename) { - FILE * f; - struct stat buf; - CURL * curl; - std::string wholeURL, protocol; - int result, i, count = m_nRetryCount; - int len = pURL.length(); - std::string file; - - if (pURL == "") + if (pURL[0] == '\0') { warn_client(_("FileTransfer: URL not specified")); return; } - protocol = ""; - i = 0; - while(pURL[i] != ':') - { - protocol += pURL[i]; - i++; - if(i == len) - { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): malformed URL, does not contain protocol"); - } - } - file = pFilename.substr(pFilename.rfind("/") + 1, pFilename.length()); - - if( pURL[len-1] == '/' ) - { - wholeURL = pURL + file; - } - else - { - wholeURL = pURL + "/" + file; - } - - update_client(_("Sending archive ") + pFilename + _(" via ") + protocol + _(" to ") + pURL); + update_client(ssprintf(_("Sending archive %s to %s"), pFilename, pURL)); + const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1; + string wholeURL = concat_path_file(pURL, base); + int count = m_nRetryCount; + int result; do { - f = fopen(pFilename.c_str(),"r"); - if(!f) + FILE* 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 (stat(pFilename.c_str(), &buf) == -1) + struct stat buf; + if (fstat(fileno(f), &buf) == -1) { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): cannot stat archive file "+pFilename); + throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't stat archive file '%s'", pFilename)); } - curl = curl_easy_init(); - if(!curl) + CURL* 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); @@ -196,48 +135,38 @@ void CTicketUploader::SendFile(const std::string& pURL, curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str()); /*file handle: passed to the default callback, it will fread() it*/ curl_easy_setopt(curl, CURLOPT_READDATA, f); - /*get file size*/ curl_easy_setopt(curl, CURLOPT_INFILESIZE, buf.st_size); - /*everything is done here; result 0 means success*/ + /* everything is done here; result 0 means success */ result = curl_easy_perform(curl); - /*goodbye*/ + /* goodbye */ curl_easy_cleanup(curl); fclose(f); if (result != 0) { - update_client(_("Sending failed, try it again: ") + std::string(curl_easy_strerror((CURLcode)result))); + update_client(ssprintf(_("Sending failed, trying again. %s"), curl_easy_strerror((CURLcode)result))); } } /*retry the upload if not succesful, wait a bit before next try*/ - while( result!=0 && --count != 0 && (sleep(m_nRetryDelay),1) ); + while (result != 0 && --count != 0 && (sleep(m_nRetryDelay), 1)); if (count <= 0 && result != 0) { - throw CABRTException(EXCEP_PLUGIN, "CFileTransfer::SendFile(): Curl can not send a ticket."); + throw CABRTException(EXCEP_PLUGIN, "Curl can not send a ticket"); } } string CTicketUploader::Report(const map_crash_report_t& pCrashReport, - const map_plugin_settings_t& pSettings, const std::string& pArgs) + const map_plugin_settings_t& pSettings, const string& pArgs) { - string ret; update_client(_("Creating an TicketUploader report...")); - - // Get ticket name, customer name, and do_encrypt from config settings - string ticket_name; - string customer_name; - string upload_url; - bool do_encrypt = false; - bool do_upload = false; - - customer_name = m_sCustomer; - ticket_name = m_sTicket; - upload_url = m_sURL; - do_encrypt = m_bEncrypt; - do_upload = m_bUpload; + string customer_name = m_sCustomer; + string ticket_name = m_sTicket; + string upload_url = m_sURL; + bool do_encrypt = m_bEncrypt; + bool do_upload = m_bUpload; bool have_ticket_name = false; if (ticket_name == "") @@ -249,168 +178,148 @@ string CTicketUploader::Report(const map_crash_report_t& pCrashReport, have_ticket_name = true; } - - // Format the time to add to the file name const int timebufmax = 256; char timebuf[timebufmax]; time_t curtime = time(NULL); - if (!strftime(timebuf,timebufmax,"-%G%m%d%k%M%S",gmtime(&curtime))) + if (!strftime(timebuf, timebufmax, "-%G%m%d%k%M%S", gmtime(&curtime))) { - Error("TicketUploader::Report:","could not format time"); + Error("Can't format time"); } - - // Create a tmp work directory, and within that the directory // that will be the root of the tarball string file_name = ticket_name + timebuf; - char TEMPLATE[] = "/tmp/rhuploadXXXXXX"; - string tmpdir_name = mkdtemp(TEMPLATE); - string tmptar_name = tmpdir_name + '/' + file_name; + char tmpdir_name[] = "/tmp/rhuploadXXXXXX"; + if (mkdtemp(tmpdir_name) == NULL) + { + Error("Can't mkdir a temporary directory in /tmp"); + } + string tmptar_name = concat_path_file(tmpdir_name, file_name.c_str()); if (mkdir(tmptar_name.c_str(),S_IRWXU)) { - Error("TicketUploader::Report:","error: could not mkdir: " + tmptar_name); + Error(ssprintf("Can't mkdir '%s'", tmptar_name.c_str()).c_str()); } - - // Copy each entry into the tarball root, // files are simply copied, strings are written to a file map_crash_report_t::const_iterator it; for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) { - if (it->second[CD_TYPE] == CD_TXT) - { - string ofile_name = tmptar_name + '/' + it->first; - std::ofstream ofile(ofile_name.c_str(),std::fstream::trunc|std::fstream::binary); + if (it->second[CD_TYPE] == CD_TXT + || it->second[CD_TYPE] == CD_ATT + ) { + string ofile_name = concat_path_file(tmptar_name.c_str(), it->first.c_str()); + ofstream ofile(ofile_name.c_str(), fstream::trunc|fstream::binary); if (!ofile) { - Error("TicketUploader::Report:","error: could not open: " + ofile_name); + Error(ssprintf("Can't open '%s'", ofile_name.c_str()).c_str()); } - ofile << it->second[CD_CONTENT] << std::endl; + ofile << it->second[CD_CONTENT] << endl; ofile.close(); } - if (it->second[CD_TYPE] == CD_ATT) + else if (it->second[CD_TYPE] == CD_BIN) { - string ofile_name = tmptar_name + '/' + it->first; - std::ofstream ofile(ofile_name.c_str(),std::fstream::trunc|std::fstream::binary); - if (!ofile) + string ofile_name = concat_path_file(tmptar_name.c_str(), it->first.c_str()); + if (copy_file(it->second[CD_CONTENT].c_str(), ofile_name.c_str()) < 0) { - Error("TicketUploader::Report:","error: could not open: " + ofile_name); + throw CABRTException(EXCEP_PLUGIN, + ssprintf("Can't copy '%s' to '%s'", + it->second[CD_CONTENT].c_str(), + ofile_name.c_str() + ) + ); } - ofile << it->second[CD_CONTENT] << std::endl; - ofile.close(); - } - if (it->second[CD_TYPE] == CD_BIN) - { - string ofile_name = tmptar_name + '/' + it->first; - CopyFile(it->second[CD_CONTENT],ofile_name); } } - - // add ticket_name and customer name to tarball if (have_ticket_name) { string ofile_name = tmptar_name + "/TICKET"; - std::ofstream ofile(ofile_name.c_str(),std::fstream::trunc|std::fstream::binary); + ofstream ofile(ofile_name.c_str(), fstream::trunc|fstream::binary); if (!ofile) { - Error("TicketUploader::Report:","error: could not open: " + ofile_name); + Error(ssprintf("Can't open '%s'", ofile_name.c_str()).c_str()); } - ofile << ticket_name << std::endl; + ofile << ticket_name << endl; ofile.close(); } if (customer_name != "") { string ofile_name = tmptar_name + "/CUSTOMER"; - std::ofstream ofile(ofile_name.c_str(),std::fstream::trunc|std::fstream::binary); + ofstream ofile(ofile_name.c_str(), fstream::trunc|fstream::binary); if (!ofile) { - Error("TicketUploader::Report:","error: could not open: " + ofile_name); + Error(ssprintf("Can't open '%s'", ofile_name.c_str()).c_str()); } - ofile << customer_name << std::endl; + ofile << customer_name << endl; ofile.close(); } - - // Create the compressed tarball string outfile_basename = file_name + ".tar.gz"; - string outfile_name = tmpdir_name + '/' + outfile_basename; - string cmd = string("tar -C ") + tmpdir_name + - " --create --gzip --file=" + outfile_name + ' ' + file_name; - RunCommand(cmd); - - - + string outfile_name = concat_path_file(tmpdir_name, outfile_basename.c_str()); + string cmd = ssprintf("tar -C %s --create --gzip --file=%s %s", tmpdir_name, outfile_name.c_str(), file_name.c_str()); + RunCommand(cmd.c_str()); // encrypt if requested string key; if (do_encrypt) { - cmd = string("openssl rand -base64 48"); - key = ReadCommand(cmd); + key = ReadCommand("openssl rand -base64 48"); string infile_name = outfile_name; outfile_basename += ".aes"; outfile_name += ".aes"; - cmd = string("openssl aes-128-cbc -in ") + infile_name + - " -out " + outfile_name + " -pass stdin"; - WriteCommand(cmd,key); + cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name.c_str()); + WriteCommand(cmd.c_str(), key.c_str()); } - - // generate md5sum - cmd = string("cd ") + tmpdir_name + string("; md5sum ") + outfile_basename; - string md5sum = ReadCommand(cmd); - - + cmd = ssprintf("cd %s; md5sum %s", tmpdir_name, outfile_basename.c_str()); + string md5sum = ReadCommand(cmd.c_str()); // upload or cp to /tmp if (do_upload) { // FIXME: SendFile isn't working sometime (scp) - SendFile(upload_url,outfile_name); + SendFile(upload_url.c_str(), outfile_name.c_str()); } else { - cmd = string("cp ") + outfile_name + " /tmp/"; - RunCommand(cmd); + cmd = ssprintf("cp %s /tmp/", outfile_name.c_str()); + RunCommand(cmd.c_str()); } - - // generate a reciept telling md5sum and encryption key - std::ostringstream msgbuf; + ostringstream msgbuf; if (have_ticket_name) - msgbuf << _("Please copy this into ticket: ") << ticket_name << std::endl; + msgbuf << _("Please copy this into ticket: ") << ticket_name << endl; else - msgbuf << _("Please send this to your technical support: ") << std::endl; + msgbuf << _("Please send this to your technical support: ") << endl; if (do_upload) - msgbuf << _("RHUPLOAD: This report was sent to ") + upload_url << std::endl; + msgbuf << _("RHUPLOAD: This report was sent to ") + upload_url << endl; else - msgbuf << _("RHUPLOAD: This report was copied into /tmp/: ") << std::endl; + msgbuf << _("RHUPLOAD: This report was copied into /tmp/: ") << endl; if (have_ticket_name) - msgbuf << _("TICKET: ") << ticket_name << std::endl; - msgbuf << _("FILE: ") << outfile_basename << std::endl; - msgbuf << _("MD5SUM: ") << std::endl; + msgbuf << _("TICKET: ") << ticket_name << endl; + msgbuf << _("FILE: ") << outfile_basename << endl; + msgbuf << _("MD5SUM: ") << endl; msgbuf << md5sum; if (do_encrypt) { - msgbuf << _("KEY: aes-128-cbc") << std::endl; + msgbuf << _("KEY: aes-128-cbc") << endl; msgbuf << key; } - msgbuf << _("END: ") << std::endl; + msgbuf << _("END: ") << endl; warn_client(msgbuf.str()); + string ret; if (do_upload) { string xx = _("report sent to ") + upload_url + '/' + outfile_basename; @@ -425,41 +334,51 @@ string CTicketUploader::Report(const map_crash_report_t& pCrashReport, } // delete the temporary directory - cmd = string("rm -rf ") + tmpdir_name; - RunCommand(cmd); + cmd = ssprintf("rm -rf %s", tmpdir_name); + RunCommand(cmd.c_str()); return ret; } void CTicketUploader::SetSettings(const map_plugin_settings_t& pSettings) { - if (pSettings.find("Customer") != pSettings.end()) + map_plugin_settings_t::const_iterator end = pSettings.end(); + map_plugin_settings_t::const_iterator it; + + it = pSettings.find("Customer"); + if (it != end) { - m_sCustomer = pSettings.find("Customer")->second; + m_sCustomer = it->second; } - if (pSettings.find("Ticket") != pSettings.end()) + it = pSettings.find("Ticket"); + if (it != end) { - m_sTicket = pSettings.find("Ticket")->second; + m_sTicket = it->second; } - if (pSettings.find("URL") != pSettings.end()) + it = pSettings.find("URL"); + if (it != end) { - m_sURL = pSettings.find("URL")->second; + m_sURL = it->second; } - if (pSettings.find("Encrypt") != pSettings.end()) + it = pSettings.find("Encrypt"); + if (it != end) { - m_bEncrypt = pSettings.find("Encrypt")->second == "yes"; + m_bEncrypt = it->second == "yes"; } - if (pSettings.find("Upload") != pSettings.end()) + it = pSettings.find("Upload"); + if (it != end) { - m_bUpload = pSettings.find("Upload")->second == "yes"; + m_bUpload = it->second == "yes"; } - if (pSettings.find("RetryCount") != pSettings.end()) + it = pSettings.find("RetryCount"); + if (it != end) { - m_nRetryCount = atoi(pSettings.find("RetryCount")->second.c_str()); + m_nRetryCount = atoi(it->second.c_str()); } - if (pSettings.find("RetryDelay") != pSettings.end()) + it = pSettings.find("RetryDelay"); + if (it != end) { - m_nRetryDelay = atoi(pSettings.find("RetryDelay")->second.c_str()); + m_nRetryDelay = atoi(it->second.c_str()); } } @@ -473,12 +392,8 @@ map_plugin_settings_t CTicketUploader::GetSettings() ret["Encrypt"] = m_bEncrypt ? "yes" : "no"; ret["Upload"] = m_bEncrypt ? "yes" : "no"; - std::stringstream ss; - ss << m_nRetryCount; - ret["RetryCount"] = ss.str(); - ss.str(""); - ss << m_nRetryDelay; - ret["RetryDelay"] = ss.str(); + ret["RetryCount"] = to_string(m_nRetryCount); + ret["RetryDelay"] = to_string(m_nRetryDelay); return ret; } diff --git a/lib/Plugins/TicketUploader.h b/lib/Plugins/TicketUploader.h index 92e3387..8995481 100644 --- a/lib/Plugins/TicketUploader.h +++ b/lib/Plugins/TicketUploader.h @@ -29,34 +29,18 @@ #include "Reporter.h" #include "CrashTypes.h" -typedef std::string string; - class CTicketUploader : public CReporter { private: - string m_sCustomer; - string m_sTicket; - string m_sURL; - bool m_bEncrypt; - bool m_bUpload; - - int m_nRetryCount; - int m_nRetryDelay; - - void Error(string func, string msg); - void CopyFile(const std::string& pSourceName, const std::string& pDestName); - // Wrappers around popen/system - // the wrapper in each case handles errors, - // and converts from string->char* - // RunCommand - a wrapper around system(cmd) - void RunCommand(string cmd); - // ReadCommand - a wrapper around popen(cmd,"r") - string ReadCommand(string cmd); - // WriteCommand - a wrapper around popen(cmd,"w") - void WriteCommand(string cmd, string input ); + std::string m_sCustomer; + std::string m_sTicket; + std::string m_sURL; + bool m_bEncrypt; + bool m_bUpload; + int m_nRetryCount; + int m_nRetryDelay; - void SendFile(const std::string& pURL, - const std::string& pFilename); + void SendFile(const char *pURL, const char *pFilename); public: CTicketUploader(); @@ -64,11 +48,9 @@ class CTicketUploader : public CReporter virtual map_plugin_settings_t GetSettings(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, const std::string& pArgs); - - }; -#endif /* TICKETUPLOADER_H_ */ +#endif diff --git a/lib/Utils/Action.h b/lib/Utils/Action.h index 1286feb..5992cbf 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 e5bda57..9108a91 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 b5b8db7..8490e2f 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 ec9e470..276c42f 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -39,9 +39,16 @@ static bool isdigit_str(const char *str) return true; } -static std::string RemoveBackSlashes(const std::string& pDir); +static std::string RemoveBackSlashes(const char *pDir) +{ + unsigned len = strlen(pDir); + while (len != 0 && pDir[len-1] == '/') + len--; + return std::string(pDir, len); +} + 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(""), @@ -50,7 +57,7 @@ CDebugDump::CDebugDump() : m_bLocked(false) {} -void CDebugDump::Open(const std::string& pDir) +void CDebugDump::Open(const char *pDir) { if (m_bOpened) { @@ -59,7 +66,7 @@ void CDebugDump::Open(const std::string& pDir) m_sDebugDumpDir = RemoveBackSlashes(pDir); if (!ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+m_sDebugDumpDir+" does not exist."); + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): " + m_sDebugDumpDir + " does not exist."); } Lock(); m_bOpened = true; @@ -208,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); 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(); @@ -228,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; @@ -245,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) @@ -267,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); } @@ -275,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); } } @@ -331,16 +339,6 @@ static bool IsTextFile(const char *name) return true; } -static std::string RemoveBackSlashes(const std::string& pDir) -{ - std::string ret = pDir; - while (ret[ret.length() - 1] == '/') - { - ret = ret.substr(0, ret.length() - 2); - } - return ret; -} - void CDebugDump::Delete() { if (!ExistFileDir(m_sDebugDumpDir.c_str())) @@ -374,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); + SaveText(FILENAME_RELEASE, release.c_str()); } -void CDebugDump::SaveTime() +static void LoadTextFile(const char *pPath, std::string& pData) { - time_t t = time(NULL); - SaveText(FILENAME_TIME, to_string(t)); -} - -static void LoadTextFile(const std::string& 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)); } } @@ -477,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() @@ -538,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())) @@ -548,7 +481,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool } else { - pContent = ""; + pContent.clear(); pIsTextFile = false; } return true; @@ -558,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 189b42d..b48a386 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 d6ec6f3..db74865 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 diff --git a/lib/Utils/copyfd.cpp b/lib/Utils/copyfd.cpp index cda52b0..9abe752 100644 --- a/lib/Utils/copyfd.cpp +++ b/lib/Utils/copyfd.cpp @@ -105,3 +105,25 @@ off_t copyfd_eof(int fd1, int fd2) { return full_fd_action(fd1, fd2, 0); } + +off_t copy_file(const char *src_name, const char *dst_name) +{ + off_t r; + int src = open(src_name, O_RDONLY); + if (src < 0) + { + perror_msg("Can't open '%s'", src_name); + return -1; + } + int dst = open(dst_name, O_WRONLY | O_TRUNC | O_CREAT, 0666); + if (dst < 0) + { + close(src); + perror_msg("Can't open '%s'", dst_name); + return -1; + } + r = copyfd_eof(src, dst); + close(src); + close(dst); + return r; +} diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index 533fbfa..97c2f76 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -355,3 +355,16 @@ std::string concat_path_file(const char *path, const char *filename) lc = last_char_is(path, '/'); return ssprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); } + +bool string_to_bool(const char *s) +{ + if (s[0] == '1' && s[1] == '\0') + return true; + if (strcasecmp(s, "on") == 0) + return true; + if (strcasecmp(s, "yes") == 0) + return true; + if (strcasecmp(s, "true") == 0) + return true; + return false; +} diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp index 327e24f..2eed556 100644 --- a/src/Applet/Applet.cpp +++ b/src/Applet/Applet.cpp @@ -49,13 +49,12 @@ static void Crash(DBusMessage* signal) dbus_message_iter_init(signal, &in_iter); const char* progname; r = load_val(&in_iter, progname); - if (r != ABRT_DBUS_MORE_FIELDS) + /* Optional 2nd param: uid */ + const char* uid_str = NULL; + if (r == ABRT_DBUS_MORE_FIELDS) { - error_msg("dbus signal %s: parameter type mismatch", __func__); - return; + r = load_val(&in_iter, uid_str); } - const char* uid_str; - r = load_val(&in_iter, uid_str); if (r != ABRT_DBUS_LAST_FIELD) { error_msg("dbus signal %s: parameter type mismatch", __func__); @@ -66,13 +65,17 @@ static void Crash(DBusMessage* signal) // return; // uid_t uid_num = atol(uid_str); - char* endptr; - int64_t uid_num = strtoll(uid_str,&endptr, 10); - - if ((uid_num != getuid()) && (uid_num != -1)) + if (uid_str != NULL) { - return; + char *end; + errno = 0; + unsigned long uid_num = strtoul(uid_str, &end, 10); + if (errno || *end != '\0' || uid_num != getuid()) + { + return; + } } + const char* message = _("A crash in package %s has been detected"); //applet->AddEvent(uid, progname); applet->SetIconTooltip(message, progname); diff --git a/src/Daemon/CommLayerServer.h b/src/Daemon/CommLayerServer.h index 6ede581..21c1b30 100644 --- a/src/Daemon/CommLayerServer.h +++ b/src/Daemon/CommLayerServer.h @@ -13,7 +13,7 @@ class CCommLayerServer { virtual ~CCommLayerServer(); /* just stubs to be called when not implemented in specific comm layer */ - virtual void Crash(const std::string& progname, const std::string& uid) {} + virtual void Crash(const char *progname, const char *uid_str) {} virtual void JobDone(const char* pDest, const char* pUUID) = 0; virtual void QuotaExceed(const char* str) {} diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index 2483942..925844e 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -46,16 +46,24 @@ static void send_flush_and_unref(DBusMessage* msg) } /* Notify the clients (UI) about a new crash */ -void CCommLayerServerDBus::Crash(const std::string& progname, const std::string& uid) +void CCommLayerServerDBus::Crash(const char *progname, const char *uid_str) { DBusMessage* msg = new_signal_msg("Crash"); - const char* c_progname = progname.c_str(); - const char* c_uid = uid.c_str(); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &c_progname, - DBUS_TYPE_STRING, &c_uid, - DBUS_TYPE_INVALID); - VERB2 log("Sending signal Crash('%s','%s')", c_progname, c_uid); + if (uid_str) + { + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &progname, + DBUS_TYPE_STRING, &uid_str, + DBUS_TYPE_INVALID); + VERB2 log("Sending signal Crash('%s','%s')", progname, uid_str); + } + else + { + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &progname, + DBUS_TYPE_INVALID); + VERB2 log("Sending signal Crash('%s')", progname); + } send_flush_and_unref(msg); } @@ -127,7 +135,7 @@ static long get_remote_uid(DBusMessage* call, const char** ppSender = NULL) static int handle_GetCrashInfos(DBusMessage* call, DBusMessage* reply) { long unix_uid = get_remote_uid(call); - vector_crash_infos_t argout1 = GetCrashInfos(to_string(unix_uid)); + vector_crash_infos_t argout1 = GetCrashInfos(to_string(unix_uid).c_str()); DBusMessageIter iter; dbus_message_iter_init_append(reply, &iter); @@ -273,7 +281,7 @@ static int handle_Report(DBusMessage* call, DBusMessage* reply) report_status_t argout1; try { - argout1 = Report(argin1, user_conf_data, to_string(unix_uid)); + argout1 = Report(argin1, user_conf_data, to_string(unix_uid).c_str()); } catch (CABRTException &e) { @@ -307,7 +315,7 @@ static int handle_DeleteDebugDump(DBusMessage* call, DBusMessage* reply) } long unix_uid = get_remote_uid(call); - bool argout1 = DeleteDebugDump(argin1, to_string(unix_uid)); + bool argout1 = DeleteDebugDump(argin1, to_string(unix_uid).c_str()); dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &argout1, diff --git a/src/Daemon/CommLayerServerDBus.h b/src/Daemon/CommLayerServerDBus.h index 7b2e31d..f159c73 100644 --- a/src/Daemon/CommLayerServerDBus.h +++ b/src/Daemon/CommLayerServerDBus.h @@ -11,7 +11,7 @@ class CCommLayerServerDBus virtual ~CCommLayerServerDBus(); /* DBus signal senders */ - virtual void Crash(const std::string& progname, const std::string& uid); + virtual void Crash(const char *progname, const char *uid_str); virtual void JobDone(const char* pDest, const char* pUUID); virtual void QuotaExceed(const char* str); diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index ad3f37a..aa86350 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -22,16 +22,16 @@ #include "ABRTException.h" #include "CrashWatcher.h" -void CCrashWatcher::Status(const std::string& pMessage, const char* peer, uint64_t pJobID) +void CCrashWatcher::Status(const char *pMessage, const char* peer, uint64_t pJobID) { - VERB1 log("Update('%s'): %s", peer, pMessage.c_str()); + VERB1 log("Update('%s'): %s", peer, pMessage); if (g_pCommLayer != NULL) g_pCommLayer->Update(pMessage, peer, pJobID); } -void CCrashWatcher::Warning(const std::string& pMessage, const char* peer, uint64_t pJobID) +void CCrashWatcher::Warning(const char *pMessage, const char* peer, uint64_t pJobID) { - VERB1 log("Warning('%s'): %s", peer, pMessage.c_str()); + VERB1 log("Warning('%s'): %s", peer, pMessage); if (g_pCommLayer != NULL) g_pCommLayer->Warning(pMessage, peer, pJobID); } @@ -44,7 +44,7 @@ CCrashWatcher::~CCrashWatcher() { } -vector_crash_infos_t GetCrashInfos(const std::string &pUID) +vector_crash_infos_t GetCrashInfos(const char *pUID) { vector_crash_infos_t retval; log("Getting crash infos..."); @@ -59,7 +59,7 @@ vector_crash_infos_t GetCrashInfos(const std::string &pUID) mw_result_t res; map_crash_info_t info; - res = GetCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second, info); + res = GetCrashInfo(UUIDsUIDs[ii].first.c_str(), UUIDsUIDs[ii].second.c_str(), info); switch (res) { case MW_OK: @@ -68,15 +68,14 @@ vector_crash_infos_t GetCrashInfos(const std::string &pUID) case MW_ERROR: warn_client("Can not find debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting from database"); update_client("Can not find debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting from database"); - DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); + DeleteCrashInfo(UUIDsUIDs[ii].first.c_str(), UUIDsUIDs[ii].second.c_str()); break; case MW_FILE_ERROR: { - std::string debugDumpDir; warn_client("Can not open file in debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting"); update_client("Can not open file in debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting"); - debugDumpDir = DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); - DeleteDebugDumpDir(debugDumpDir); + std::string debugDumpDir = DeleteCrashInfo(UUIDsUIDs[ii].first.c_str(), UUIDsUIDs[ii].second.c_str()); + DeleteDebugDumpDir(debugDumpDir.c_str()); } break; default: @@ -134,7 +133,7 @@ map_crash_report_t GetJobResult(const char* pUUID, const char* pUID, int force) default: warn_client(std::string("Corrupted crash with UUID ") + pUUID + ", deleting"); std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID); - DeleteDebugDumpDir(debugDumpDir); + DeleteDebugDumpDir(debugDumpDir.c_str()); break; } return crashReport; @@ -208,12 +207,12 @@ int CreateReportThread(const char* pUUID, const char* pUID, int force, const cha return r; } -bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID) +bool DeleteDebugDump(const char *pUUID, const char *pUID) { try { std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID); - DeleteDebugDumpDir(debugDumpDir); + DeleteDebugDumpDir(debugDumpDir.c_str()); } catch (CABRTException& e) { diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index d8c7c28..995d2a1 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -44,13 +44,13 @@ class CCrashWatcher public: /* Observer methods */ - virtual void Status(const std::string& pMessage, const char* peer, uint64_t pJobID); - virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pJobID); + virtual void Status(const char *pMessage, const char* peer, uint64_t pJobID); + virtual void Warning(const char *pMessage, const char* peer, uint64_t pJobID); }; -vector_crash_infos_t GetCrashInfos(const std::string &pUID); +vector_crash_infos_t GetCrashInfos(const char *pUID); int CreateReportThread(const char* pUUID, const char* pUID, int force, const char* pSender); map_crash_report_t GetJobResult(const char* pUUID, const char* pUID, int force); -bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID); +bool DeleteDebugDump(const char *pUUID, const char *pUID); #endif /*CRASHWATCHER_H_*/ diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 175efe9..b417cfd 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -165,6 +165,18 @@ static double GetDirSize(const std::string &pPath, std::string *worst_dir = NULL return size; } +static bool analyzer_has_InformAllUsers(const char *analyzer_name) +{ + CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(analyzer_name); + if (!analyzer) + return false; + map_plugin_settings_t settings = analyzer->GetSettings(); + map_plugin_settings_t::const_iterator it = settings.find("InformAllUsers"); + if (it == settings.end()) + return false; + return string_to_bool(it->second.c_str()); +} + static void cron_delete_callback_data_cb(gpointer data) { cron_callback_data_t* cronDeleteCallbackData = static_cast<cron_callback_data_t*>(data); @@ -176,8 +188,9 @@ static gboolean cron_activation_periodic_cb(gpointer data) cron_callback_data_t* cronPeriodicCallbackData = static_cast<cron_callback_data_t*>(data); VERB1 log("Activating plugin: %s", cronPeriodicCallbackData->m_sPluginName.c_str()); RunAction(DEBUG_DUMPS_DIR, - cronPeriodicCallbackData->m_sPluginName, - cronPeriodicCallbackData->m_sPluginArgs); + cronPeriodicCallbackData->m_sPluginName.c_str(), + cronPeriodicCallbackData->m_sPluginArgs.c_str() + ); return TRUE; } static gboolean cron_activation_one_cb(gpointer data) @@ -185,8 +198,9 @@ static gboolean cron_activation_one_cb(gpointer data) cron_callback_data_t* cronOneCallbackData = static_cast<cron_callback_data_t*>(data); VERB1 log("Activating plugin: %s", cronOneCallbackData->m_sPluginName.c_str()); RunAction(DEBUG_DUMPS_DIR, - cronOneCallbackData->m_sPluginName, - cronOneCallbackData->m_sPluginArgs); + cronOneCallbackData->m_sPluginName.c_str(), + cronOneCallbackData->m_sPluginArgs.c_str() + ); return FALSE; } static gboolean cron_activation_reshedule_cb(gpointer data) @@ -200,7 +214,8 @@ static gboolean cron_activation_reshedule_cb(gpointer data) cronPeriodicCallbackData->m_nTimeout, cron_activation_periodic_cb, static_cast<gpointer>(cronPeriodicCallbackData), - cron_delete_callback_data_cb); + cron_delete_callback_data_cb + ); return FALSE; } @@ -226,7 +241,7 @@ static void SetUpMW() vector_pair_string_string_t::iterator it_ar = g_settings_vectorActionsAndReporters.begin(); for (; it_ar != g_settings_vectorActionsAndReporters.end(); it_ar++) { - AddActionOrReporter(it_ar->first, it_ar->second); + AddActionOrReporter(it_ar->first.c_str(), it_ar->second.c_str()); } VERB1 log("Adding analyzers, actions or reporters"); map_analyzer_actions_and_reporters_t::iterator it_aar = g_settings_mapAnalyzerActionsAndReporters.begin(); @@ -235,7 +250,7 @@ static void SetUpMW() vector_pair_string_string_t::iterator it_ar = it_aar->second.begin(); for (; it_ar != it_aar->second.end(); it_ar++) { - AddAnalyzerActionOrReporter(it_aar->first, it_ar->first, it_ar->second); + AddAnalyzerActionOrReporter(it_aar->first.c_str(), it_ar->first.c_str(), it_ar->second.c_str()); } } } @@ -369,13 +384,12 @@ static void FindNewDumps(const char* pPath) map_crash_info_t crashinfo; try { - mw_result_t res; - res = SaveDebugDump(*itt, crashinfo); + mw_result_t res = SaveDebugDump(itt->c_str(), crashinfo); switch (res) { case MW_OK: VERB1 log("Saving into database (%s)", itt->c_str()); - RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); + RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT].c_str()); break; case MW_IN_DB: VERB1 log("Already saved in database (%s)", itt->c_str()); @@ -391,7 +405,7 @@ static void FindNewDumps(const char* pPath) //Perhaps corrupted & bad needs to be logged unconditionally, //already saved one - only on VERB1 VERB1 log("Corrupted, bad or already saved crash, deleting"); - DeleteDebugDumpDir(*itt); + DeleteDebugDumpDir(itt->c_str()); break; } } @@ -515,47 +529,34 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin ) { log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir.c_str()); g_pCommLayer->QuotaExceed(_("Report size exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); - DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + worst_dir); + DeleteDebugDumpDir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str()); worst_dir = ""; } map_crash_info_t crashinfo; try { - mw_result_t res; - res = SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); + std::string fullname = concat_path_file(DEBUG_DUMPS_DIR, name); + + mw_result_t res = SaveDebugDump(fullname.c_str(), crashinfo); switch (res) { case MW_OK: - log("New crash, saving..."); - RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); - /* Send dbus signal */ - if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") - { - // When Kerneloops comes it will be sent uid with -1 - // Applet will detected and show normal user - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); - } - else - { - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); - } - break; + log("New crash, saving"); + RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT].c_str()); + /* Fall through to "send dbus signal" */ case MW_REPORTED: case MW_OCCURED: - log("Already saved crash, deleting..."); + if (res != MW_OK) + log("Already saved crash, just sending dbus signal"); /* Send dbus signal */ - if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") - { - // When Kerneloops comes it will be sent uid with -1 - // Applet will detected and show normal user - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); - } - else { - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); + const char *uid_str = analyzer_has_InformAllUsers(crashinfo[CD_MWANALYZER][CD_CONTENT].c_str()) + ? NULL + : crashinfo[CD_UID][CD_CONTENT].c_str(); + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT].c_str(), uid_str); } - //DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + //DeleteDebugDumpDir(fullname.c_str()); break; case MW_BLACKLISTED: case MW_CORRUPTED: @@ -564,8 +565,8 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin case MW_IN_DB: case MW_FILE_ERROR: default: - log("Corrupted or bad crash, deleting..."); - DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + log("Corrupted or bad crash, deleting"); + DeleteDebugDumpDir(fullname.c_str()); break; } } @@ -825,7 +826,7 @@ int main(int argc, char** argv) SetUpMW(); /* logging is inside */ if (SetUpCron() != 0) throw 1; -#ifdef ENABLE_DBUS +#if 1 //def ENABLE_DBUS VERB1 log("Initializing dbus"); g_pCommLayer = new CCommLayerServerDBus(); #elif ENABLE_SOCKET diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index 4365a0c..a5bb64f 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -2,6 +2,7 @@ bin_SCRIPTS = abrt-debuginfo-install sbin_PROGRAMS = abrtd +# disabled: CommLayerServerSocket.h CommLayerServerSocket.cpp abrtd_SOURCES = \ ABRTPlugin.h ABRTPlugin.cpp \ PluginManager.h PluginManager.cpp \ @@ -9,7 +10,6 @@ abrtd_SOURCES = \ MiddleWare.h MiddleWare.cpp \ CrashWatcher.h CrashWatcher.cpp \ CommLayerServer.h CommLayerServer.cpp \ - CommLayerServerSocket.h CommLayerServerSocket.cpp \ CommLayerServerDBus.h CommLayerServerDBus.cpp \ Daemon.h Daemon.cpp \ Settings.h Settings.cpp diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index e30a004..abf1381 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -20,6 +20,7 @@ */ #include "abrtlib.h" +#include "abrt_types.h" #include "Daemon.h" #include "Settings.h" #include "RPM.h" @@ -60,7 +61,7 @@ static map_analyzer_actions_and_reporters_t s_mapAnalyzerActionsAndReporters; static vector_pair_string_string_t s_vectorActionsAndReporters; -static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir); +static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir); /** @@ -69,7 +70,7 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& * @param pDebugDumpDir A debugdump dir containing all necessary data. * @param pCrashReport A created crash report. */ -static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport) +static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t& pCrashReport) { std::string fileName; std::string content; @@ -98,7 +99,8 @@ static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_r fileName, CD_BIN, CD_ISNOTEDITABLE, - pDebugDumpDir + "/" + fileName); + concat_path_file(pDebugDumpDir, fileName.c_str()) + ); } else { @@ -137,8 +139,8 @@ static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_r * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return A local UUID. */ -static std::string GetLocalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir) +static std::string GetLocalUUID(const char *pAnalyzer, + const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetLocalUUID(pDebugDumpDir); @@ -150,8 +152,8 @@ static std::string GetLocalUUID(const std::string& pAnalyzer, * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return A global UUID. */ -static std::string GetGlobalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir) +static std::string GetGlobalUUID(const char *pAnalyzer, + const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetGlobalUUID(pDebugDumpDir); @@ -164,32 +166,32 @@ static std::string GetGlobalUUID(const std::string& pAnalyzer, * @param pAnalyzer A name of an analyzer plugin. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ -static void CreateReport(const std::string& pAnalyzer, - const std::string& pDebugDumpDir, +static void CreateReport(const char *pAnalyzer, + const char *pDebugDumpDir, int force) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); analyzer->CreateReport(pDebugDumpDir, force); } -mw_result_t CreateCrashReport(const std::string& pUUID, - const std::string& pUID, +mw_result_t CreateCrashReport(const char *pUUID, + const char *pUID, int force, map_crash_report_t& pCrashReport) { - VERB2 log("CreateCrashReport('%s','%s',result)", pUUID.c_str(), pUID.c_str()); + VERB2 log("CreateCrashReport('%s','%s',result)", pUUID, pUID); database_row_t row; - if (pUUID != "") + if (pUUID[0] != '\0') { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); row = database->GetUUIDData(pUUID, pUID); database->DisConnect(); } - if (pUUID == "" || row.m_sUUID != pUUID) + if (pUUID[0] == '\0' || row.m_sUUID != pUUID) { - warn_client("CreateCrashReport(): UUID '"+pUUID+"' is not in database"); + warn_client(ssprintf("CreateCrashReport(): UUID '%s' is not in database", pUUID)); return MW_IN_DB_ERROR; } @@ -202,7 +204,7 @@ mw_result_t CreateCrashReport(const std::string& pUUID, std::string reproduce = "1.\n2.\n3.\n"; VERB3 log(" LoadText(FILENAME_ANALYZER,'%s')", row.m_sDebugDumpDir.c_str()); - dd.Open(row.m_sDebugDumpDir); + dd.Open(row.m_sDebugDumpDir.c_str()); dd.LoadText(FILENAME_ANALYZER, analyzer); if (dd.Exist(FILENAME_COMMENT)) { @@ -215,15 +217,15 @@ mw_result_t CreateCrashReport(const std::string& pUUID, dd.Close(); VERB3 log(" CreateReport('%s')", analyzer.c_str()); - CreateReport(analyzer, row.m_sDebugDumpDir, force); + CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force); - gUUID = GetGlobalUUID(analyzer, row.m_sDebugDumpDir); + gUUID = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" GetGlobalUUID:'%s'", gUUID.c_str()); VERB3 log(" RunAnalyzerActions"); - RunAnalyzerActions(analyzer, row.m_sDebugDumpDir); + RunAnalyzerActions(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" DebugDumpToCrashReport"); - DebugDumpToCrashReport(row.m_sDebugDumpDir, pCrashReport); + DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashReport); add_crash_data_to_crash_report(pCrashReport, CD_UUID, CD_TXT, CD_ISNOTEDITABLE, gUUID); add_crash_data_to_crash_report(pCrashReport, CD_MWANALYZER, CD_SYS, CD_ISNOTEDITABLE, analyzer); @@ -239,11 +241,11 @@ mw_result_t CreateCrashReport(const std::string& pUUID, { return MW_ERROR; } - else if (e.type() == EXCEP_DD_LOAD) + if (e.type() == EXCEP_DD_LOAD) { return MW_FILE_ERROR; } - else if (e.type() == EXCEP_PLUGIN) + if (e.type() == EXCEP_PLUGIN) { return MW_PLUGIN_ERROR; } @@ -253,24 +255,23 @@ mw_result_t CreateCrashReport(const std::string& pUUID, return MW_OK; } -void RunAction(const std::string& pActionDir, - const std::string& pPluginName, - const std::string& pPluginArgs) +void RunAction(const char *pActionDir, + const char *pPluginName, + const char *pPluginArgs) { try { CAction* action = g_pPluginManager->GetAction(pPluginName); - action->Run(pActionDir, pPluginArgs); } catch (CABRTException& e) { - warn_client("RunAction(): " + e.what()); - update_client("Execution of '"+pPluginName+"' was not successful: " + e.what()); + warn_client(ssprintf("RunAction(): %s", e.what().c_str())); + update_client(ssprintf("Execution of '%s' was not successful: %s", pPluginName, e.what().c_str())); } } -void RunActionsAndReporters(const std::string& pDebugDumpDir) +void RunActionsAndReporters(const char *pDebugDumpDir) { vector_pair_string_string_t::iterator it_ar = s_vectorActionsAndReporters.begin(); map_plugin_settings_t plugin_settings; @@ -278,24 +279,24 @@ void RunActionsAndReporters(const std::string& pDebugDumpDir) { try { - if (g_pPluginManager->GetPluginType((*it_ar).first) == REPORTER) + if (g_pPluginManager->GetPluginType(it_ar->first) == REPORTER) { - CReporter* reporter = g_pPluginManager->GetReporter((*it_ar).first); + CReporter* reporter = g_pPluginManager->GetReporter(it_ar->first); map_crash_report_t crashReport; DebugDumpToCrashReport(pDebugDumpDir, crashReport); - reporter->Report(crashReport, plugin_settings, (*it_ar).second); + reporter->Report(crashReport, plugin_settings, it_ar->second); } - else if (g_pPluginManager->GetPluginType((*it_ar).first) == ACTION) + else if (g_pPluginManager->GetPluginType(it_ar->first) == ACTION) { - CAction* action = g_pPluginManager->GetAction((*it_ar).first); - action->Run(pDebugDumpDir, (*it_ar).second); + CAction* action = g_pPluginManager->GetAction(it_ar->first); + action->Run(pDebugDumpDir, it_ar->second.c_str()); } } catch (CABRTException& e) { warn_client("RunActionsAndReporters(): " + e.what()); - update_client("Activation of plugin '"+(*it_ar).first+"' was not successful: " + e.what()); + update_client("Activation of plugin '" + it_ar->first + "' was not successful: " + e.what()); } } } @@ -315,11 +316,11 @@ static bool CheckReport(const map_crash_report_t& pCrashReport) map_crash_report_t::const_iterator it_executable = pCrashReport.find(FILENAME_EXECUTABLE); map_crash_report_t::const_iterator end = pCrashReport.end(); - + // FIXME: bypass the test if it's kerneloops - if(it_package->second[CD_CONTENT] == "kernel") + if (it_package->second[CD_CONTENT] == "kernel") return true; - + if (it_analyzer == end || it_mwuid == end || it_mwuuid == end || it_package == end || it_architecture == end || it_kernel == end || @@ -343,7 +344,7 @@ static bool CheckReport(const map_crash_report_t& pCrashReport) report_status_t Report(const map_crash_report_t& pCrashReport, map_map_string_t& pSettings, - const std::string& pUID) + const char *pUID) { report_status_t ret; @@ -361,18 +362,18 @@ report_status_t Report(const map_crash_report_t& pCrashReport, // Save comments and how to reproduciton map_crash_report_t::const_iterator it_comment = pCrashReport.find(CD_COMMENT); map_crash_report_t::const_iterator it_reproduce = pCrashReport.find(CD_REPRODUCE); - std::string pDumpDir = getDebugDumpDir(UUID,UID); + std::string pDumpDir = getDebugDumpDir(UUID.c_str(), UID.c_str()); { CDebugDump dd; - dd.Open(pDumpDir); + dd.Open(pDumpDir.c_str()); if (it_comment != pCrashReport.end()) { - dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT]); + dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT].c_str()); } if (it_reproduce != pCrashReport.end()) { - dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT]); + dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT].c_str()); } } @@ -448,15 +449,15 @@ report_status_t Report(const map_crash_report_t& pCrashReport, return ret; } -void DeleteDebugDumpDir(const std::string& pDebugDumpDir) +void DeleteDebugDumpDir(const char *pDebugDumpDir) { CDebugDump dd; dd.Open(pDebugDumpDir); dd.Delete(); } -std::string DeleteCrashInfo(const std::string& pUUID, - const std::string& pUID) +std::string DeleteCrashInfo(const char *pUUID, + const char *pUID) { database_row_t row; CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); @@ -476,8 +477,8 @@ std::string DeleteCrashInfo(const std::string& pUUID, * @return It returns true if debugdump dir is already saved, otherwise * it returns false. */ -static bool IsDebugDumpSaved(const std::string& pUID, - const std::string& pDebugDumpDir) +static bool IsDebugDumpSaved(const char *pUID, + const char *pDebugDumpDir) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); @@ -511,19 +512,19 @@ void LoadOpenGPGPublicKey(const char* key) * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, - const std::string& pDebugDumpDir) +static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, + const char *pDebugDumpDir) { std::string package; std::string packageName; - if (pExecutable == "kernel") + if (strcmp(pExecutable, "kernel") == 0) { packageName = package = "kernel"; } else { - package = GetPackage(pExecutable.c_str()); + package = GetPackage(pExecutable); packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1)); if (packageName == "" || (g_setBlackList.find(packageName) != g_setBlackList.end())) @@ -543,7 +544,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta error_msg("package isn't signed with proper key"); return MW_GPG_ERROR; } - if (!CheckHash(packageName.c_str(), pExecutable.c_str())) + if (!CheckHash(packageName.c_str(), pExecutable)) { error_msg("executable has bad hash"); return MW_GPG_ERROR; @@ -552,15 +553,15 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta } std::string description = GetDescription(packageName.c_str()); - std::string component = GetComponent(pExecutable.c_str()); + std::string component = GetComponent(pExecutable); try { CDebugDump dd; dd.Open(pDebugDumpDir); - dd.SaveText(FILENAME_PACKAGE, package); - dd.SaveText(FILENAME_DESCRIPTION, description); - dd.SaveText(FILENAME_COMPONENT, component); + dd.SaveText(FILENAME_PACKAGE, package.c_str()); + dd.SaveText(FILENAME_DESCRIPTION, description.c_str()); + dd.SaveText(FILENAME_COMPONENT, component.c_str()); } catch (CABRTException& e) { @@ -581,7 +582,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecuta * @param pAnalyzer A name of an analyzer plugin. * @param pDebugDumpPath A debugdump dir containing all necessary data. */ -static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir) +static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir) { map_analyzer_actions_and_reporters_t::iterator analyzer = s_mapAnalyzerActionsAndReporters.find(pAnalyzer); if (analyzer != s_mapAnalyzerActionsAndReporters.end()) @@ -595,7 +596,7 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& if (g_pPluginManager->GetPluginType(pluginName) == ACTION) { CAction* action = g_pPluginManager->GetAction(pluginName); - action->Run(pDebugDumpDir, it_a->second); + action->Run(pDebugDumpDir, it_a->second.c_str()); } } catch (CABRTException& e) @@ -618,10 +619,10 @@ static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& * @param pCrashInfo A filled crash info. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, - const std::string& pUID, - const std::string& pTime, - const std::string& pDebugDumpDir, +static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, + const char *pUID, + const char *pTime, + const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { mw_result_t res; @@ -645,8 +646,8 @@ static mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, return res; } -std::string getDebugDumpDir( const std::string& pUUID, - const std::string& pUID) +std::string getDebugDumpDir(const char *pUUID, + const char *pUID) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database_row_t row; @@ -656,13 +657,13 @@ std::string getDebugDumpDir( const std::string& pUUID, return row.m_sDebugDumpDir; } -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir) +mw_result_t SaveDebugDump(const char *pDebugDumpDir) { map_crash_info_t info; return SaveDebugDump(pDebugDumpDir, info); } -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, +mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { std::string lUUID; @@ -691,23 +692,23 @@ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, return MW_ERROR; } - if (IsDebugDumpSaved(UID, pDebugDumpDir)) + if (IsDebugDumpSaved(UID.c_str(), pDebugDumpDir)) { return MW_IN_DB; } - res = SavePackageDescriptionToDebugDump(executable, pDebugDumpDir); + res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); if (res != MW_OK) { return res; } - lUUID = GetLocalUUID(analyzer, pDebugDumpDir); + lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); - return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo); + return SaveDebugDumpToDatabase(lUUID.c_str(), UID.c_str(), time.c_str(), pDebugDumpDir, pCrashInfo); } -mw_result_t GetCrashInfo(const std::string& pUUID, - const std::string& pUID, +mw_result_t GetCrashInfo(const char *pUUID, + const char *pUID, map_crash_info_t& pCrashInfo) { pCrashInfo.clear(); @@ -725,7 +726,7 @@ mw_result_t GetCrashInfo(const std::string& pUUID, try { CDebugDump dd; - dd.Open(row.m_sDebugDumpDir); + dd.Open(row.m_sDebugDumpDir.c_str()); dd.LoadText(FILENAME_EXECUTABLE, executable); dd.LoadText(FILENAME_PACKAGE, package); dd.LoadText(FILENAME_DESCRIPTION, description); @@ -755,7 +756,7 @@ mw_result_t GetCrashInfo(const std::string& pUUID, return MW_OK; } -vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID) +vector_pair_string_string_t GetUUIDsOfCrash(const char *pUID) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); vector_database_rows_t rows; @@ -773,15 +774,15 @@ vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID) return UUIDsUIDs; } -void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, - const std::string& pAnalyzerOrReporter, - const std::string& pArgs) +void AddAnalyzerActionOrReporter(const char *pAnalyzer, + const char *pAnalyzerOrReporter, + const char *pArgs) { - s_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(pAnalyzerOrReporter, pArgs)); + s_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(std::string(pAnalyzerOrReporter), std::string(pArgs))); } -void AddActionOrReporter(const std::string& pActionOrReporter, - const std::string& pArgs) +void AddActionOrReporter(const char *pActionOrReporter, + const char *pArgs) { - s_vectorActionsAndReporters.push_back(make_pair(pActionOrReporter, pArgs)); + s_vectorActionsAndReporters.push_back(make_pair(std::string(pActionOrReporter), std::string(pArgs))); } diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h index c78d4d9..0671dd0 100644 --- a/src/Daemon/MiddleWare.h +++ b/src/Daemon/MiddleWare.h @@ -63,8 +63,8 @@ void LoadOpenGPGPublicKey(const char* key); * @param pCrashReport A filled crash report. * @return It return results of operation. See mw_result_t. */ -mw_result_t CreateCrashReport(const std::string& pUUID, - const std::string& pUID, +mw_result_t CreateCrashReport(const char *pUUID, + const char *pUID, int force, map_crash_report_t& pCrashReport); /** @@ -73,15 +73,15 @@ mw_result_t CreateCrashReport(const std::string& pUUID, * @param pPluginName An action plugin name. * @param pPluginArgs Action plugin's arguments. */ -void RunAction(const std::string& pActionDir, - const std::string& pPluginName, - const std::string& pPluginArgs); +void RunAction(const char *pActionDir, + const char *pPluginName, + const char *pPluginArgs); /** * Activates all action and reporter plugins when any * crash occurs. * @param pDebugDumpDir A debugdump dir containing all necessary data. */ -void RunActionsAndReporters(const std::string& pDebugDumpDir); +void RunActionsAndReporters(const char *pDebugDumpDir); /** * Reports a crash report to particular receiver. It * takes an user uid, tries to find user config file and load it. If it @@ -94,7 +94,7 @@ void RunActionsAndReporters(const std::string& pDebugDumpDir); */ report_status_t Report(const map_crash_report_t& pCrashReport, map_map_string_t& pSettings, - const std::string& pUID); + const char *pUID); /** * Get debugdump direcotory. If debugdump is not found * in database it will return empty string. @@ -102,13 +102,13 @@ report_status_t Report(const map_crash_report_t& pCrashReport, * @param pUID An UID of an user. * @return A debugdump directory. */ -std::string getDebugDumpDir( const std::string& pUUID, - const std::string& pUID); +std::string getDebugDumpDir( const char *pUUID, + const char *pUID); /** * Deletes particular debugdump directory. * @param pDebugDumpDir A debugdump directory. */ -void DeleteDebugDumpDir(const std::string& pDebugDumpDir); +void DeleteDebugDumpDir(const char *pDebugDumpDir); /** * Deletes a row from database. If a deleting is * successfull, it returns a debugdump directort, which is not @@ -117,14 +117,14 @@ void DeleteDebugDumpDir(const std::string& pDebugDumpDir); * @param pUID An UID of an user. * @return A debugdump directory. */ -std::string DeleteCrashInfo(const std::string& pUUID, - const std::string& pUID); +std::string DeleteCrashInfo(const char *pUUID, + const char *pUID); /** * Saves debugdump into database. * @param pDebugDumpDir A debugdump directory. * @return It return results of operation. See mw_result_t. */ -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir); +mw_result_t SaveDebugDump(const char *pDebugDumpDir); /** * Saves debugdump into database. If saving is successful, * it fills crash info. @@ -132,7 +132,7 @@ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir); * @param pCrashInfo A crash info. * @return It return results of operation. See mw_result_t. */ -mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, +mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo); /** * Get one crash info. If getting is successful, @@ -142,8 +142,8 @@ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, * @param pCrashInfo A crash info. * @return It return results of operation. See mw_result_t. */ -mw_result_t GetCrashInfo(const std::string& pUUID, - const std::string& pUID, +mw_result_t GetCrashInfo(const char *pUUID, + const char *pUID, map_crash_info_t& pCrashInfo); /** * Gets all local UUIDs and UIDs of crashes. These crashes @@ -151,7 +151,7 @@ mw_result_t GetCrashInfo(const std::string& pUUID, * @param pUID an UID of an user. * @return A vector of pairs (local UUID, UID). */ -vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID); +vector_pair_string_string_t GetUUIDsOfCrash(const char *pUID); /** * Adds one association among alanyzer plugin and its * action and reporter plugins. @@ -159,17 +159,17 @@ vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID); * @param pActionOrReporter A name of an action or reporter plugin. * @param pArgs An arguments for action or reporter plugin. */ -void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, - const std::string& pActionOrReporter, - const std::string& pArgs); +void AddAnalyzerActionOrReporter(const char *pAnalyzer, + const char *pActionOrReporter, + const char *pArgs); /** * Add action and reporter plugins, which are activated * when any crash occurs. * @param pActionOrReporter A name of an action or reporter plugin. * @param pArgs An arguments for action or reporter plugin. */ -void AddActionOrReporter(const std::string& pActionOrReporter, - const std::string& pArgs); +void AddActionOrReporter(const char *pActionOrReporter, + const char *pArgs); #endif /*MIDDLEWARE_H_*/ diff --git a/src/Daemon/abrt.conf b/src/Daemon/abrt.conf index a02cef4..e9845e5 100644 --- a/src/Daemon/abrt.conf +++ b/src/Daemon/abrt.conf @@ -1,32 +1,31 @@ # test conf file. it will be generated in the future -# common abrt settings +# Common abrt settings [ Common ] # With this option set to "yes", # only crashes in signed packages will be analyzed. OpenGPGCheck = no # GPG keys OpenGPGPublicKeys = /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora -# blacklisted packages +# Blacklisted packages BlackList = nspluginwrapper -# enabled plugins -# there has to be exactly one database plugin +# Enabled plugins. There has to be exactly one database plugin EnabledPlugins = SQLite3, CCpp, Logger, Kerneloops, KerneloopsScanner, KerneloopsReporter, Bugzilla, Python # Database Database = SQLite3 -# max size for crash storage [MiB] +# Max size for crash storage [MiB] MaxCrashReportsSize = 1000 -# vector of actions and reporters which are activated immediately after a crash occurs +# Vector of actions and reporters which are activated immediately after a crash occurs # ActionsAndReporters = Mailx("[abrt] new crash was detected") -# reporters association with analyzers +# Reporters association with analyzers [ AnalyzerActionsAndReporters ] Kerneloops = KerneloopsReporter CCpp = Bugzilla, Logger Python = Bugzilla, Logger # CCpp : xorg-x11-apps = RunApp("date", "RunApp") -# repeated calling of Action plugins +# Repeated calling of Action plugins [ Cron ] # h:m - at h:m an action plugin is activated # s - every s seconds is an action plugin activated diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index 1c152e6..4e0dc71 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -188,7 +188,7 @@ int main(int argc, char** argv) dd.SaveText(FILENAME_ANALYZER, "CCpp"); dd.SaveText(FILENAME_EXECUTABLE, executable); dd.SaveText(FILENAME_CMDLINE, cmdline); - dd.SaveText(FILENAME_REASON, std::string("Process was terminated by signal ") + signal_str); + dd.SaveText(FILENAME_REASON, ssprintf("Process was terminated by signal %s", signal_str).c_str()); int len = strlen(path); snprintf(path + len, sizeof(path) - len, "/"FILENAME_COREDUMP); |
