summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--inc/abrtlib.h16
-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
-rw-r--r--lib/utils/DebugDump.cpp31
-rw-r--r--lib/utils/Makefile.am2
-rw-r--r--lib/utils/abrt_rh_support.cpp38
-rw-r--r--lib/utils/append_to_malloced_string.c27
-rw-r--r--lib/utils/concat_path_file.c25
-rw-r--r--lib/utils/dirsize.cpp20
-rw-r--r--lib/utils/hooklib.cpp4
-rw-r--r--src/daemon/Daemon.cpp28
14 files changed, 200 insertions, 97 deletions
diff --git a/inc/abrtlib.h b/inc/abrtlib.h
index f38374e3..a111ce71 100644
--- a/inc/abrtlib.h
+++ b/inc/abrtlib.h
@@ -64,6 +64,7 @@ int vdprintf(int d, const char *format, va_list ap);
#include "abrt_types.h"
#include "xfuncs.h"
#include "logging.h"
+#include "read_write.h"
char* skip_whitespace(const char *s);
@@ -73,9 +74,10 @@ char* skip_non_whitespace(const char *s);
#ifdef __cplusplus
extern "C" {
#endif
-
int prefixcmp(const char *str, const char *prefix);
int suffixcmp(const char *str, const char *suffix);
+char *concat_path_file(const char *path, const char *filename);
+char *append_to_malloced_string(char *mstr, const char *append);
#ifdef __cplusplus
}
#endif
@@ -89,7 +91,6 @@ int xatoi(const char *numstr);
* dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */
int xatoi_u(const char *numstr);
-#include "read_write.h"
/* copyfd_XX print read/write errors and return -1 if they occur */
enum {
@@ -204,7 +205,6 @@ std::string to_string(T x)
void parse_args(const char *psArgs, vector_string_t& pArgs, int quote = -1);
void parse_release(const char *pRelease, char **product, char **version);
-#endif
// TODO: npajkovs: full rewrite ssprintf -> xasprintf
static inline std::string ssprintf(const char *format, ...)
@@ -220,14 +220,6 @@ static inline std::string ssprintf(const char *format, ...)
free(string_ptr);
return res;
}
+#endif
-static inline std::string concat_path_file(const char *path, const char *filename)
-{
- char *lc;
-
- while (*filename == '/')
- filename++;
- lc = last_char_is(path, '/');
- return ssprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
-}
#endif
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
}
diff --git a/lib/utils/DebugDump.cpp b/lib/utils/DebugDump.cpp
index 9bc0ab73..6858fe36 100644
--- a/lib/utils/DebugDump.cpp
+++ b/lib/utils/DebugDump.cpp
@@ -109,8 +109,10 @@ bool CDebugDump::Open(const char *pDir)
bool CDebugDump::Exist(const char* pPath)
{
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pPath);
- return ExistFileDir(fullPath.c_str());
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pPath);
+ bool r = ExistFileDir(full_path);
+ free(full_path);
+ return r;
}
static bool GetAndSetLock(const char* pLockFile, const char* pPID)
@@ -362,17 +364,19 @@ static bool DeleteFileDir(const char *pDir)
{
if (dot_or_dotdot(dent->d_name))
continue;
- std::string fullPath = concat_path_file(pDir, dent->d_name);
- if (unlink(fullPath.c_str()) == -1)
+ char *full_path = concat_path_file(pDir, dent->d_name);
+ if (unlink(full_path) == -1)
{
if (errno != EISDIR)
{
closedir(dir);
- error_msg("Can't remove dir '%s'", fullPath.c_str());
+ error_msg("Can't remove dir '%s'", full_path);
+ free(full_path);
return false;
}
- DeleteFileDir(fullPath.c_str());
+ DeleteFileDir(full_path);
}
+ free(full_path);
}
closedir(dir);
if (rmdir(pDir) == -1)
@@ -459,8 +463,9 @@ void CDebugDump::LoadText(const char* pName, std::string& pData)
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- LoadTextFile(fullPath.c_str(), pData);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ LoadTextFile(full_path, pData);
+ free(full_path);
}
void CDebugDump::SaveText(const char* pName, const char* pData)
@@ -468,16 +473,18 @@ void CDebugDump::SaveText(const char* pName, const char* pData)
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- SaveBinaryFile(fullPath.c_str(), pData, strlen(pData), m_uid, m_gid);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ SaveBinaryFile(full_path, pData, strlen(pData), m_uid, m_gid);
+ free(full_path);
}
void CDebugDump::SaveBinary(const char* pName, const char* pData, unsigned pSize)
{
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- SaveBinaryFile(fullPath.c_str(), pData, pSize, m_uid, m_gid);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ SaveBinaryFile(full_path, pData, pSize, m_uid, m_gid);
+ free(full_path);
}
bool CDebugDump::InitGetNextFile()
diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am
index 04211a7c..d182e1a0 100644
--- a/lib/utils/Makefile.am
+++ b/lib/utils/Makefile.am
@@ -11,6 +11,8 @@ AM_YFLAGS = --verbose
libABRTUtils_la_SOURCES = \
xfuncs.c \
+ concat_path_file.c \
+ append_to_malloced_string.c \
encbase64.cpp \
read_write.c read_write.h \
logging.c logging.h \
diff --git a/lib/utils/abrt_rh_support.cpp b/lib/utils/abrt_rh_support.cpp
index 7e804f9f..4a1d80f0 100644
--- a/lib/utils/abrt_rh_support.cpp
+++ b/lib/utils/abrt_rh_support.cpp
@@ -190,8 +190,9 @@ reportfile_add_binding_from_namedfile(reportfile_t* file,
// <binding name=NAME fileName=FILENAME type=text/binary...
internal_reportfile_start_binding(file, binding_name, isbinary, recorded_filename);
// ... href=content/NAME>
- string href_name = concat_path_file("content", binding_name);
- xxmlTextWriterWriteAttribute(file->writer, "href", href_name.c_str());
+ char *href_name = concat_path_file("content", binding_name);
+ xxmlTextWriterWriteAttribute(file->writer, "href", href_name);
+ free(href_name);
}
//
@@ -222,7 +223,7 @@ reportfile_free(reportfile_t* file)
char*
post_signature(const char* baseURL, bool ssl_verify, const char* signature)
{
- string URL = concat_path_file(baseURL, "/signatures");
+ char *URL = concat_path_file(baseURL, "/signatures");
abrt_post_state *state = new_abrt_post_state(0
+ ABRT_POST_WANT_HEADERS
@@ -230,7 +231,8 @@ post_signature(const char* baseURL, bool ssl_verify, const char* signature)
+ ABRT_POST_WANT_ERROR_MSG
+ (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0)
);
- int http_resp_code = abrt_post_string(state, URL.c_str(), "application/xml", signature);
+ int http_resp_code = abrt_post_string(state, URL, "application/xml", signature);
+ free(URL);
char *retval;
const char *strata_msg;
@@ -369,7 +371,7 @@ send_report_to_new_case(const char* baseURL,
const char* component,
const char* report_file_name)
{
- string case_url = concat_path_file(baseURL, "/cases");
+ char *case_url = concat_path_file(baseURL, "/cases");
char *case_data = make_case_data(summary, description,
"Red Hat Enterprise Linux", "6.0",
@@ -390,14 +392,16 @@ send_report_to_new_case(const char* baseURL,
);
case_state->username = username;
case_state->password = password;
- abrt_post_string(case_state, case_url.c_str(), "application/xml", case_data);
+ abrt_post_string(case_state, case_url, "application/xml", case_data);
char *case_location = find_header_in_abrt_post_state(case_state, "Location:");
switch (case_state->http_resp_code)
{
case 305: /* "305 Use Proxy" */
- if (++redirect_count < 10 && case_location) {
- case_url = case_location;
+ if (++redirect_count < 10 && case_location)
+ {
+ free(case_url);
+ case_url = xstrdup(case_location);
free_abrt_post_state(case_state);
goto redirect_case;
}
@@ -408,7 +412,7 @@ send_report_to_new_case(const char* baseURL,
* instead of returning html-encoded body, we show short concise message,
* and show offending URL (typos in which is a typical cause) */
retval = xasprintf("error in case creation, "
- "HTTP code: 404 (Not found), URL:'%s'", case_url.c_str());
+ "HTTP code: 404 (Not found), URL:'%s'", case_url);
break;
default:
@@ -431,7 +435,7 @@ send_report_to_new_case(const char* baseURL,
break;
case 200:
- case 201:
+ case 201: {
if (!case_location) {
/* Case Creation returned valid code, but no location */
retval = xasprintf("error in case creation: no Location URL, HTTP code: %d",
@@ -439,7 +443,7 @@ send_report_to_new_case(const char* baseURL,
break;
}
- string atch_url = concat_path_file(case_location, "/attachments");
+ char *atch_url = concat_path_file(case_location, "/attachments");
abrt_post_state *atch_state;
redirect_attach:
atch_state = new_abrt_post_state(0
@@ -450,14 +454,16 @@ send_report_to_new_case(const char* baseURL,
);
atch_state->username = username;
atch_state->password = password;
- abrt_post_file_as_form(atch_state, atch_url.c_str(), "application/binary", report_file_name);
+ abrt_post_file_as_form(atch_state, atch_url, "application/binary", report_file_name);
char *atch_location = find_header_in_abrt_post_state(atch_state, "Location:");
switch (atch_state->http_resp_code)
{
case 305: /* "305 Use Proxy" */
- if (++redirect_count < 10 && atch_location) {
- atch_url = atch_location;
+ if (++redirect_count < 10 && atch_location)
+ {
+ free(atch_url);
+ atch_url = xstrdup(atch_location);
free_abrt_post_state(atch_state);
goto redirect_attach;
}
@@ -503,11 +509,15 @@ send_report_to_new_case(const char* baseURL,
//}
retval = xasprintf("Case created: %s", /*body,*/ case_location);
} /* switch (attach HTTP code) */
+
free_abrt_post_state(atch_state);
+ free(atch_url);
+ } /* case 200/201 */
} /* switch (case HTTP code) */
free_abrt_post_state(case_state);
free(allocated);
+ free(case_url);
return retval;
}
diff --git a/lib/utils/append_to_malloced_string.c b/lib/utils/append_to_malloced_string.c
new file mode 100644
index 00000000..430cef0b
--- /dev/null
+++ b/lib/utils/append_to_malloced_string.c
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2010 ABRT team
+ Copyright (C) 2010 RedHat Inc
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "abrtlib.h"
+
+char *append_to_malloced_string(char *mstr, const char *append)
+{
+ unsigned mlen = strlen(mstr);
+ mstr = (char*) xrealloc(mstr, mlen + strlen(append) + 1);
+ strcpy(mstr + mlen, append);
+ return mstr;
+}
diff --git a/lib/utils/concat_path_file.c b/lib/utils/concat_path_file.c
new file mode 100644
index 00000000..4c946628
--- /dev/null
+++ b/lib/utils/concat_path_file.c
@@ -0,0 +1,25 @@
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2001 Erik Andersen
+ *
+ * Licensed under GPLv2 or later.
+ */
+
+/* Concatenate path and filename to new allocated buffer.
+ * Add '/' only as needed (no duplicate // are produced).
+ * If path is NULL, it is assumed to be "/".
+ * filename should not be NULL.
+ */
+
+#include "abrtlib.h"
+
+char *concat_path_file(const char *path, const char *filename)
+{
+ if (!path)
+ path = "";
+ const char *end = path + strlen(path);
+ while (*filename == '/')
+ filename++;
+ return xasprintf("%s%s%s", path, (end != path && end[-1] != '/' ? "/" : ""), filename);
+}
diff --git a/lib/utils/dirsize.cpp b/lib/utils/dirsize.cpp
index 739b6b73..79f429e3 100644
--- a/lib/utils/dirsize.cpp
+++ b/lib/utils/dirsize.cpp
@@ -33,17 +33,21 @@ double get_dirsize(const char *pPath)
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(pPath, ep->d_name);
- if (lstat(dname.c_str(), &statbuf) != 0)
+ char *dname = concat_path_file(pPath, ep->d_name);
+ if (lstat(dname, &statbuf) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(statbuf.st_mode))
{
- size += get_dirsize(dname.c_str());
+ size += get_dirsize(dname);
}
else if (S_ISREG(statbuf.st_mode))
{
size += statbuf.st_size;
}
+ free(dname);
}
closedir(dp);
return size;
@@ -66,12 +70,15 @@ double get_dirsize_find_largest_dir(
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(pPath, ep->d_name);
- if (lstat(dname.c_str(), &statbuf) != 0)
+ char *dname = concat_path_file(pPath, ep->d_name);
+ if (lstat(dname, &statbuf) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(statbuf.st_mode))
{
- double sz = get_dirsize(dname.c_str());
+ double sz = get_dirsize(dname);
size += sz;
if (worst_dir && (!excluded || strcmp(excluded, ep->d_name) != 0))
@@ -94,6 +101,7 @@ double get_dirsize_find_largest_dir(
{
size += statbuf.st_size;
}
+ free(dname);
}
closedir(dp);
return size;
diff --git a/lib/utils/hooklib.cpp b/lib/utils/hooklib.cpp
index 68970661..7c794ef5 100644
--- a/lib/utils/hooklib.cpp
+++ b/lib/utils/hooklib.cpp
@@ -127,7 +127,9 @@ void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_
if (dirsize / (1024*1024) < setting_MaxCrashReportsSize || worst_dir == "")
break;
log("size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, setting_MaxCrashReportsSize, worst_dir.c_str());
- delete_debug_dump_dir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str());
+ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str());
+ delete_debug_dump_dir(d);
+ free(d);
worst_dir = "";
}
}
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index a568b477..6e20f6ae 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -293,9 +293,9 @@ static void FindNewDumps(const char* pPath)
{
if (dot_or_dotdot(ep->d_name))
continue; /* skip "." and ".." */
- std::string dname = concat_path_file(pPath, ep->d_name);
+ char *dname = concat_path_file(pPath, ep->d_name);
struct stat stats;
- if (lstat(dname.c_str(), &stats) == 0)
+ if (lstat(dname, &stats) == 0)
{
if (S_ISDIR(stats.st_mode))
{
@@ -303,6 +303,7 @@ static void FindNewDumps(const char* pPath)
dirs.push_back(dname);
}
}
+ free(dname);
}
closedir(dp);
@@ -511,23 +512,26 @@ 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(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf."));
/* deletes both directory and DB record */
- DeleteDebugDump_by_dir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str());
+ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str());
+ DeleteDebugDump_by_dir(d);
+ free(d);
worst_dir = "";
}
}
+ char *fullname = NULL;
try
{
- std::string fullname = concat_path_file(DEBUG_DUMPS_DIR, name);
+ fullname = concat_path_file(DEBUG_DUMPS_DIR, name);
/* Note: SaveDebugDump does not save crashinfo, it _fetches_ crashinfo */
map_crash_data_t crashinfo;
- mw_result_t res = SaveDebugDump(fullname.c_str(), crashinfo);
+ mw_result_t res = SaveDebugDump(fullname, crashinfo);
switch (res)
{
case MW_OK:
- log("New crash %s, processing", fullname.c_str());
+ log("New crash %s, processing", fullname);
/* Run automatic actions and reporters on it (if we have them configured) */
- RunActionsAndReporters(fullname.c_str());
+ RunActionsAndReporters(fullname);
/* Fall through */
case MW_REPORTED: /* already reported dup */
@@ -537,9 +541,9 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
{
const char *first = get_crash_data_item_content(crashinfo, CD_DUMPDIR).c_str();
log("Deleting crash %s (dup of %s), sending dbus signal",
- strrchr(fullname.c_str(), '/') + 1,
+ strrchr(fullname, '/') + 1,
strrchr(first, '/') + 1);
- delete_debug_dump_dir(fullname.c_str());
+ delete_debug_dump_dir(fullname);
}
#define fullname fullname_should_not_be_used_here
@@ -597,8 +601,8 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
case MW_GPG_ERROR:
case MW_FILE_ERROR:
default:
- log("Corrupted or bad crash %s (res:%d), deleting", fullname.c_str(), (int)res);
- delete_debug_dump_dir(fullname.c_str());
+ log("Corrupted or bad crash %s (res:%d), deleting", fullname, (int)res);
+ delete_debug_dump_dir(fullname);
break;
}
}
@@ -608,9 +612,11 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
}
catch (...)
{
+ free(fullname);
free(buf);
throw;
}
+ free(fullname);
} /* while */
free(buf);