summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-08-24 13:07:44 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-08-24 13:07:44 +0200
commit5cc439c2c24859accf8a94d8a91879ad6d967ea4 (patch)
tree1915379ff53eeb579ed92d889b7e6d873df1144a /lib/plugins
parentbe100446ebd3b1c8f6bb3ed450867c9dcbc625e8 (diff)
downloadabrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.tar.gz
abrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.tar.xz
abrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.zip
concat_path_file: make it a C function, not C++
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/CCpp.cpp15
-rw-r--r--lib/plugins/FileTransfer.cpp6
-rw-r--r--lib/plugins/RHTSupport.cpp8
-rw-r--r--lib/plugins/ReportUploader.cpp57
-rw-r--r--lib/plugins/SOSreport.cpp20
5 files changed, 65 insertions, 41 deletions
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp
index 5b93e8c6..01866d62 100644
--- a/lib/plugins/CCpp.cpp
+++ b/lib/plugins/CCpp.cpp
@@ -475,12 +475,15 @@ static double get_dir_size(const char *dirname,
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(dirname, ep->d_name);
- if (lstat(dname.c_str(), &stats) != 0)
+ char *dname = concat_path_file(dirname, ep->d_name);
+ if (lstat(dname, &stats) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(stats.st_mode))
{
- double sz = get_dir_size(dname.c_str(), worst_file, maxsz);
+ double sz = get_dir_size(dname, worst_file, maxsz);
size += sz;
}
else if (S_ISREG(stats.st_mode))
@@ -504,6 +507,7 @@ static double get_dir_size(const char *dirname,
}
}
}
+ free(dname);
}
closedir(dp);
return size;
@@ -603,7 +607,6 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
// This whole block should be deleted for Fedora 14.
log(_("Getting global universal unique identification..."));
- string backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE);
string executable;
string package;
string uid_str;
@@ -617,13 +620,14 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
{
/* Run abrt-backtrace to get independent backtrace suitable
to UUID calculation. */
+ char *backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE);
char *args[7];
args[0] = (char*)"abrt-backtrace";
args[1] = (char*)"--single-thread";
args[2] = (char*)"--remove-exit-handlers";
args[3] = (char*)"--frame-depth=5";
args[4] = (char*)"--remove-noncrash-frames";
- args[5] = (char*)backtrace_path.c_str();
+ args[5] = backtrace_path;
args[6] = NULL;
int pipeout[2];
@@ -653,6 +657,7 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
exit(1);
}
+ free(backtrace_path);
close(pipeout[1]); /* write side of the pipe */
/* Read the result from abrt-backtrace. */
diff --git a/lib/plugins/FileTransfer.cpp b/lib/plugins/FileTransfer.cpp
index cf7cf1f3..05820d05 100644
--- a/lib/plugins/FileTransfer.cpp
+++ b/lib/plugins/FileTransfer.cpp
@@ -55,7 +55,7 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename)
update_client(_("Sending archive %s to %s"), pFilename, pURL);
- string wholeURL = concat_path_file(pURL, strrchr(pFilename, '/') ? : pFilename);
+ char *whole_url = concat_path_file(pURL, strrchr(pFilename, '/') ? : pFilename);
int count = m_nRetryCount;
while (1)
@@ -63,6 +63,7 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename)
FILE *f = fopen(pFilename, "r");
if (!f)
{
+ free(whole_url);
throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename);
}
@@ -73,7 +74,7 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename)
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
/* FILE handle: passed to the default callback, it will fread() it */
curl_easy_setopt(curl, CURLOPT_READDATA, f);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size);
@@ -88,6 +89,7 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename)
/* retry the upload if not succesful, wait a bit before next try */
sleep(m_nRetryDelay);
}
+ free(whole_url);
}
static void create_tar(const char *archive_name, const char *directory)
diff --git a/lib/plugins/RHTSupport.cpp b/lib/plugins/RHTSupport.cpp
index d13ff467..26582048 100644
--- a/lib/plugins/RHTSupport.cpp
+++ b/lib/plugins/RHTSupport.cpp
@@ -202,17 +202,19 @@ string CReporterRHticket::Report(const map_crash_data_t& pCrashData,
basename++;
else
basename = content;
- string xml_name = concat_path_file("content", basename);
+ char *xml_name = concat_path_file("content", basename);
reportfile_add_binding_from_namedfile(file,
/*on_disk_filename */ content,
/*binding_name */ it->first.c_str(),
- /*recorded_filename*/ xml_name.c_str(),
+ /*recorded_filename*/ xml_name,
/*binary */ 1);
- if (tar_append_file(tar, (char*)content, (char*)(xml_name.c_str())) != 0)
+ if (tar_append_file(tar, (char*)content, xml_name) != 0)
{
retval = "can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ free(xml_name);
goto ret;
}
+ free(xml_name);
}
}
}
diff --git a/lib/plugins/ReportUploader.cpp b/lib/plugins/ReportUploader.cpp
index eb01691c..7c31d516 100644
--- a/lib/plugins/ReportUploader.cpp
+++ b/lib/plugins/ReportUploader.cpp
@@ -101,7 +101,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
update_client(_("Sending archive %s to %s"), pFilename, pURL);
const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1;
- string wholeURL = concat_path_file(pURL, base);
+ char *whole_url = concat_path_file(pURL, base);
int count = retry_count;
int result;
while (1)
@@ -109,6 +109,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
FILE* f = fopen(pFilename, "r");
if (!f)
{
+ free(whole_url);
throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename);
}
struct stat buf;
@@ -117,7 +118,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
curl_easy_setopt(curl, CURLOPT_READDATA, f);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size);
/* everything is done here; result 0 means success */
@@ -134,6 +135,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
/* retry the upload if not succesful, wait a bit before next try */
sleep(retry_delay);
}
+ free(whole_url);
if (count <= 0 && result != 0)
{
@@ -144,12 +146,15 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
static void write_str_to_file(const char *str, const char *path, const char *fname)
{
- string ofile_name = concat_path_file(path, fname);
- FILE *ofile = fopen(ofile_name.c_str(), "w");
+ char *ofile_name = concat_path_file(path, fname);
+ FILE *ofile = fopen(ofile_name, "w");
if (!ofile)
{
- throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", ofile_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't open '%s'", ofile_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
fputs(str, ofile);
fclose(ofile);
}
@@ -212,11 +217,13 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
{
throw CABRTException(EXCEP_PLUGIN, "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(), 0700))
+ char *tmptar_name = concat_path_file(tmpdir_name, file_name.c_str());
+ if (mkdir(tmptar_name, 0700))
{
- throw CABRTException(EXCEP_PLUGIN, "Can't mkdir '%s'", tmptar_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't mkdir '%s'", tmptar_name);
+ free(tmptar_name);
+ throw e;
}
// Copy each entry into the tarball root.
@@ -230,36 +237,39 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
const char *content = it->second[CD_CONTENT].c_str();
if (it->second[CD_TYPE] == CD_TXT)
{
- write_str_to_file(content, tmptar_name.c_str(), it->first.c_str());
+ write_str_to_file(content, tmptar_name, it->first.c_str());
}
else if (it->second[CD_TYPE] == CD_BIN)
{
- string ofile_name = concat_path_file(tmptar_name.c_str(), it->first.c_str());
- if (copy_file(content, ofile_name.c_str(), 0644) < 0)
+ char *ofile_name = concat_path_file(tmptar_name, it->first.c_str());
+ if (copy_file(content, ofile_name, 0644) < 0)
{
- throw CABRTException(EXCEP_PLUGIN,
+ CABRTException e(EXCEP_PLUGIN,
"Can't copy '%s' to '%s'",
- content,
- ofile_name.c_str()
+ content, ofile_name
);
+ free(tmptar_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
}
}
// add ticket_name and customer name to tarball
if (have_ticket_name)
{
- write_str_to_file(ticket_name.c_str(), tmptar_name.c_str(), "TICKET");
+ write_str_to_file(ticket_name.c_str(), tmptar_name, "TICKET");
}
if (customer_name != "")
{
- write_str_to_file(customer_name.c_str(), tmptar_name.c_str(), "CUSTOMER");
+ write_str_to_file(customer_name.c_str(), tmptar_name, "CUSTOMER");
}
// Create the compressed tarball
string outfile_basename = file_name + ".tar.gz";
- 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());
+ char *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, file_name.c_str());
RunCommand(cmd.c_str());
// encrypt if requested
@@ -270,9 +280,9 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
string infile_name = outfile_name;
outfile_basename += ".aes";
- outfile_name += ".aes";
+ outfile_name = append_to_malloced_string(outfile_name, ".aes");
- cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name.c_str());
+ cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name);
WriteCommand(cmd.c_str(), key.c_str());
}
@@ -284,11 +294,11 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
if (do_upload)
{
// FIXME: SendFile isn't working sometime (scp)
- SendFile(upload_url.c_str(), outfile_name.c_str(), retry_count, retry_delay);
+ SendFile(upload_url.c_str(), outfile_name, retry_count, retry_delay);
}
else
{
- cmd = ssprintf("cp %s /tmp/", outfile_name.c_str());
+ cmd = ssprintf("cp %s /tmp/", outfile_name);
RunCommand(cmd.c_str());
}
@@ -343,6 +353,9 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
cmd = ssprintf("rm -rf %s", tmpdir_name);
RunCommand(cmd.c_str());
+ free(tmptar_name);
+ free(outfile_name);
+
return msg;
}
diff --git a/lib/plugins/SOSreport.cpp b/lib/plugins/SOSreport.cpp
index df254ec3..a3e7f612 100644
--- a/lib/plugins/SOSreport.cpp
+++ b/lib/plugins/SOSreport.cpp
@@ -123,42 +123,44 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs, int force)
throw CABRTException(EXCEP_PLUGIN, "Can't find filename in sosreport output");
}
- string sosreport_dd_filename = concat_path_file(pActionDir, "sosreport.tar");
+ char *sosreport_dd_filename = concat_path_file(pActionDir, "sosreport.tar");
char *ext = strrchr(sosreport_filename, '.');
if (ext && strcmp(ext, ".tar") != 0)
{
// Assuming it's .bz2, .gz or some such
- sosreport_dd_filename += ext;
+ sosreport_dd_filename = append_to_malloced_string(sosreport_dd_filename, ext);
}
+
CDebugDump dd;
if (!dd.Open(pActionDir))
{
VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir);
+ free(sosreport_filename);
+ free(sosreport_dd_filename);
return;
}
//Not useful: dd.SaveText("sosreportoutput", output);
- off_t sz = copy_file(sosreport_filename, sosreport_dd_filename.c_str(), 0644);
+ off_t sz = copy_file(sosreport_filename, sosreport_dd_filename, 0644);
// don't want to leave sosreport-XXXX.tar.bz2 in /tmp
unlink(sosreport_filename);
// sosreport-XXXX.tar.bz2.md5 too
- unsigned len = strlen(sosreport_filename);
- sosreport_filename = (char*)xrealloc(sosreport_filename, len + sizeof(".md5")-1 + 1);
- strcpy(sosreport_filename + len, ".md5");
+ sosreport_filename = append_to_malloced_string(sosreport_filename, ".md5");
unlink(sosreport_filename);
+ dd.Close();
if (sz < 0)
{
- dd.Close();
CABRTException e(EXCEP_PLUGIN,
"Can't copy '%s' to '%s'",
- sosreport_filename,
- sosreport_dd_filename.c_str()
+ sosreport_filename, sosreport_dd_filename
);
free(sosreport_filename);
+ free(sosreport_dd_filename);
throw e;
}
free(sosreport_filename);
+ free(sosreport_dd_filename);
#endif
}