summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-11-06 15:11:55 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-11-06 15:11:55 +0100
commit3a62ede25114452938acb8e1a67006633b139efc (patch)
treed3a291e5dac5d7ddf14bae4a097ff5b298b71aa5 /lib
parentfc571a9ac7aaa8802d3e8aacf9aefac12ca3c81c (diff)
parent80975b02ec1a2e8dfc6f7ce21e47cf71b16b5a6e (diff)
downloadabrt-3a62ede25114452938acb8e1a67006633b139efc.tar.gz
abrt-3a62ede25114452938acb8e1a67006633b139efc.tar.xz
abrt-3a62ede25114452938acb8e1a67006633b139efc.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib')
-rw-r--r--lib/Plugins/CCpp.cpp31
-rw-r--r--lib/Plugins/CCpp.h8
-rw-r--r--lib/Plugins/FileTransfer.cpp133
-rw-r--r--lib/Plugins/FileTransfer.h10
-rw-r--r--lib/Plugins/Kerneloops.conf2
-rw-r--r--lib/Plugins/Kerneloops.cpp14
-rw-r--r--lib/Plugins/Kerneloops.h11
-rw-r--r--lib/Plugins/KerneloopsReporter.cpp15
-rw-r--r--lib/Plugins/KerneloopsScanner.cpp30
-rw-r--r--lib/Plugins/KerneloopsScanner.h5
-rw-r--r--lib/Plugins/Makefile.am62
-rw-r--r--lib/Plugins/Python.cpp6
-rw-r--r--lib/Plugins/Python.h7
-rw-r--r--lib/Plugins/RunApp.cpp31
-rw-r--r--lib/Plugins/RunApp.h6
-rw-r--r--lib/Plugins/SOSreport.cpp89
-rw-r--r--lib/Plugins/SOSreport.h15
-rw-r--r--lib/Plugins/SQLite3.cpp2
-rw-r--r--lib/Plugins/TicketUploader.cpp357
-rw-r--r--lib/Plugins/TicketUploader.h38
-rw-r--r--lib/Utils/Action.h6
-rw-r--r--lib/Utils/Analyzer.h6
-rw-r--r--lib/Utils/CommLayerInner.cpp4
-rw-r--r--lib/Utils/DebugDump.cpp170
-rw-r--r--lib/Utils/DebugDump.h10
-rw-r--r--lib/Utils/Observer.h4
-rw-r--r--lib/Utils/copyfd.cpp22
-rw-r--r--lib/Utils/xfuncs.cpp13
28 files changed, 468 insertions, 639 deletions
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;
+}