[PATCH] reporter-ureport: save reported_to from server response
by Michal Toman
---
src/plugins/ureport.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 96c7878..d24d8e7 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -58,6 +58,7 @@ struct ureport_server_response {
const char *value;
const char *message;
const char *bthash;
+ json_object *reported_to_list;
};
/*
@@ -92,6 +93,10 @@ static bool ureport_server_parse_json(json_object *json, struct ureport_server_r
if (bthash)
out_response->bthash = json_object_get_string(bthash);
+ json_object *reported_to_list = json_object_object_get(json, "reported_to");
+ if (reported_to_list)
+ out_response->reported_to_list = reported_to_list;
+
return true;
}
@@ -117,6 +122,64 @@ static bool check_response_statuscode(post_state_t *post_state,
return true;
}
+/* reported_to json element should be a list of structures
+{ "reporter": "Bugzilla",
+ "type": "url",
+ "value": "https://bugzilla.redhat.com/show_bug.cgi?id=XYZ" } */
+static void add_reported_to_from_json_list(struct dump_dir *dd, struct json_object *list)
+{
+ int i;
+ json_object *list_elem, *struct_elem;
+ const char *reporter, *value, *type;
+ char *reported_to_line, *prefix;
+
+ for (i = 0; i < json_object_array_length(list); ++i)
+ {
+ prefix = NULL;
+ list_elem = json_object_array_get_idx(list, i);
+ if (!list_elem)
+ continue;
+
+ struct_elem = json_object_object_get(list_elem, "reporter");
+ if (!struct_elem)
+ continue;
+
+ reporter = json_object_get_string(struct_elem);
+ if (!reporter)
+ continue;
+
+ struct_elem = json_object_object_get(list_elem, "value");
+ if (!struct_elem)
+ continue;
+
+ value = json_object_get_string(struct_elem);
+ if (!value)
+ continue;
+
+ struct_elem = json_object_object_get(list_elem, "type");
+ if (!struct_elem)
+ continue;
+
+ type = json_object_get_string(struct_elem);
+ if (type)
+ {
+ if (strcasecmp("url", type) == 0)
+ prefix = xstrdup("URL=");
+ else if (strcasecmp("bthash", type) == 0)
+ prefix = xstrdup("BTHASH=");
+ }
+
+ if (!prefix)
+ prefix = xstrdup("");
+
+ reported_to_line = xasprintf("%s: %s%s", reporter, prefix, value);
+ free(prefix);
+
+ add_reported_to(dd, reported_to_line);
+ free(reported_to_line);
+ }
+}
+
int main(int argc, char **argv)
{
abrt_init(argv);
@@ -276,6 +339,10 @@ int main(int argc, char **argv)
char *msg = xasprintf("uReport: BTHASH=%s", response.bthash);
add_reported_to(dd, msg);
free(msg);
+
+ if (response.reported_to_list)
+ add_reported_to_from_json_list(dd, response.reported_to_list);
+
dd_close(dd);
}
--
1.7.1
11 years, 8 months
[ABRT PATCH] add post_report event which updates ABRT server database
by Jakub Filak
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
abrt.spec.in | 1 +
po/POTFILES.in | 1 +
src/plugins/Makefile.am | 6 ++++--
src/plugins/ccpp_event.conf | 6 +++++-
src/plugins/koops_event.conf | 6 +++++-
src/plugins/post_report.xml.in | 8 ++++++++
src/plugins/python_event.conf | 6 +++++-
7 files changed, 29 insertions(+), 5 deletions(-)
create mode 100644 src/plugins/post_report.xml.in
diff --git a/abrt.spec.in b/abrt.spec.in
index 29c561f..fd71204 100644
--- a/abrt.spec.in
+++ b/abrt.spec.in
@@ -546,6 +546,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%{_sysconfdir}/libreport/events/collect_GConf.xml
%{_sysconfdir}/libreport/events/collect_vimrc_user.xml
%{_sysconfdir}/libreport/events/collect_vimrc_system.xml
+%{_sysconfdir}/libreport/events/post_report.xml
%{_mandir}/man*/abrt-action-analyze-c.*
%{_mandir}/man*/abrt-action-trim-files.*
%{_mandir}/man*/abrt-action-generate-backtrace.*
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0b8176c..3bd7a1b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -40,4 +40,5 @@ src/plugins/collect_GConf.xml.in
src/plugins/collect_Smolt.xml.in
src/plugins/collect_vimrc_system.xml.in
src/plugins/collect_vimrc_user.xml.in
+src/plugins/post_report.xml.in
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 0f8a4d4..10ab579 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -35,7 +35,8 @@ dist_events_DATA = \
collect_Smolt.xml \
collect_GConf.xml \
collect_vimrc_user.xml \
- collect_vimrc_system.xml
+ collect_vimrc_system.xml \
+ post_report.xml
@INTLTOOL_XML_RULE@
@@ -71,7 +72,8 @@ EXTRA_DIST = \
analyze_RetraceServer.xml.in \
analyze_VMcore.xml.in \
abrt-action-analyze-vmcore \
- https-utils.h
+ https-utils.h \
+ post_report.xml.in
abrt_watch_log_SOURCES = \
abrt-watch-log.c
diff --git a/src/plugins/ccpp_event.conf b/src/plugins/ccpp_event.conf
index 1667ff8..81b14d2 100644
--- a/src/plugins/ccpp_event.conf
+++ b/src/plugins/ccpp_event.conf
@@ -52,6 +52,10 @@ EVENT=report_Bugzilla analyzer=CCpp duphash!=
EVENT=report_uReport analyzer=CCpp
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=post_report analyzer=CCpp
+ reporter-ureport -r
+
# Reporting of C/Cpp problems
EVENT=report-gui analyzer=CCpp
- report-gtk -e report_uReport -e analyze_RetraceServer -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e analyze_RetraceServer -e report_Bugzilla -e post_report -- "$DUMP_DIR"
diff --git a/src/plugins/koops_event.conf b/src/plugins/koops_event.conf
index 4d75110..91759b1 100644
--- a/src/plugins/koops_event.conf
+++ b/src/plugins/koops_event.conf
@@ -22,6 +22,10 @@ EVENT=report_Bugzilla analyzer=Kerneloops
EVENT=report_uReport analyzer=Kerneloops
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=post_report analyzer=Kerneloops
+ reporter-ureport -r
+
# Reporting of kernel oopses
EVENT=report-gui analyzer=Kerneloops
- report-gtk -e report_uReport -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e report_Bugzilla -e post_report -- "$DUMP_DIR"
diff --git a/src/plugins/post_report.xml.in b/src/plugins/post_report.xml.in
new file mode 100644
index 0000000..6f13b2e
--- /dev/null
+++ b/src/plugins/post_report.xml.in
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<event>
+ <_name>Post report</_name>
+ <_description>Executed after the reporting is finished</_description>
+ <_long-description>Used for updating of the databases</_long-description>
+ <requires-items>reported_to</requires-items>
+ <gui-review-elements>no</gui-review-elements>
+</event>
diff --git a/src/plugins/python_event.conf b/src/plugins/python_event.conf
index a7c72ac..e60df11 100644
--- a/src/plugins/python_event.conf
+++ b/src/plugins/python_event.conf
@@ -10,6 +10,10 @@ EVENT=report_Bugzilla analyzer=Python
EVENT=report_uReport analyzer=Python
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=post_report analyzer=Python
+ reporter-ureport -r
+
# Reporting of python exceptions
EVENT=report-gui analyzer=Python
- report-gtk -e report_uReport -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e report_Bugzilla -e post_report -- "$DUMP_DIR"
--
1.7.11.4
11 years, 8 months
[ABRT PATCH] add update of abrt server database to event chains
by Jakub Filak
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/plugins/ccpp_event.conf | 8 ++++++--
src/plugins/koops_event.conf | 8 ++++++--
src/plugins/python_event.conf | 8 ++++++--
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/plugins/ccpp_event.conf b/src/plugins/ccpp_event.conf
index 1667ff8..01bab1c 100644
--- a/src/plugins/ccpp_event.conf
+++ b/src/plugins/ccpp_event.conf
@@ -49,9 +49,13 @@ EVENT=report_Bugzilla analyzer=CCpp duphash!=
reporter-bugzilla -b -c /etc/libreport/plugins/bugzilla.conf
# Send micro report
-EVENT=report_uReport analyzer=CCpp
+EVENT=report_uReport analyzer=CCpp reported_to=
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=report_uReport analyzer=CCpp reported_to~=^Bugzilla: reported_to~=^uReport:
+ reporter-ureport -r
+
# Reporting of C/Cpp problems
EVENT=report-gui analyzer=CCpp
- report-gtk -e report_uReport -e analyze_RetraceServer -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e analyze_RetraceServer -e report_Bugzilla -e report_uReport -- "$DUMP_DIR"
diff --git a/src/plugins/koops_event.conf b/src/plugins/koops_event.conf
index 4d75110..42ce933 100644
--- a/src/plugins/koops_event.conf
+++ b/src/plugins/koops_event.conf
@@ -19,9 +19,13 @@ EVENT=report_Bugzilla analyzer=Kerneloops
reporter-bugzilla -b
# Send micro report
-EVENT=report_uReport analyzer=Kerneloops
+EVENT=report_uReport analyzer=Kerneloops reported_to=
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=report_uReportl analyzer=Kerneloops reported_to~=^Bugzilla: reported_to~=^uReport:
+ reporter-ureport -r
+
# Reporting of kernel oopses
EVENT=report-gui analyzer=Kerneloops
- report-gtk -e report_uReport -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e report_Bugzilla -e report_uReport -- "$DUMP_DIR"
diff --git a/src/plugins/python_event.conf b/src/plugins/python_event.conf
index a7c72ac..7eea14a 100644
--- a/src/plugins/python_event.conf
+++ b/src/plugins/python_event.conf
@@ -7,9 +7,13 @@ EVENT=report_Bugzilla analyzer=Python
reporter-bugzilla -b -c /etc/libreport/plugins/bugzilla.conf
# Send micro report
-EVENT=report_uReport analyzer=Python
+EVENT=report_uReport analyzer=Python reported_to=
reporter-ureport
+# update ABRT database after successful report to bugzilla
+EVENT=report_uReport analyzer=Python reported_to~=^Bugzilla: reported_to~=^uReport:
+ reporter-ureport -r
+
# Reporting of python exceptions
EVENT=report-gui analyzer=Python
- report-gtk -e report_uReport -e report_Bugzilla -- "$DUMP_DIR"
+ report-gtk -e report_uReport -e report_Bugzilla -e report_uReport -- "$DUMP_DIR"
--
1.7.11.4
11 years, 8 months
[LIBREPORT PATCH] reporter-ureport: make configurable only URL to a server
by Jakub Filak
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/plugins/ureport.c | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 62d993d..a9c649c 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -22,8 +22,9 @@
#include "ureport.h"
#include "libreport_curl.h"
-#define REPORT_URL "https://retrace.fedoraproject.org/faf/reports/new/"
-#define ATTACH_URL "https://retrace.fedoraproject.org/faf/reports/attach/"
+#define SERVER_URL "https://retrace.fedoraproject.org/faf"
+#define REPORT_URL_SFX "/reports/new/"
+#define ATTACH_URL_SFX "/reports/attach/"
/*
* Loads uReport configuration from various sources.
@@ -121,7 +122,7 @@ int main(int argc, char **argv)
abrt_init(argv);
struct ureport_server_config config = {
- .ur_url = NULL,
+ .ur_url = SERVER_URL,
.ur_ssl_verify = true,
};
@@ -133,7 +134,7 @@ int main(int argc, char **argv)
struct options program_options[] = {
OPT__VERBOSE(&g_verbose),
OPT__DUMP_DIR(&dump_dir_path),
- OPT_STRING('u', "url", &config.ur_url, "URL", _("Specify url")),
+ OPT_STRING('u', "url", &config.ur_url, "URL", _("Specify URL to desired server")),
OPT_BOOL('k', "insecure", &insecure,
_("Allow insecure connection to ureport server")),
OPT_STRING('a', "attach", &ureport_hash, "BTHASH",
@@ -160,18 +161,14 @@ int main(int argc, char **argv)
/* we either need both -b & -a or none of them */
if (ureport_hash && rhbz_bug > 0)
{
- if (!config.ur_url)
- config.ur_url = ATTACH_URL;
-
+ char *dest_url = xasprintf("%s%s", config.ur_url, ATTACH_URL_SFX);
post_state = ureport_attach_rhbz(ureport_hash, rhbz_bug, &config);
- if (!check_response_statuscode(post_state, config.ur_url))
- {
- free_post_state(post_state);
- return 1;
- }
+ const int result = !check_response_statuscode(post_state, config.ur_url);
free_post_state(post_state);
- return 0;
+ free(dest_url);
+
+ return result;
}
else if (ureport_hash && rhbz_bug <= 0)
error_msg_and_die(_("You need to specify bug ID to attach."));
@@ -185,9 +182,6 @@ int main(int argc, char **argv)
/* -r */
if (attach_reported_to)
{
- if (!config.ur_url)
- config.ur_url = ATTACH_URL;
-
report_result_t *ureport_result = find_in_reported_to(dd, "uReport");
report_result_t *bz_result = find_in_reported_to(dd, "Bugzilla");
@@ -217,30 +211,30 @@ int main(int argc, char **argv)
post_state = ureport_attach_rhbz(bthash, bugid, &config);
free(bthash);
+ char *dest_url = xasprintf("%s%s", config.ur_url, ATTACH_URL_SFX);
int ret = !check_response_statuscode(post_state, config.ur_url);
free_post_state(post_state);
+ free(dest_url);
+
return ret;
}
/* -b, -a nor -r were specified - upload uReport from dump_dir */
- if (!config.ur_url)
- config.ur_url = REPORT_URL;
-
problem_data_t *pd = create_problem_data_from_dump_dir(dd);
dd_close(dd);
if (!pd)
xfunc_die(); /* create_problem_data_for_reporting already emitted error msg */
+ char *dest_url = xasprintf("%s%s", config.ur_url, REPORT_URL_SFX);
post_state = post_ureport(pd, &config);
problem_data_free(pd);
- if (!check_response_statuscode(post_state, config.ur_url))
- {
- free_post_state(post_state);
- return 1;
- }
-
int ret = 1; /* return 1 by default */
+
+ if (!check_response_statuscode(post_state, dest_url))
+ /* check_response_statuscode() already logged an error message */
+ goto err;
+
json_object *const json = json_tokener_parse(post_state->body);
if (is_error(json))
@@ -308,6 +302,7 @@ int main(int argc, char **argv)
format_err:
json_object_put(json);
err:
+ free(dest_url);
free_post_state(post_state);
return ret;
--
1.7.11.4
11 years, 8 months
[PATCH] new version of sparse-core-files-performance-hit
by Denys Vlasenko
Essentially, new logic is just:
# Making sure abrt is intercepting coredumps
# (otherwise test will "pass" but we'd not test abrt, just the kernel)
rlAssertGrep "abrt-hook-ccpp" /proc/sys/kernel/core_pattern
rlLog "Generating core"
rlRun "rm core* 2>/dev/null; sh -c './bigcore; exit 0' &>/dev/null"
rlAssertExists core*
apparent_coresize=$(du -B1 --apparent-size core* | sed 's/[ \t].*//')
actual_coresize=$(du -B1 core* | sed 's/[ \t].*//')
rlLog "Core sizes: apparent:$apparent_coresize actual:$actual_coresize"
# In my experience here apparent size is almost 500 times bigger
rlAssertGreater "Corefile is very sparse" $((apparent_coresize/50)) $actual_coresize
bigcore.c is ripped from gdb sources.
--
vda
diff --git a/tests/runtests/bz591504-sparse-core-files-performance-hit/runtest.sh b/tests/runtests/bz591504-sparse-core-files-performance-hit/runtest.sh
index 9f36c5a..e0e9ce5 100755
--- a/tests/runtests/bz591504-sparse-core-files-performance-hit/runtest.sh
+++ b/tests/runtests/bz591504-sparse-core-files-performance-hit/runtest.sh
@@ -33,73 +33,32 @@ GDB_BUILDDEPS="expat-devel ncurses-devel rpm-devel bison python-devel gettext fl
rlJournalStart
rlPhaseStartSetup
- rlRun "yum-builddep -y gdb" 0 "Build dependencies for gdb"
TmpDir=$(mktemp -d)
+ rlRun "cc bigcore.c -o $TmpDir/bigcore" 0 "Compiling bigcore.c"
pushd $TmpDir
- rlRun "yumdownloader --source gdb" 0 "Download gdb sources"
-
- # deps. explicitly listed in kickstart due to yum-builddep in RHEL
- # not able to parse deps from spec file inside the package causing
- # architecure mismatch. safe for fedora
- #rlRun "yum-builddep -y gdb-*.src.rpm" 0 "Fetch gdb dependencies"
- # in case packages weren't installed before
- rlRun "yum -y install $GDB_BUILDDEPS" 0 "Install build dependencies"
-
- rlRun "rpm -ivh gdb-*.src.rpm" 0 "Install gdb sources"
- specfile="$(rpm --eval '%_specdir')/gdb.spec"
- rlRun "rpmbuild -bp $specfile" 0 "Unpack and patch"
- gdbtestdir="$(rpm --eval '%_builddir')/gdb-*/gdb/testsuite"
- pushd $gdbtestdir
- rlRun "./configure" 0 "Run configure"
- rlRun "make site.exp" 0 "Make gdb tests"
+ rlRun "ulimit -c unlimited"
rlPhaseEnd
rlPhaseStartTest
- times=3 # number of repetitions
- stoptime=0 # runtime when abrt is stopped
- goldratio=5 # $stoptime * $goldratio:
- # | run with abrt on should not take more that five times
- # | compared to run with abrt turned off
- absmin=45 # sometimes we have so powerfull machine it finishes the
- # | test in less then a second (and average is then also
- # | less then a second. Let's constitute a minimal time
- # | with which we are always OK.
-
- rlRun "service abrtd stop" 0 "Killing abrtd"
-
- rlLog "Calculate run times with abrt turned off"
- rlRun "runtest gdb.base/bigcore.exp &> /dev/null" 0 "Pre-test run"
- for run in $(seq $times); do
- rlRun "/usr/bin/time -f '%e' -o bigcore-stop.time.$run runtest gdb.base/bigcore.exp"
- done
- for cnt in $(seq $times); do
- stoptime=$(echo "$(cat bigcore-stop.time.$cnt) + $stoptime" | bc -l)
- rlLog "Execution #${cnt} took $(cat bigcore-stop.time.$cnt) seconds"
- done
- stoptime=$(echo "scale=3; $stoptime / $times" | bc -l)
- rlLog "Computed time with abrt stopped: $stoptime"
+ # Making sure abrt is intercepting coredumps
+ # (otherwise test will "pass" but we'd not test abrt, just the kernel)
+ rlAssertGrep "abrt-hook-ccpp" /proc/sys/kernel/core_pattern
- starttimeout=$(echo "$goldratio * $stoptime" | bc -l)
- starttimeout=$(echo "$starttimeout" | awk '{ if ($1 < '$absmin') { print '$absmin' } else { print '$starttimeout' } }')
- rlLog "Adjusted timeout: $starttimeout"
+ rlLog "Generating core"
+ rlRun "rm core* 2>/dev/null; sh -c './bigcore; exit 0' &>/dev/null"
+ rlAssertExists core*
+ apparent_coresize=$(du -B1 --apparent-size core* | sed 's/[ \t].*//')
+ actual_coresize=$(du -B1 core* | sed 's/[ \t].*//')
+ rlLog "Core sizes: apparent:$apparent_coresize actual:$actual_coresize"
- rlRun "service abrtd start" 0 "Starting abrtd"
+ # In my experience here apparent size is almost 500 times bigger
+ rlAssertGreater "Corefile is very sparse" $((apparent_coresize/50)) $actual_coresize
- rlRun "runtest gdb.base/bigcore.exp &> /dev/null" 0 "Pre-test run"
- for run in $(seq $times); do
- rlWatchdog "runtest gdb.base/bigcore.exp" $starttimeout
- ec=$?
- rlAssert0 "Test performed fine" $ec
- done
rlPhaseEnd
rlPhaseStartCleanup
# clean the awfully big coredumps, it causes the test machine to run out of space :(
- for coredump in `find /var/spool/abrt -name "coredump"`;
- do
- rm $coredump;
- done;
- popd # $gdbtestdir
+ rm /var/spool/abrt/*/coredump 2>/dev/null
popd # $TmpDir
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
11 years, 8 months
[PATCH] reporter-ureport: attach bug ID from reported_to
by Michal Toman
---
src/plugins/ureport.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 99ce60a..3f8b3c2 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -126,6 +126,7 @@ int main(int argc, char **argv)
};
bool insecure = !config.ur_ssl_verify;
+ bool attach_reported_to = false;
const char *dump_dir_path = ".";
const char *ureport_hash = NULL;
int rhbz_bug = -1;
@@ -139,11 +140,13 @@ int main(int argc, char **argv)
_("bthash of uReport to attach")),
OPT_INTEGER('b', "bug-id", &rhbz_bug,
_("Attach RHBZ bug (requires -a)")),
+ OPT_BOOL('r', "attach-reported-to", &attach_reported_to,
+ _("Attach contents of reported_to")),
OPT_END(),
};
const char *program_usage_string = _(
- "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-d DIR]\n"
+ "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-r] [-d DIR]\n"
"\n"
"Upload micro report or add an attachment to a micro report"
);
@@ -175,11 +178,61 @@ int main(int argc, char **argv)
else if (!ureport_hash && rhbz_bug > 0)
error_msg_and_die(_("You need to specify bthash of the uReport to attach."));
- /* -b nor -a were specified - upload uReport from dump_dir */
+ struct dump_dir *dd;
+
+ /* -r */
+ if (attach_reported_to)
+ {
+ if (!config.ur_url)
+ config.ur_url = ATTACH_URL;
+
+ dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ if (!dd)
+ xfunc_die();
+
+ report_result_t *ureport_result = find_in_reported_to(dd, "uReport");
+ report_result_t *bz_result = find_in_reported_to(dd, "Bugzilla");
+
+ dd_close(dd);
+
+ if (!ureport_result || !ureport_result->bthash)
+ error_msg_and_die("This problem has not an uReport assigned.");
+
+ char *bthash = xstrdup(ureport_result->bthash);
+ free_report_result(ureport_result);
+
+ if (!bz_result || !bz_result->url)
+ error_msg_and_die("This problem has not been reported to Bugzilla.");
+
+ char *bugid_ptr = strstr(bz_result->url, "show_bug.cgi?id=");
+ if (!bugid_ptr)
+ error_msg_and_die("Unable to find bug ID in bugzilla URL.");
+
+ bugid_ptr += strlen("show_bug.cgi?id=");
+ int bugid;
+ if (sscanf(bugid_ptr, "%d", &bugid) != 1)
+ error_msg_and_die("Unable to parse bug ID from bugzilla URL.");
+
+ free_report_result(bz_result);
+
+ post_state = ureport_attach_rhbz(bthash, bugid, &config);
+ free(bthash);
+
+ if (!check_response_statuscode(post_state, config.ur_url))
+ {
+ free_post_state(post_state);
+ return 1;
+ }
+
+ free_post_state(post_state);
+ return 0;
+ }
+
+ /* -b, -a nor -r were specified - upload uReport from dump_dir */
if (!config.ur_url)
config.ur_url = REPORT_URL;
- struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
if (!dd)
xfunc_die();
--
1.7.1
11 years, 8 months
[PATCH] add python binding for problem_data_send_to_abrt
by Michal Toman
---
src/report-python/problem_data.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/report-python/problem_data.c b/src/report-python/problem_data.c
index 666d839..2396620 100644
--- a/src/report-python/problem_data.c
+++ b/src/report-python/problem_data.c
@@ -128,6 +128,13 @@ static PyObject *p_problem_data_add_current_process(PyObject *pself, PyObject *a
Py_RETURN_NONE;
}
+static PyObject *p_problem_data_send_to_abrt(PyObject *pself, PyObject *always_null)
+{
+ p_problem_data *self = (p_problem_data*)pself;
+ problem_data_send_to_abrt(self->cd);
+
+ Py_RETURN_NONE;
+}
//static PyMemberDef p_problem_data_members[] = {
// { NULL }
@@ -140,6 +147,7 @@ static PyMethodDef p_problem_data_methods[] = {
{ "create_dump_dir" , p_create_dump_dir_from_problem_data, METH_VARARGS },
{ "add_basics" , p_problem_data_add_basics , METH_NOARGS },
{ "add_current_proccess", p_problem_data_add_current_process , METH_NOARGS },
+ { "send_to_abrt" , p_problem_data_send_to_abrt , METH_NOARGS },
{ NULL }
};
--
1.7.1
11 years, 8 months
[PATCH] reporter-ureport: allow sending attachments
by Michal Toman
---
src/lib/json.c | 42 ++++++++++++++++++++++++++
src/lib/ureport.h | 4 ++
src/plugins/ureport.c | 78 +++++++++++++++++++++++++++++++++++++++---------
3 files changed, 109 insertions(+), 15 deletions(-)
diff --git a/src/lib/json.c b/src/lib/json.c
index 2cda77d..a413751 100644
--- a/src/lib/json.c
+++ b/src/lib/json.c
@@ -251,6 +251,22 @@ char *new_json_ureport(problem_data_t *pd)
return j;
}
+char *new_json_attachment(const char *bthash, const char *type, const char *data)
+{
+ struct json_object *attachment = json_object_new_object();
+ if (!attachment)
+ die_out_of_memory();
+
+ ureport_add_str(attachment, "bthash", bthash);
+ ureport_add_str(attachment, "type", type);
+ ureport_add_str(attachment, "data", data);
+
+ char *result = xstrdup(json_object_to_json_string(attachment));
+ json_object_put(attachment);
+
+ return result;
+}
+
struct post_state *post_ureport(problem_data_t *pd, struct ureport_server_config *config)
{
int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
@@ -275,3 +291,29 @@ struct post_state *post_ureport(problem_data_t *pd, struct ureport_server_config
return post_state;
}
+
+struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id,
+ struct ureport_server_config *config)
+{
+ int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
+
+ if (config->ur_ssl_verify)
+ flags |= POST_WANT_SSL_VERIFY;
+
+ struct post_state *post_state = new_post_state(flags);
+
+ static const char *headers[] = {
+ "Accept: application/json",
+ "Connection: close",
+ NULL,
+ };
+
+ char *str_bug_id = xasprintf("%d", rhbz_bug_id);
+ char *json_attachment = new_json_attachment(bthash, "RHBZ", str_bug_id);
+ post_string_as_form_data(post_state, config->ur_url, "application/json",
+ headers, json_attachment);
+ free(str_bug_id);
+ free(json_attachment);
+
+ return post_state;
+}
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
index 4e1bfcc..f851806 100644
--- a/src/lib/ureport.h
+++ b/src/lib/ureport.h
@@ -39,6 +39,10 @@ struct abrt_post_state;
#define post_ureport libreport_post_ureport
struct post_state *post_ureport(problem_data_t *pd, struct ureport_server_config *config);
+#define ureport_attach_rhbz libreport_ureport_attach_rhbz
+struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id,
+ struct ureport_server_config *config);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index bd7a3bb..99ce60a 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -22,6 +22,9 @@
#include "ureport.h"
#include "libreport_curl.h"
+#define REPORT_URL "https://retrace.fedoraproject.org/faf/reports/new/"
+#define ATTACH_URL "https://retrace.fedoraproject.org/faf/reports/attach/"
+
/*
* Loads uReport configuration from various sources.
*
@@ -95,58 +98,103 @@ static bool ureport_server_parse_json(json_object *json, struct ureport_server_r
return false;
}
+static bool check_response_statuscode(post_state_t *post_state,
+ const char *url)
+{
+ if (post_state->http_resp_code != 202)
+ {
+ char *errmsg = post_state->curl_error_msg;
+ if (errmsg && *errmsg)
+ error_msg("%s '%s'", errmsg, url);
+ else
+ error_msg("Unexpected HTTP status code: %d",
+ post_state->http_resp_code);
+
+ return false;
+ }
+
+ return true;
+}
+
int main(int argc, char **argv)
{
abrt_init(argv);
struct ureport_server_config config = {
- .ur_url = "https://retrace.fedoraproject.org/faf/reports/new/",
+ .ur_url = NULL,
.ur_ssl_verify = true,
};
bool insecure = !config.ur_ssl_verify;
const char *dump_dir_path = ".";
+ const char *ureport_hash = NULL;
+ int rhbz_bug = -1;
struct options program_options[] = {
OPT__VERBOSE(&g_verbose),
OPT__DUMP_DIR(&dump_dir_path),
OPT_STRING('u', "url", &config.ur_url, "URL", _("Specify url")),
OPT_BOOL('k', "insecure", &insecure,
_("Allow insecure connection to ureport server")),
+ OPT_STRING('a', "attach", &ureport_hash, "BTHASH",
+ _("bthash of uReport to attach")),
+ OPT_INTEGER('b', "bug-id", &rhbz_bug,
+ _("Attach RHBZ bug (requires -a)")),
OPT_END(),
};
const char *program_usage_string = _(
- "& [-v] [-u URL] [-k] -d DIR\n"
+ "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-d DIR]\n"
"\n"
- "Upload micro report"
+ "Upload micro report or add an attachment to a micro report"
);
parse_opts(argc, argv, program_options, program_usage_string);
- struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
- if (!dd)
- xfunc_die();
config.ur_ssl_verify = !insecure;
load_ureport_server_config(&config);
+ post_state_t *post_state = NULL;
+
+ /* we either need both -b & -a or none of them */
+ if (ureport_hash && rhbz_bug > 0)
+ {
+ if (!config.ur_url)
+ config.ur_url = ATTACH_URL;
+
+ post_state = ureport_attach_rhbz(ureport_hash, rhbz_bug, &config);
+ if (!check_response_statuscode(post_state, config.ur_url))
+ {
+ free_post_state(post_state);
+ return 1;
+ }
+
+ free_post_state(post_state);
+ return 0;
+ }
+ else if (ureport_hash && rhbz_bug <= 0)
+ error_msg_and_die(_("You need to specify bug ID to attach."));
+ else if (!ureport_hash && rhbz_bug > 0)
+ error_msg_and_die(_("You need to specify bthash of the uReport to attach."));
+
+ /* -b nor -a were specified - upload uReport from dump_dir */
+ if (!config.ur_url)
+ config.ur_url = REPORT_URL;
+
+ struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ if (!dd)
+ xfunc_die();
problem_data_t *pd = create_problem_data_from_dump_dir(dd);
dd_close(dd);
if (!pd)
xfunc_die(); /* create_problem_data_for_reporting already emitted error msg */
- post_state_t *post_state = NULL;
post_state = post_ureport(pd, &config);
problem_data_free(pd);
- if (post_state->http_resp_code != 200)
+ if (!check_response_statuscode(post_state, config.ur_url))
{
- char *errmsg = post_state->curl_error_msg;
- if (errmsg && *errmsg)
- {
- error_msg("%s '%s'", errmsg, config.ur_url);
- free_post_state(post_state);
- return 1;
- }
+ free_post_state(post_state);
+ return 1;
}
int ret = 1; /* return 1 by default */
--
1.7.1
11 years, 8 months
[PATCH] reporter-ureport: allow sending attachments
by Michal Toman
Signed-off-by: Michal Toman <mtoman(a)redhat.com>
---
src/lib/json.c | 42 ++++++++++++++++++++++++++
src/lib/ureport.h | 4 ++
src/plugins/ureport.c | 78
+++++++++++++++++++++++++++++++++++++++---------
3 files changed, 109 insertions(+), 15 deletions(-)
diff --git a/src/lib/json.c b/src/lib/json.c
index 2cda77d..a413751 100644
--- a/src/lib/json.c
+++ b/src/lib/json.c
@@ -251,6 +251,22 @@ char *new_json_ureport(problem_data_t *pd)
return j;
}
+char *new_json_attachment(const char *bthash, const char *type, const
char *data)
+{
+ struct json_object *attachment = json_object_new_object();
+ if (!attachment)
+ die_out_of_memory();
+
+ ureport_add_str(attachment, "bthash", bthash);
+ ureport_add_str(attachment, "type", type);
+ ureport_add_str(attachment, "data", data);
+
+ char *result = xstrdup(json_object_to_json_string(attachment));
+ json_object_put(attachment);
+
+ return result;
+}
+
struct post_state *post_ureport(problem_data_t *pd, struct
ureport_server_config *config)
{
int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
@@ -275,3 +291,29 @@ struct post_state *post_ureport(problem_data_t *pd,
struct ureport_server_config
return post_state;
}
+
+struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id,
+ struct ureport_server_config
*config)
+{
+ int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
+
+ if (config->ur_ssl_verify)
+ flags |= POST_WANT_SSL_VERIFY;
+
+ struct post_state *post_state = new_post_state(flags);
+
+ static const char *headers[] = {
+ "Accept: application/json",
+ "Connection: close",
+ NULL,
+ };
+
+ char *str_bug_id = xasprintf("%d", rhbz_bug_id);
+ char *json_attachment = new_json_attachment(bthash, "RHBZ",
str_bug_id);
+ post_string_as_form_data(post_state, config->ur_url,
"application/json",
+ headers, json_attachment);
+ free(str_bug_id);
+ free(json_attachment);
+
+ return post_state;
+}
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
index 4e1bfcc..f851806 100644
--- a/src/lib/ureport.h
+++ b/src/lib/ureport.h
@@ -39,6 +39,10 @@ struct abrt_post_state;
#define post_ureport libreport_post_ureport
struct post_state *post_ureport(problem_data_t *pd, struct
ureport_server_config *config);
+#define ureport_attach_rhbz libreport_ureport_attach_rhbz
+struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id,
+ struct ureport_server_config
*config);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index bd7a3bb..99ce60a 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -22,6 +22,9 @@
#include "ureport.h"
#include "libreport_curl.h"
+#define REPORT_URL "https://retrace.fedoraproject.org/faf/reports/new/"
+#define ATTACH_URL "https://retrace.fedoraproject.org/faf/reports/attach/"
+
/*
* Loads uReport configuration from various sources.
*
@@ -95,58 +98,103 @@ static bool ureport_server_parse_json(json_object
*json, struct ureport_server_r
return false;
}
+static bool check_response_statuscode(post_state_t *post_state,
+ const char *url)
+{
+ if (post_state->http_resp_code != 202)
+ {
+ char *errmsg = post_state->curl_error_msg;
+ if (errmsg && *errmsg)
+ error_msg("%s '%s'", errmsg, url);
+ else
+ error_msg("Unexpected HTTP status code: %d",
+ post_state->http_resp_code);
+
+ return false;
+ }
+
+ return true;
+}
+
int main(int argc, char **argv)
{
abrt_init(argv);
struct ureport_server_config config = {
- .ur_url = "https://retrace.fedoraproject.org/faf/reports/new/",
+ .ur_url = NULL,
.ur_ssl_verify = true,
};
bool insecure = !config.ur_ssl_verify;
const char *dump_dir_path = ".";
+ const char *ureport_hash = NULL;
+ int rhbz_bug = -1;
struct options program_options[] = {
OPT__VERBOSE(&g_verbose),
OPT__DUMP_DIR(&dump_dir_path),
OPT_STRING('u', "url", &config.ur_url, "URL", _("Specify url")),
OPT_BOOL('k', "insecure", &insecure,
_("Allow insecure connection to ureport
server")),
+ OPT_STRING('a', "attach", &ureport_hash, "BTHASH",
+ _("bthash of uReport to attach")),
+ OPT_INTEGER('b', "bug-id", &rhbz_bug,
+ _("Attach RHBZ bug (requires -a)")),
OPT_END(),
};
const char *program_usage_string = _(
- "& [-v] [-u URL] [-k] -d DIR\n"
+ "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-d DIR]\n"
"\n"
- "Upload micro report"
+ "Upload micro report or add an attachment to a micro report"
);
parse_opts(argc, argv, program_options, program_usage_string);
- struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
- if (!dd)
- xfunc_die();
config.ur_ssl_verify = !insecure;
load_ureport_server_config(&config);
+ post_state_t *post_state = NULL;
+
+ /* we either need both -b & -a or none of them */
+ if (ureport_hash && rhbz_bug > 0)
+ {
+ if (!config.ur_url)
+ config.ur_url = ATTACH_URL;
+
+ post_state = ureport_attach_rhbz(ureport_hash, rhbz_bug, &config);
+ if (!check_response_statuscode(post_state, config.ur_url))
+ {
+ free_post_state(post_state);
+ return 1;
+ }
+
+ free_post_state(post_state);
+ return 0;
+ }
+ else if (ureport_hash && rhbz_bug <= 0)
+ error_msg_and_die(_("You need to specify bug ID to attach."));
+ else if (!ureport_hash && rhbz_bug > 0)
+ error_msg_and_die(_("You need to specify bthash of the uReport
to attach."));
+
+ /* -b nor -a were specified - upload uReport from dump_dir */
+ if (!config.ur_url)
+ config.ur_url = REPORT_URL;
+
+ struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ if (!dd)
+ xfunc_die();
problem_data_t *pd = create_problem_data_from_dump_dir(dd);
dd_close(dd);
if (!pd)
xfunc_die(); /* create_problem_data_for_reporting already
emitted error msg */
- post_state_t *post_state = NULL;
post_state = post_ureport(pd, &config);
problem_data_free(pd);
- if (post_state->http_resp_code != 200)
+ if (!check_response_statuscode(post_state, config.ur_url))
{
- char *errmsg = post_state->curl_error_msg;
- if (errmsg && *errmsg)
- {
- error_msg("%s '%s'", errmsg, config.ur_url);
- free_post_state(post_state);
- return 1;
- }
+ free_post_state(post_state);
+ return 1;
}
int ret = 1; /* return 1 by default */
--
1.7.1
11 years, 8 months
[PATCH] hide socket communication into a helper function
by Jiri Moskovcak
---
src/include/problem_data.h | 1 +
src/lib/abrt_sock.c | 89 +++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/src/include/problem_data.h b/src/include/problem_data.h
index d741b5d..0392e0f 100644
--- a/src/include/problem_data.h
+++ b/src/include/problem_data.h
@@ -89,6 +89,7 @@ char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char
/* Aborts if key is not found: */
char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);
+int problem_data_send_to_abrt(problem_data_t* problem_data);
/* Conversions between in-memory and on-disk formats */
diff --git a/src/lib/abrt_sock.c b/src/lib/abrt_sock.c
index b595208..d52b975 100644
--- a/src/lib/abrt_sock.c
+++ b/src/lib/abrt_sock.c
@@ -21,18 +21,37 @@
#define SOCKET_FILE VAR_RUN"/abrt/abrt.socket"
-static int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name)
+/* conencts to abrtd
+ * returns: socketfd
+ * -1 on error
+ */
+static int connect_to_abrtd_socket()
{
- int result = 1; /* error so far */
-
int socketfd = xsocket(AF_UNIX, SOCK_STREAM, 0);
+ if (socketfd == -1)
+ return -1;
/*close_on_exec_on(socketfd); - not needed, we are closing it soon */
struct sockaddr_un local;
memset(&local, 0, sizeof(local));
local.sun_family = AF_UNIX;
strcpy(local.sun_path, SOCKET_FILE);
int r = connect(socketfd, (struct sockaddr*)&local, sizeof(local));
- if (r == 0)
+ if (r != 0)
+ return -1;
+
+ return socketfd;
+}
+
+static int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name)
+{
+ int result = 1; /* error so far */
+ int socketfd = connect_to_abrtd_socket();
+ if (socketfd == -1)
+ {
+ VERB1 perror_msg("Can't connect to '%s'", SOCKET_FILE);
+ return result;
+ }
+ else
{
full_write(socketfd, "DELETE ", strlen("DELETE "));
full_write(socketfd, dump_dir_name, strlen(dump_dir_name));
@@ -40,7 +59,7 @@ static int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name)
shutdown(socketfd, SHUT_WR);
char response[64];
- r = full_read(socketfd, response, sizeof(response) - 1);
+ int r = full_read(socketfd, response, sizeof(response) - 1);
if (r >= 0)
{
VERB1 log("Response via socket:'%.*s'", r, response);
@@ -51,13 +70,67 @@ static int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name)
result = strncmp(response, "HTTP/1.1 200 ", strlen("HTTP/1.1 200 "));
}
}
- else
+
+ close(socketfd);
+
+ return result;
+}
+
+int problem_data_send_to_abrt(problem_data_t* problem_data)
+{
+ int result = 1; /* error so far */
+ int socketfd = connect_to_abrtd_socket();
+ if (socketfd == -1)
{
VERB1 perror_msg("Can't connect to '%s'", SOCKET_FILE);
+ return result;
}
- close(socketfd);
+ else
+ {
+ GHashTableIter iter;
+ char *name;
+ struct problem_item *value;
+ g_hash_table_iter_init(&iter, problem_data);
- return result;
+ full_write(socketfd, "PUT / HTTP/1.1\r\n\r\n", strlen("PUT / HTTP/1.1\r\n\r\n"));
+ while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value))
+ {
+ if (value->flags & CD_FLAG_BIN)
+ {
+ /* sending files over the socket is not implemented yet */
+ log("Skipping binary file %s", name);
+ continue;
+ }
+
+ /* only files should contain '/' and those are handled earlier */
+ if (name[0] == '.' || strchr(name, '/'))
+ {
+ error_msg("Problem data field name contains disallowed chars: '%s'", name);
+ continue;
+ }
+
+ char* msg = xasprintf("%s=%s", name, value->content);
+ full_write(socketfd, msg, strlen(msg)+1 /* yes, +1 coz we want to send the trailing 0 */);
+ free(msg);
+ }
+ shutdown(socketfd, SHUT_WR);
+
+ char response[64];
+ int r = full_read(socketfd, response, sizeof(response) - 1);
+ if (r >= 0)
+ {
+ VERB1 log("Response via socket:'%.*s'", r, response);
+ /* 0123456789... */
+ /* "HTTP/1.1 200 " */
+ response[5] = '1';
+ response[7] = '1';
+ result = strncmp(response, "HTTP/1.1 201 ", strlen("HTTP/1.1 201 "));
+ }
+
+ close(socketfd);
+
+ return result;
+ }
}
int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name)
--
1.7.11.2
11 years, 8 months