[PATCH] convert concat_path_file() to use C, not C++
by Denys Vlasenko
diff -x '*.po' -d -urpN abrt.4/inc/abrtlib.h abrt.5/inc/abrtlib.h
--- abrt.4/inc/abrtlib.h 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/inc/abrtlib.h 2010-08-23 14:57:07.822400254 +0200
@@ -62,10 +62,13 @@ int vdprintf(int d, const char *format,
#include "abrt_types.h"
#include "xfuncs.h"
#include "logging.h"
+#include "read_write.h"
char* skip_whitespace(const char *s);
char* skip_non_whitespace(const char *s);
+char *concat_path_file(const char *path, const char *filename);
+char *append_to_malloced_string(char *mstr, const char *append);
#ifdef __cplusplus
@@ -87,7 +90,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 {
@@ -217,13 +219,4 @@ static inline std::string ssprintf(const
return res;
}
-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 -x '*.po' -d -urpN abrt.4/lib/plugins/CCpp.cpp abrt.5/lib/plugins/CCpp.cpp
--- abrt.4/lib/plugins/CCpp.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/CCpp.cpp 2010-08-23 15:10:30.000000000 +0200
@@ -460,12 +460,15 @@ static double get_dir_size(const char *d
{
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))
@@ -489,6 +492,7 @@ static double get_dir_size(const char *d
}
}
}
+ free(dname);
}
closedir(dp);
return size;
@@ -583,7 +587,6 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
// 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;
@@ -597,13 +600,14 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
{
/* 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];
@@ -633,6 +637,7 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
exit(1);
}
+ free(backtrace_path);
close(pipeout[1]); /* write side of the pipe */
/* Read the result from abrt-backtrace. */
diff -x '*.po' -d -urpN abrt.4/lib/plugins/FileTransfer.cpp abrt.5/lib/plugins/FileTransfer.cpp
--- abrt.4/lib/plugins/FileTransfer.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/plugins/FileTransfer.cpp 2010-08-23 13:13:13.555150331 +0200
@@ -55,7 +55,7 @@ void CFileTransfer::SendFile(const char
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
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
/* 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
/* 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 -x '*.po' -d -urpN abrt.4/lib/plugins/ReportUploader.cpp abrt.5/lib/plugins/ReportUploader.cpp
--- abrt.4/lib/plugins/ReportUploader.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/plugins/ReportUploader.cpp 2010-08-23 15:12:12.000000000 +0200
@@ -101,7 +101,7 @@ void CReportUploader::SendFile(const cha
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 cha
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 cha
/* 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 cha
/* 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 cha
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
{
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
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
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
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
cmd = ssprintf("rm -rf %s", tmpdir_name);
RunCommand(cmd.c_str());
+ free(tmptar_name);
+ free(outfile_name);
+
return msg;
}
diff -x '*.po' -d -urpN abrt.4/lib/plugins/RHTSupport.cpp abrt.5/lib/plugins/RHTSupport.cpp
--- abrt.4/lib/plugins/RHTSupport.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/RHTSupport.cpp 2010-08-23 13:36:39.393150300 +0200
@@ -202,17 +202,19 @@ string CReporterRHticket::Report(const m
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 -x '*.po' -d -urpN abrt.4/lib/plugins/SOSreport.cpp abrt.5/lib/plugins/SOSreport.cpp
--- abrt.4/lib/plugins/SOSreport.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/SOSreport.cpp 2010-08-23 13:35:26.512150980 +0200
@@ -123,42 +123,44 @@ void CActionSOSreport::Run(const char *p
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 -x '*.po' -d -urpN abrt.4/lib/utils/abrt_rh_support.cpp abrt.5/lib/utils/abrt_rh_support.cpp
--- abrt.4/lib/utils/abrt_rh_support.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/abrt_rh_support.cpp 2010-08-23 14:45:27.304400549 +0200
@@ -190,8 +190,9 @@ reportfile_add_binding_from_namedfile(re
// <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
+ 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* base
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* base
);
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* base
* 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* base
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* base
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* base
);
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* base
//}
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 -x '*.po' -d -urpN abrt.4/lib/utils/append_to_malloced_string.cpp abrt.5/lib/utils/append_to_malloced_string.cpp
--- abrt.4/lib/utils/append_to_malloced_string.cpp 1970-01-01 01:00:00.000000000 +0100
+++ abrt.5/lib/utils/append_to_malloced_string.cpp 2010-08-23 15:00:27.535150194 +0200
@@ -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 -x '*.po' -d -urpN abrt.4/lib/utils/concat_path_file.cpp abrt.5/lib/utils/concat_path_file.cpp
--- abrt.4/lib/utils/concat_path_file.cpp 1970-01-01 01:00:00.000000000 +0100
+++ abrt.5/lib/utils/concat_path_file.cpp 2010-08-23 15:07:47.000000000 +0200
@@ -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 -x '*.po' -d -urpN abrt.4/lib/utils/DebugDump.cpp abrt.5/lib/utils/DebugDump.cpp
--- abrt.4/lib/utils/DebugDump.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/utils/DebugDump.cpp 2010-08-23 14:14:52.743150070 +0200
@@ -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 *pD
{
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* pN
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* pN
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 -x '*.po' -d -urpN abrt.4/lib/utils/dirsize.cpp abrt.5/lib/utils/dirsize.cpp
--- abrt.4/lib/utils/dirsize.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/dirsize.cpp 2010-08-23 13:38:59.521400170 +0200
@@ -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 -x '*.po' -d -urpN abrt.4/lib/utils/hooklib.cpp abrt.5/lib/utils/hooklib.cpp
--- abrt.4/lib/utils/hooklib.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/hooklib.cpp 2010-08-23 13:37:27.584159722 +0200
@@ -127,7 +127,9 @@ void trim_debug_dumps(unsigned setting_M
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 -x '*.po' -d -urpN abrt.4/lib/utils/Makefile.am abrt.5/lib/utils/Makefile.am
--- abrt.4/lib/utils/Makefile.am 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/Makefile.am 2010-08-23 15:00:40.159400743 +0200
@@ -11,6 +11,8 @@ AM_YFLAGS = --verbose
libABRTUtils_la_SOURCES = \
xfuncs.c \
+ concat_path_file.cpp \
+ append_to_malloced_string.cpp \
encbase64.cpp \
read_write.c read_write.h \
logging.c logging.h \
diff -x '*.po' -d -urpN abrt.4/src/daemon/Daemon.cpp abrt.5/src/daemon/Daemon.cpp
--- abrt.4/src/daemon/Daemon.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/src/daemon/Daemon.cpp 2010-08-23 15:15:56.000000000 +0200
@@ -293,9 +293,9 @@ static void FindNewDumps(const char* pPa
{
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* pPa
dirs.push_back(dname);
}
}
+ free(dname);
}
closedir(dp);
@@ -511,23 +512,26 @@ static gboolean handle_inotify_cb(GIOCha
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(GIOCha
{
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,20 +601,24 @@ static gboolean handle_inotify_cb(GIOCha
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;
}
}
catch (CABRTException& e)
{
+ free(fullname);
+ fullname = NULL;
error_msg("%s", e.what());
}
catch (...)
{
+ free(fullname);
free(buf);
throw;
}
+ free(fullname);
} /* while */
free(buf);
13 years, 9 months
Re: [PATCH] Python hook: Reflect ProcessUnpackaged option
by Roman Rakus
On 08/24/2010 12:45 PM, Roman Rakus wrote:
> Signed-off-by: Roman Rakus<rrakus(a)redhat.com>
> ---
> src/hooks/abrt_exception_handler.py.in | 6 ------
> 1 files changed, 0 insertions(+), 6 deletions(-)
>
> diff --git a/src/hooks/abrt_exception_handler.py.in b/src/hooks/abrt_exception_handler.py.in
> index dd6fbae..46642a7 100644
> --- a/src/hooks/abrt_exception_handler.py.in
> +++ b/src/hooks/abrt_exception_handler.py.in
> @@ -91,12 +91,6 @@ def handleMyException((etype, value, tb)):
> syslog.syslog("abrt: detected unhandled Python exception")
> raise Exception
> syslog.syslog("abrt: detected unhandled Python exception in %s" % sys.argv[0])
> - if sys.argv[0][0] != "/":
> - # Relative path - can't reliably determine package
> - # this script belongs to - abort dumping
> - # TODO: check abrt.conf and abort only if
> - # ProcessUnpackaged = no?
> - raise Exception
>
> elist = traceback.format_exception(etype, value, tb)
> tblast = traceback.extract_tb(tb, limit=None)
I'm not sure about the code further. However, when I delete the lines
the python hook works as expected and reflects ProcessUnpackaged option.
I guess, the cleanest way is to really check ProcessUnpackaged option.
RR
13 years, 9 months
fichiers d'adresses email BtoB
by easy-fichiers
Vous avez besoin de trouver de nouveaux clients rapidement et sans un gros investissement ?
Nous sommes spécialisés dans l'email marketing de prospection qui est un média idéal pour cibler des publics qualifiés et toucher vos prospects en bénéficiant d'un très rapide retour sur investissement.
EASY-FICHIERS vous offre la possibilité d'acheter des listes et fichiers d'adresses email professionnelles à tout petit prix !
MAIRIES
59,00 EurosASSURANCES
79,00 EurosCOIFFEURS
39,00 EurosRESTAURANTS
59,00 Euros
EASY-FICHIERS
13 years, 9 months
Impression et routage
by Printing Corporation Ltd
Bonjour,
Dans le cadre de vos besoins en matière d'impression et de routage, nous nous permettons de vous présenter nos prestations.
Notre groupe implanté en Asie et en Europe met à votre disposition plusieurs sites de production pour la réalisation de vos travaux d'impression (livres, catalogues, magazines, brochures, tabloid, dépliants, produits dédiés au marketing direct avec personnalisation + façonnage en ligne).
Parallèlement et pour répondre à la forte demande du marché Européen, nous avons 4 usines de routage en Espagne nous permettant de traiter vos envois pour le marché Français (Destinéo Intégral) et à l'international (25 machines de mise sous film et mise sous papier).
Restant à votre entière disposition pour répondre à l'ensemble de vos demandes.
Contact commercial
Tel : 0820 620 135 - Fax : 01 78 768 729
Demande de devis (production en Europe) & Demande de devis (production en Asie)
Veuillez me retirer de votre liste de diffusion
http://www.printingcorporationltd.com/desinscription.html
13 years, 9 months
[PATCH] get rid of std::string& as parameter
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
lib/plugins/CCpp.cpp | 127 +++++++++++++++++++++++++++++++-------------------
1 files changed, 79 insertions(+), 48 deletions(-)
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp
index 2e8b917..5b93e8c 100644
--- a/lib/plugins/CCpp.cpp
+++ b/lib/plugins/CCpp.cpp
@@ -31,6 +31,7 @@
#include "Polkit.h"
#include "backtrace.h"
#include "CCpp_sha1.h"
+#include "strbuf.h"
using namespace std;
@@ -112,8 +113,12 @@ static string create_hash(const char *pInput)
return hash_str;
}
-/* Returns status. See `man 2 wait` for status information. */
-static int ExecVP(char **pArgs, uid_t uid, int redirect_stderr, string& pOutput)
+/**
+ *
+ * @param[out] status See `man 2 wait` for status information.
+ * @return Malloc'ed string
+ */
+static char* exec_vp(char **args, uid_t uid, int redirect_stderr, int *status)
{
/* Nuke everything which may make setlocale() switch to non-POSIX locale:
* we need to avoid having gdb output in some obscure language.
@@ -136,7 +141,7 @@ static int ExecVP(char **pArgs, uid_t uid, int redirect_stderr, string& pOutput)
VERB1 flags &= ~EXECFLG_QUIET;
int pipeout[2];
- pid_t child = fork_execv_on_steroids(flags, pArgs, pipeout, (char**)unsetenv_vec, /*dir:*/ NULL, uid);
+ pid_t child = fork_execv_on_steroids(flags, args, pipeout, (char**)unsetenv_vec, /*dir:*/ NULL, uid);
/* We use this function to run gdb and unstrip. Bugs in gdb or corrupted
* coredumps were observed to cause gdb to enter infinite loop.
@@ -144,15 +149,16 @@ static int ExecVP(char **pArgs, uid_t uid, int redirect_stderr, string& pOutput)
*/
int t = time(NULL); /* int is enough, no need to use time_t */
int endtime = t + 60;
+
+ struct strbuf *buf_out = strbuf_new();
+
while (1)
{
int timeout = endtime - t;
if (timeout < 0)
{
kill(child, SIGKILL);
- pOutput += "\nTimeout exceeded: 60 second, killing ";
- pOutput += pArgs[0];
- pOutput += "\n";
+ strbuf_append_strf(buf_out, "\nTimeout exceeded: 60 second, killing %s\n", args[0]);
break;
}
@@ -167,20 +173,20 @@ static int ExecVP(char **pArgs, uid_t uid, int redirect_stderr, string& pOutput)
if (r <= 0)
break;
buff[r] = '\0';
- pOutput += buff;
+ strbuf_append_str(buf_out, buff);
t = time(NULL);
}
close(pipeout[0]);
- int status;
- waitpid(child, &status, 0); /* prevent having zombie child process */
+ int st;
+ waitpid(child, &st, 0); /* prevent having zombie child process */
+ if (status)
+ *status = st;
- return status;
+ return strbuf_free_nobuf(buf_out);
}
-static bool GetBacktrace(const char *pDebugDumpDir,
- const char *pDebugInfoDirs,
- string& pBacktrace)
+static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs)
{
update_client(_("Generating backtrace"));
@@ -246,12 +252,10 @@ static bool GetBacktrace(const char *pDebugDumpDir,
* BINARY_FILE if it is newer (to at least avoid gdb complaining).
*/
args[4] = (char*)"-ex";
- string file = ssprintf("file %s", executable.c_str());
- args[5] = (char*)file.c_str();
+ args[5] = xasprintf("file %s", executable.c_str());
args[6] = (char*)"-ex";
- string corefile = ssprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir);
- args[7] = (char*)corefile.c_str();
+ args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir);
args[8] = (char*)"-ex";
/*args[9] = ... see below */
@@ -271,16 +275,19 @@ static bool GetBacktrace(const char *pDebugDumpDir,
/* Get the backtrace, but try to cap its size */
/* Limit bt depth. With no limit, gdb sometimes OOMs the machine */
unsigned bt_depth = 2048;
- const char *thread_apply_all = "thread apply all ";
+ const char *thread_apply_all = "thread apply all";
const char *full = " full";
+ char *bt = NULL;
while (1)
{
- string cmd = ssprintf("%sbacktrace %u%s", thread_apply_all, bt_depth, full);
- args[9] = (char*)cmd.c_str();
- pBacktrace = "";
- ExecVP(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 1, pBacktrace);
- if (bt_depth <= 64 || pBacktrace.size() < 256*1024)
- return true;
+ args[9] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
+ bt = exec_vp(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 1, NULL);
+ if (bt && (bt_depth <= 64 || strlen(bt) < 256*1024))
+ {
+ free(args[9]);
+ break;
+ }
+
bt_depth /= 2;
if (bt_depth <= 64 && thread_apply_all[0] != '\0')
{
@@ -294,7 +301,12 @@ static bool GetBacktrace(const char *pDebugDumpDir,
bt_depth = 256;
full = "";
}
+ free(bt);
+ free(args[9]);
}
+ free(args[5]);
+ free(args[7]);
+ return bt;
}
static void GetIndependentBuildIdPC(const char *unstrip_n_output,
@@ -324,14 +336,14 @@ static void GetIndependentBuildIdPC(const char *unstrip_n_output,
}
}
-static string run_unstrip_n(const char *pDebugDumpDir)
+static char* run_unstrip_n(const char *pDebugDumpDir)
{
string UID;
CDebugDump dd;
if (!dd.Open(pDebugDumpDir))
{
VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir);
- return string("");
+ return NULL;
}
dd.LoadText(CD_UID, UID);
@@ -343,20 +355,19 @@ static string run_unstrip_n(const char *pDebugDumpDir)
args[2] = (char*)"-n";
args[3] = NULL;
- string output;
- ExecVP(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 0, output);
+ char *out = exec_vp(args, xatoi_u(UID.c_str()), /*redirect_stderr:*/ 0, NULL);
free(args[1]);
- return output;
+ return out;
}
/* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668
* It is slated to be in F12/RHEL6.
+ *
+ * returened value must be freed
*/
-static void InstallDebugInfos(const char *pDebugDumpDir,
- const char *debuginfo_dirs,
- string& build_ids)
+static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginfo_dirs)
{
update_client(_("Starting the debuginfo installation"));
@@ -397,7 +408,7 @@ static void InstallDebugInfos(const char *pDebugDumpDir,
{
close(pipeout[0]);
waitpid(child, NULL, 0);
- return;
+ return NULL;
}
/* With 126 debuginfos I've seen lines 9k+ chars long...
@@ -405,15 +416,16 @@ static void InstallDebugInfos(const char *pDebugDumpDir,
* therefore we are using LARGE, but still limited buffer.
*/
char *buff = (char*) xmalloc(64*1024);
+
+ struct strbuf *buf_build_ids = strbuf_new();
+
while (fgets(buff, 64*1024, pipeout_fp))
{
strchrnul(buff, '\n')[0] = '\0';
if (strncmp(buff, "MISSING:", 8) == 0)
{
- build_ids += "Debuginfo absent: ";
- build_ids += buff + 8;
- build_ids += "\n";
+ strbuf_append_strf(buf_build_ids, "Debuginfo absent: %s\n", buff + 8);
continue;
}
@@ -422,6 +434,7 @@ static void InstallDebugInfos(const char *pDebugDumpDir,
{
p++;
}
+
if (*p)
{
VERB1 log("%s", buff);
@@ -443,6 +456,8 @@ static void InstallDebugInfos(const char *pDebugDumpDir,
{
error_msg("%s killed by signal %u", "abrt-debuginfo-install", (int)WTERMSIG(status));
}
+
+ return strbuf_free_nobuf(buf_build_ids);
}
static double get_dir_size(const char *dirname,
@@ -525,9 +540,14 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir)
dd.LoadText(FILENAME_PACKAGE, package);
dd.Close();
- string unstrip_n_output = run_unstrip_n(pDebugDumpDir);
string independentBuildIdPC;
- GetIndependentBuildIdPC(unstrip_n_output.c_str(), independentBuildIdPC);
+ char *unstrip_n_output = run_unstrip_n(pDebugDumpDir);
+ if (unstrip_n_output)
+ GetIndependentBuildIdPC(unstrip_n_output, independentBuildIdPC);
+ else
+ VERB3 error_msg("run_unstrip_n() returns `NULL', broken coredump/eu-unstrip?");
+
+ free(unstrip_n_output);
/* package variable has "firefox-3.5.6-1.fc11[.1]" format */
/* Remove distro suffix and maybe least significant version number */
@@ -703,6 +723,7 @@ static bool DebuginfoCheckPolkit(uid_t uid)
{
perror_msg_and_die("fork");
}
+
if (child_pid == 0)
{
//child
@@ -760,32 +781,42 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
dd.LoadText(CD_UID, UID);
dd.Close(); /* do not keep dir locked longer than needed */
- string build_ids;
+ char *build_ids;
if (m_bInstallDebugInfo && DebuginfoCheckPolkit(xatoi_u(UID.c_str())))
{
if (m_nDebugInfoCacheMB > 0)
trim_debuginfo_cache(m_nDebugInfoCacheMB);
- InstallDebugInfos(pDebugDumpDir, m_sDebugInfoDirs.c_str(), build_ids);
+ build_ids = install_debug_infos(pDebugDumpDir, m_sDebugInfoDirs.c_str());
}
else
VERB1 log(_("Skipping the debuginfo installation"));
/* Create and store backtrace. */
- string backtrace_str;
- GetBacktrace(pDebugDumpDir, m_sDebugInfoDirs.c_str(), backtrace_str);
+ char *backtrace_str = get_backtrace(pDebugDumpDir, m_sDebugInfoDirs.c_str());
+
+ if (!backtrace_str)
+ {
+ backtrace_str = "";
+ VERB3 log("get_backtrace() retruns `NULL', broken core/gdb?");
+ }
+
+ char *bt_build_ids = xasprintf("%s%s", backtrace_str, (build_ids) ? build_ids : "");
+ free(build_ids);
+
if (!dd.Open(pDebugDumpDir))
{
VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir);
return;
}
-
- dd.SaveText(FILENAME_BACKTRACE, (backtrace_str + build_ids).c_str());
+ dd.SaveText(FILENAME_BACKTRACE, bt_build_ids);
+ free(bt_build_ids);
if (m_bMemoryMap)
dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet");
/* Compute and store UUID from the backtrace. */
- char *backtrace_cpy = xstrdup(backtrace_str.c_str());
+ char *backtrace_cpy = xstrdup(backtrace_str);
+
struct backtrace *backtrace = backtrace_parse(backtrace_cpy, false, false);
free(backtrace_cpy);
if (backtrace)
@@ -854,7 +885,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
/* If we write and use a hand-written parser instead of the bison one,
the parser never fails, and it will be possible to get rid of
the independent_backtrace and backtrace_rate_old. */
- struct strbuf *ibt = independent_backtrace(backtrace_str.c_str());
+ struct strbuf *ibt = independent_backtrace(backtrace_str);
strbuf_prepend_str(ibt, executable.c_str());
strbuf_prepend_str(ibt, package.c_str());
dd.SaveText(FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str());
@@ -862,9 +893,9 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
/* Compute and store backtrace rating. */
/* Crash frame is not known so store nothing. */
- dd.SaveText(FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str.c_str())).c_str());
+ dd.SaveText(FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str)).c_str());
}
-
+ free(backtrace_str);
dd.Close();
}
--
1.7.1
13 years, 9 months
[PATCH] massage RHTSupport URL into one which points to human-usabel web UI
by Denys Vlasenko
RHTSupport people asked for this. Run-tested.
--
vda
diff -x '*.po' -d -urpN abrt.2/lib/plugins/RHTSupport.cpp abrt.3/lib/plugins/RHTSupport.cpp
--- abrt.2/lib/plugins/RHTSupport.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.3/lib/plugins/RHTSupport.cpp 2010-08-20 17:26:01.810918212 +0200
@@ -175,7 +175,7 @@ string CReporterRHticket::Report(const m
if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile,
/*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0)
{
- retval = "can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ retval = "error: can't create temporary file in "LOCALSTATEDIR"/run/abrt";
goto ret;
}
@@ -210,7 +210,7 @@ string CReporterRHticket::Report(const m
/*binary */ 1);
if (tar_append_file(tar, (char*)content, (char*)(xml_name.c_str())) != 0)
{
- retval = "can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ retval = "error: can't create temporary file in "LOCALSTATEDIR"/run/abrt";
goto ret;
}
}
@@ -237,7 +237,7 @@ string CReporterRHticket::Report(const m
|| full_write(tar_fd(tar), block, len512) != len512
|| tar_close(tar) != 0
) {
- retval = "can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ retval = "error: can't create temporary file in "LOCALSTATEDIR"/run/abrt";
goto ret;
}
tar = NULL;
diff -x '*.po' -d -urpN abrt.2/lib/utils/abrt_rh_support.cpp abrt.3/lib/utils/abrt_rh_support.cpp
--- abrt.2/lib/utils/abrt_rh_support.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.3/lib/utils/abrt_rh_support.cpp 2010-08-20 17:50:51.268918429 +0200
@@ -359,6 +359,40 @@ make_response(const char* title, const c
//<response><title>Case Created and Report Attached</title><body></body><URL href="http://support-services-devel.gss.redhat.com:8080/Strata/cases/00005129/a...">New Case URL</URL></response>
#endif
+static char* process_location(const char *url)
+{
+ const char *api = strstr(url, "://api.");
+ const char *after_api;
+ if (api)
+ {
+ after_api = api + strlen("://api.");
+ api += 3; // skip "://"
+ } else {
+ after_api = api = url;
+ }
+
+ const char *rs = strstr(after_api, "/rs/");
+ const char *after_rs;
+ const char *repl_rs;
+ if (rs)
+ {
+ after_rs = rs + strlen("/rs");
+ rs += 1; // skip "/"
+ repl_rs = "support";
+ } else {
+ after_rs = rs = after_api;
+ repl_rs = "";
+ }
+
+ char *r = xasprintf("%.*s" "%.*s" "%s" "%s",
+ (int)(api - url), url, // the part from start to "api."
+ (int)(rs - after_api), after_api, // the part from end of "://api." to start of "rs/"
+ repl_rs, // replacement "support"
+ after_rs // part after "/rs"
+ );
+ return r;
+}
+
char*
send_report_to_new_case(const char* baseURL,
const char* username,
@@ -479,14 +513,18 @@ send_report_to_new_case(const char* base
else /* only body exists */
errmsg = atch_state->body;
}
- /* Note: to prevent URL misparsing, make sure to delimit
- * case_location only using spaces */
- retval = xasprintf("Case created: %s but report attachment failed (HTTP code %d)%s%s",
- case_location,
- atch_state->http_resp_code,
- errmsg ? ": " : "",
- errmsg ? errmsg : ""
- );
+ {
+ /* Note: to prevent URL misparsing, make sure to delimit
+ * case_location only using spaces */
+ char *processed_loc = process_location(case_location);
+ retval = xasprintf("Case created: %s but report attachment failed (HTTP code %d)%s%s",
+ processed_loc,
+ atch_state->http_resp_code,
+ errmsg ? ": " : "",
+ errmsg ? errmsg : ""
+ );
+ free(processed_loc);
+ }
break;
case 200:
@@ -501,7 +539,9 @@ send_report_to_new_case(const char* base
// case_state->body,
// atch_state->body);
//}
- retval = xasprintf("Case created: %s", /*body,*/ case_location);
+ char *processed_loc = process_location(case_location);
+ retval = xasprintf("Case created: %s", /*body,*/ processed_loc);
+ free(processed_loc);
} /* switch (attach HTTP code) */
free_abrt_post_state(atch_state);
13 years, 9 months