[libreport/f16] allow sending binary files to bz rhbz#733448

Jiří Moskovčák jmoskovc at fedoraproject.org
Fri Sep 9 12:45:08 UTC 2011


commit 222df7010fcba0b6d71b72b7379e3aaa8ba3db62
Author: Jiri Moskovcak <jmoskovc at redhat.com>
Date:   Fri Sep 9 14:40:59 2011 +0200

    allow sending binary files to bz rhbz#733448

 ...gzilla-add-b-to-make-it-possible-to-attac.patch |  293 ++++++++++++++++++++
 libreport.spec                                     |    8 +-
 2 files changed, 300 insertions(+), 1 deletions(-)
---
diff --git a/0001-reporter-bugzilla-add-b-to-make-it-possible-to-attac.patch b/0001-reporter-bugzilla-add-b-to-make-it-possible-to-attac.patch
new file mode 100644
index 0000000..1fa976f
--- /dev/null
+++ b/0001-reporter-bugzilla-add-b-to-make-it-possible-to-attac.patch
@@ -0,0 +1,293 @@
+From ac1c8f561dbdc9a1ba6277d8aa776bc76a9fc928 Mon Sep 17 00:00:00 2001
+From: Jiri Moskovcak <jmoskovc at redhat.com>
+Date: Wed, 31 Aug 2011 09:59:21 +0200
+Subject: [PATCH 2/2] reporter-bugzilla: add -b to make it possible to attach
+ binary items
+
+Text file max size is increased to 500k.
+Both these measures should help with rhbz#733448.
+
+Signed-off-by: Denys Vlasenko <dvlasenk at redhat.com>
+
+Conflicts:
+
+	src/plugins/reporter-bugzilla.c
+---
+ src/lib/problem_data.c             |    3 +-
+ src/plugins/bugzilla_event.conf    |    2 +-
+ src/plugins/report_Bugzilla.xml.in |    2 +-
+ src/plugins/reporter-bugzilla.c    |   38 +++++++------------------
+ src/plugins/reporter-bugzilla.txt  |    5 ++-
+ src/plugins/rhbz.c                 |   54 ++++++++++++++++++++++++++++++++++--
+ src/plugins/rhbz.h                 |    8 ++++-
+ 7 files changed, 76 insertions(+), 36 deletions(-)
+
+diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
+index 91f269c..1783b63 100644
+--- a/src/lib/problem_data.c
++++ b/src/lib/problem_data.c
+@@ -236,9 +236,10 @@ static char* is_text_file(const char *name, ssize_t *sz)
+      * So, don't remove this. If you really need to, raise the limit.
+      *
+      * Bumped up to 200k: saw 124740 byte /proc/PID/smaps file
++     * Bumped up to 500k: saw 375252 byte anaconda traceback file
+      */
+     off_t size = lseek(fd, 0, SEEK_END);
+-    if (size < 0 || size > 200*1024)
++    if (size < 0 || size > 500*1024)
+     {
+         close(fd);
+         return NULL; /* it's not a SMALL text */
+diff --git a/src/plugins/bugzilla_event.conf b/src/plugins/bugzilla_event.conf
+index 3fb604d..109c581 100644
+--- a/src/plugins/bugzilla_event.conf
++++ b/src/plugins/bugzilla_event.conf
+@@ -1 +1 @@
+-EVENT=report_Bugzilla analyzer=libreport reporter-bugzilla
+\ No newline at end of file
++EVENT=report_Bugzilla analyzer=libreport reporter-bugzilla -b
+diff --git a/src/plugins/report_Bugzilla.xml.in b/src/plugins/report_Bugzilla.xml.in
+index 00ef4a4..059171f 100644
+--- a/src/plugins/report_Bugzilla.xml.in
++++ b/src/plugins/report_Bugzilla.xml.in
+@@ -6,7 +6,7 @@
+     <requires-items>component,duphash,os_release</requires-items>
+     <exclude-items-by-default>coredump,count,event_log,reported_to,vmcore</exclude-items-by-default>
+     <exclude-items-always></exclude-items-always>
+-    <exclude-binary-items>yes</exclude-binary-items>
++    <exclude-binary-items>no</exclude-binary-items>
+     <include-items-by-default></include-items-by-default>
+
+     <options>
+diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
+index 5f46636..ec263ae 100644
+--- a/src/plugins/reporter-bugzilla.c
++++ b/src/plugins/reporter-bugzilla.c
+@@ -24,7 +24,7 @@
+
+ static void report_to_bugzilla(const char *dump_dir_name, const char *login,
+                                const char *password, const char *bugzilla_xmlrpc,
+-                               const char *bugzilla_url, int ssl_verify)
++                               const char *bugzilla_url, int ssl_verify, int attach_binary)
+ {
+     problem_data_t *problem_data = create_problem_data_for_reporting(dump_dir_name);
+     if (!problem_data)
+@@ -113,7 +113,10 @@ static void report_to_bugzilla(const char *dump_dir_name, const char *login,
+         char bug_id_str[sizeof(int)*3 + 2];
+         sprintf(bug_id_str, "%i", bug_id);
+
+-        rhbz_attachments(client, bug_id_str, problem_data, RHBZ_NOMAIL_NOTIFY);
++        int flags = RHBZ_NOMAIL_NOTIFY;
++        if (attach_binary)
++            flags |= RHBZ_ATTACH_BINARY_FILES;
++        rhbz_attach_big_files(client, bug_id_str, problem_data, flags);
+
+         bz = new_bug_info();
+         bz->bi_status = xstrdup("NEW");
+@@ -210,8 +210,8 @@
+
+     /* Can't keep these strings/structs static: _() doesn't support that */
+     const char *program_usage_string = _(
+-        "\b [-v] [-c CONFFILE] -d DIR\n"
+-        "   or: \b [-v] --ticket[ID] FILE [FILE...]\n"
++        "\b [-vb] [-c CONFFILE] -d DIR\n"
++        "   or: \b [-vb] --ticket[ID] FILE [FILE...]\n"
+         "\n"
+         "Reports problem to Bugzilla.\n"
+         "\n"
+@@ -245,6 +248,7 @@ int main(int argc, char **argv)
+         OPT_d = 1 << 1,
+         OPT_c = 1 << 2,
+         OPT_t = 1 << 3,
++        OPT_b = 1 << 4,
+     };
+
+     char *ticket_no = NULL;
+@@ -249,6 +249,7 @@
+         OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Dump directory")),
+         OPT_LIST(  'c', NULL, &conf_file    , "FILE", _("Configuration file (may be given many times)")),
+         OPT_OPTSTRING('t', "ticket", &ticket_no, "ID", _("Attach file to a bugzilla id")),
++        OPT_BOOL(     'b', NULL, NULL,                   _("When creating bug, attach binary files too")),
+         OPT_END()
+     };
+     unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
+@@ -353,29 +358,8 @@ int main(int argc, char **argv)
+                 continue;
+             }
+
+-            off_t size = lseek(fd, 0, SEEK_END);
+-            if (size < 0)
+-            {
+-                perror_msg("Can't lseek '%s'", filename);
+-                close(fd);
+-                continue;
+-            }
+-            lseek(fd, 0, SEEK_SET);
+-
+-    /* FIXME: what if the file is tens of gigabytes? */
+-            char *data = xmalloc(size + 1);
+-            ssize_t r = full_read(fd, data, size);
+-            if (r < 0)
+-            {
+-                free(data);
+-                perror_msg("Can't read '%s'", filename);
+-                close(fd);
+-                continue;
+-            }
++            rhbz_attach_fd(client, filename, ticket_no, fd, /*flags*/ 0);
+             close(fd);
+-
+-            rhbz_attachment(client, filename, ticket_no, data, r, /*flags*/ 0);
+-            free(data);
+         }
+
+         log(_("Logging out"));
+@@ -385,7 +369,7 @@ int main(int argc, char **argv)
+     else
+     {
+         report_to_bugzilla(dump_dir_name, login, password, bugzilla_xmlrpc,
+-                           bugzilla_url, ssl_verify);
++                           bugzilla_url, ssl_verify, opts & OPT_b);
+     }
+
+     free_map_string(settings);
+diff --git a/src/plugins/reporter-bugzilla.txt b/src/plugins/reporter-bugzilla.txt
+index c78a1ba..4285600 100644
+--- a/src/plugins/reporter-bugzilla.txt
++++ b/src/plugins/reporter-bugzilla.txt
+@@ -10,7 +10,7 @@ reporter-bugzilla - Reports problem to Bugzilla.
+
+ SYNOPSIS
+ --------
+-'reporter-bugzilla' [-v] [-c CONFFILE] -d DIR
++'reporter-bugzilla' [-vb] [-c CONFFILE] -d DIR
+
+ DESCRIPTION
+ -----------
+@@ -62,6 +62,12 @@ OPTIONS
+
+ -c CONFFILE::
+    Path to configuration file.
++
++-b:
++   When creating bug, attach binary files too.
++
++-t[ID]::
++   Upload FILEs to the already created bug on Bugzilla site
+
+ SEE ALSO
+ --------
+diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
+index e086042..8ccb72b 100644
+--- a/src/plugins/rhbz.c
++++ b/src/plugins/rhbz.c
+@@ -380,7 +380,7 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
+ }
+
+ /* suppress mail notify by {s:i} (nomail:1) (driven by flag) */
+-int rhbz_attachment(struct abrt_xmlrpc *ax, const char *filename,
++int rhbz_attach_blob(struct abrt_xmlrpc *ax, const char *filename,
+                     const char *bug_id, const char *data, int data_len, int flags)
+ {
+     char *encoded64 = encode_base64(data, data_len);
+@@ -406,8 +406,38 @@ int rhbz_attachment(struct abrt_xmlrpc *ax, const char *filename,
+     return 0;
+ }
+
++int rhbz_attach_fd(struct abrt_xmlrpc *ax, const char *filename,
++                    const char *bug_id, int fd, int flags)
++{
++    off_t size = lseek(fd, 0, SEEK_END);
++    if (size < 0)
++    {
++        perror_msg("Can't lseek '%s'", filename);
++        return -1;
++    }
++    if (size > INT_MAX / 2)
++    {
++        error_msg("Can't upload '%s', it's too large (%llu bytes)", filename, (long long)size);
++        return -1;
++    }
++    lseek(fd, 0, SEEK_SET);
++
++    char *data = xmalloc(size + 1);
++    ssize_t r = full_read(fd, data, size);
++    if (r < 0)
++    {
++        free(data);
++        perror_msg("Can't read '%s'", filename);
++        return -1;
++    }
++
++    int res = rhbz_attach_blob(ax, filename, bug_id, data, size, flags);
++    free(data);
++    return res;
++}
++
+ /* suppress mail notify by {s:i} (nomail:1) (driven by flag) */
+-int rhbz_attachments(struct abrt_xmlrpc *ax, const char *bug_id,
++int rhbz_attach_big_files(struct abrt_xmlrpc *ax, const char *bug_id,
+                      problem_data_t *problem_data, int flags)
+ {
+     GHashTableIter iter;
+@@ -427,8 +457,26 @@ int rhbz_attachments(struct abrt_xmlrpc *ax, const char *bug_id,
+                 /* This text item wasn't added in comments, it is too big
+                  * for that. Attach it as a file.
+                  */
+-                rhbz_attachment(ax, name, bug_id, content, len, flags);
++                rhbz_attach_blob(ax, name, bug_id, content, len, flags);
++            }
++        }
++        if ((flags & RHBZ_ATTACH_BINARY_FILES) && (value->flags & CD_FLAG_BIN))
++        {
++            int fd = open(value->content, O_RDONLY);
++            if (fd < 0)
++            {
++                perror_msg("Can't open '%s'", value->content);
++                continue;
++            }
++            struct stat st;
++            if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode))
++            {
++                error_msg("'%s': not a regular file", value->content);
++                close(fd);
++                continue;
+             }
++            rhbz_attach_fd(ax, name, bug_id, fd, flags);
++            close(fd);
+         }
+     }
+
+diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
+index 29908b6..8e782b8 100644
+--- a/src/plugins/rhbz.h
++++ b/src/plugins/rhbz.h
+@@ -36,6 +36,7 @@ enum {
+     RHBZ_READ_INT       = (1 << 2),
+     RHBZ_NOMAIL_NOTIFY  = (1 << 3),
+     RHBZ_PRIVATE        = (1 << 4),
++    RHBZ_ATTACH_BINARY_FILES = (1 << 5),
+ };
+
+ #define IS_MANDATORY(flags) ((flags) & RHBZ_MANDATORY_MEMB)
+@@ -82,12 +83,15 @@ int rhbz_bug_id(xmlrpc_value *xml);
+ int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
+                  int depend_on_bug);
+
+-int rhbz_attachments(struct abrt_xmlrpc *ax, const char *bug_id,
++int rhbz_attach_big_files(struct abrt_xmlrpc *ax, const char *bug_id,
+                      problem_data_t *problem_data, int flags);
+
+-int rhbz_attachment(struct abrt_xmlrpc *ax, const char *filename,
++int rhbz_attach_blob(struct abrt_xmlrpc *ax, const char *filename,
+                     const char *bug_id, const char *data, int data_len, int flags);
+
++int rhbz_attach_fd(struct abrt_xmlrpc *ax, const char *filename,
++                    const char *bug_id, int fd, int flags);
++
+ GList *rhbz_bug_cc(xmlrpc_value *result_xml);
+
+ struct bug_info *rhbz_bug_info(struct abrt_xmlrpc *ax, int bug_id);
+--
+1.7.6.1
+
diff --git a/libreport.spec b/libreport.spec
index 252a74d..a9de618 100644
--- a/libreport.spec
+++ b/libreport.spec
@@ -5,7 +5,7 @@
 Summary: Generic library for reporting various problems
 Name: libreport
 Version: 2.0.5
-Release: 7%{?dist}
+Release: 8%{?dist}
 License: GPLv2+
 Group: System Environment/Libraries
 URL: https://fedorahosted.org/abrt/
@@ -55,6 +55,7 @@ Patch56: parse_release_bz.patch
 Patch57: libreport-fallback-textedit.patch
 Patch58: 0001-reporter-bugzilla-fix-file-attaching-was-using-strle.patch
 Patch59: 0002-wizard-support-shell-glob-patterns-in-.xml-item-sele.patch
+Patch60: 0001-reporter-bugzilla-add-b-to-make-it-possible-to-attac.patch
 BuildRequires: dbus-devel
 BuildRequires: gtk2-devel
 BuildRequires: curl-devel
@@ -271,6 +272,7 @@ Plugin to report bugs into anonymous FTP site associated with ticketing system.
 %patch57 -p1
 %patch58 -p1
 %patch59 -p1
+%patch60 -p1
 
 %build
 mkdir -p m4
@@ -422,6 +424,10 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
 %config(noreplace) %{_sysconfdir}/libreport/events.d/uploader_event.conf
 
 %changelog
+* Fri Sep 09 2011 Jiri Moskovcak <jmoskovc at redhat.com> 2.0.5-8
+- allow bugzilla to send binary files
+- Related: #733448
+
 * Tue Aug 30 2011 Jiri Moskovcak <jmoskovc at redhat.com> 2.0.5-7
 - added glob support to event xml files
 - changed handling of long text files


More information about the scm-commits mailing list