Blame SOURCES/0214-tree-wide-introduce-stop_on_not_reportable-option.patch

28bab8
From 8ee8cf6d0467241d2886a095be25c2885d3a8666 Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Wed, 23 Nov 2016 16:22:51 +0100
28bab8
Subject: [PATCH] tree-wide: introduce 'stop_on_not_reportable' option
28bab8
28bab8
Make it possible to ignore existence of not-reportable file and continue
28bab8
in reporting.
28bab8
28bab8
The new configuration option is not yet persistent and can be configured
28bab8
via an environment variable.
28bab8
28bab8
Related to #1257159
28bab8
Related to abrt/abrt#1166
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/cli/cli-report.c               |  3 +-
28bab8
 src/gui-wizard-gtk/wizard.c        | 21 ++++++++----
28bab8
 src/include/global_configuration.h | 28 ++++++++++++++++
28bab8
 src/include/internal_libreport.h   |  1 +
28bab8
 src/include/report.h               |  3 ++
28bab8
 src/lib/global_configuration.c     | 22 +++++++++++++
28bab8
 src/lib/report.c                   |  6 ++++
28bab8
 src/report-newt/report-newt.c      |  4 ++-
28bab8
 src/report-python/reportmodule.c   |  1 +
28bab8
 tests/global_config.at             | 67 ++++++++++++++++++++++++++++++++++++++
28bab8
 10 files changed, 148 insertions(+), 8 deletions(-)
28bab8
28bab8
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
28bab8
index 68baa8b..adb58a7 100644
28bab8
--- a/src/cli/cli-report.c
28bab8
+++ b/src/cli/cli-report.c
28bab8
@@ -525,7 +525,8 @@ static int is_not_reportable(problem_data_t *problem_data)
28bab8
     if (not_reportable)
28bab8
     {
28bab8
         printf("%s\n", not_reportable);
28bab8
-        return 1;
28bab8
+        if (get_global_stop_on_not_reportable())
28bab8
+            return 1;
28bab8
     }
28bab8
     return 0;
28bab8
 }
28bab8
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
28bab8
index 31861a1..35c6fc3 100644
28bab8
--- a/src/gui-wizard-gtk/wizard.c
28bab8
+++ b/src/gui-wizard-gtk/wizard.c
28bab8
@@ -2039,7 +2039,7 @@ static gboolean consume_cmd_output(GIOChannel *source, GIOCondition condition, g
28bab8
             dd_sanitize_mode_and_owner(dd);
28bab8
     }
28bab8
 
28bab8
-    if (retval == 0 && !g_expert_mode)
28bab8
+    if (retval == 0 && !g_expert_mode && get_global_stop_on_not_reportable())
28bab8
     {
28bab8
         /* Check whether NOT_REPORTABLE element appeared. If it did, we'll stop
28bab8
          * even if exit code is "success".
28bab8
@@ -3103,16 +3103,25 @@ static gint select_next_page_no(gint current_page_no, gpointer data)
28bab8
 
28bab8
             if (problem_data_get_content_or_NULL(g_cd, FILENAME_NOT_REPORTABLE))
28bab8
             {
28bab8
-                free(event);
28bab8
 
28bab8
                 char *msg = xasprintf(_("This problem should not be reported "
28bab8
                                 "(it is likely a known problem). %s"),
28bab8
                                 problem_data_get_content_or_NULL(g_cd, FILENAME_NOT_REPORTABLE)
28bab8
                 );
28bab8
-                cancel_processing(g_lbl_event_log, msg, TERMINATE_NOFLAGS);
28bab8
-                free(msg);
28bab8
-                current_page_no = pages[PAGENO_EVENT_PROGRESS].page_no - 1;
28bab8
-                goto again;
28bab8
+
28bab8
+                if (get_global_stop_on_not_reportable())
28bab8
+                {
28bab8
+                    free(event);
28bab8
+                    cancel_processing(g_lbl_event_log, msg, TERMINATE_NOFLAGS);
28bab8
+                    free(msg);
28bab8
+                    current_page_no = pages[PAGENO_EVENT_PROGRESS].page_no - 1;
28bab8
+                    goto again;
28bab8
+                }
28bab8
+                else
28bab8
+                {
28bab8
+                    log(msg);
28bab8
+                    free(msg);
28bab8
+                }
28bab8
             }
28bab8
 
28bab8
             /* must set g_event_selected otherwise if the event was not
28bab8
diff --git a/src/include/global_configuration.h b/src/include/global_configuration.h
28bab8
index bc5513d..0eb18c6 100644
28bab8
--- a/src/include/global_configuration.h
28bab8
+++ b/src/include/global_configuration.h
28bab8
@@ -53,6 +53,34 @@ bool get_global_create_private_ticket(void);
28bab8
 #define set_global_create_private_ticket libreport_set_global_create_private_ticket
28bab8
 void set_global_create_private_ticket(bool enabled, int flags);
28bab8
 
28bab8
+/**
28bab8
+ * Returns logical true if the reporting process shall not start or contine if
28bab8
+ * the not-reportable files exists.
28bab8
+ *
28bab8
+ * The option can be enabled by ABRT_STOP_ON_NOT_REPORTABLE environment
28bab8
+ * variable.
28bab8
+ *
28bab8
+ * @return true if the process shall stop; otherwise the function returns
28bab8
+ * false.
28bab8
+ */
28bab8
+#define get_global_stop_on_not_reportable libreport_get_global_stop_on_not_reportable
28bab8
+bool get_global_stop_on_not_reportable(void);
28bab8
+
28bab8
+/**
28bab8
+ * Configures the stop on not reportable global option
28bab8
+ *
28bab8
+ * The function changes the configuration only for the current process by
28bab8
+ * default.
28bab8
+ *
28bab8
+ * The option can be enabled by ABRT_STOP_ON_NOT_REPORTABLE environment
28bab8
+ * variable.
28bab8
+ *
28bab8
+ * @param enabled The option's value
28bab8
+ * @param flags For future needs (enable persistent configuration)
28bab8
+ */
28bab8
+#define set_global_stop_on_not_reportable libreport_set_global_stop_on_not_reportable
28bab8
+void set_global_stop_on_not_reportable(bool enabled, int flags);
28bab8
+
28bab8
 #ifdef __cplusplus
28bab8
 }
28bab8
 #endif
28bab8
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
28bab8
index cf5730c..23cdfa0 100644
28bab8
--- a/src/include/internal_libreport.h
28bab8
+++ b/src/include/internal_libreport.h
28bab8
@@ -87,6 +87,7 @@ int vdprintf(int d, const char *format, va_list ap);
28bab8
 
28bab8
 /* consts used across whole libreport */
28bab8
 #define CREATE_PRIVATE_TICKET "ABRT_CREATE_PRIVATE_TICKET"
28bab8
+#define STOP_ON_NOT_REPORTABLE "ABRT_STOP_ON_NOT_REPORTABLE"
28bab8
 
28bab8
 /* Pull in entire public libreport API */
28bab8
 #include "dump_dir.h"
28bab8
diff --git a/src/include/report.h b/src/include/report.h
28bab8
index d31eb0a..03f3dc6 100644
28bab8
--- a/src/include/report.h
28bab8
+++ b/src/include/report.h
28bab8
@@ -35,6 +35,9 @@ enum {
28bab8
     LIBREPORT_DEL_DIR     = (1 << 6), /* delete directory after reporting (passes --delete to child) */
28bab8
     LIBREPORT_RUN_CLI     = (1 << 7), /* run 'cli' instead of 'gui' */
28bab8
     LIBREPORT_RUN_NEWT    = (1 << 8), /* run 'report-newt' */
28bab8
+    LIBREPORT_IGNORE_NOT_REPORTABLE = (1 << 9), /* do not terminate the
28bab8
+                                                  reporting process if the
28bab8
+                                                  not-repotrable file exits. */
28bab8
 };
28bab8
 
28bab8
 int report_problem_in_dir(const char *dirname, int flags);
28bab8
diff --git a/src/lib/global_configuration.c b/src/lib/global_configuration.c
28bab8
index ef921e9..46b9a63 100644
28bab8
--- a/src/lib/global_configuration.c
28bab8
+++ b/src/lib/global_configuration.c
28bab8
@@ -163,3 +163,25 @@ void set_global_create_private_ticket(bool enabled, int flags/*unused - persiste
28bab8
     else
28bab8
         safe_unsetenv(CREATE_PRIVATE_TICKET);
28bab8
 }
28bab8
+
28bab8
+bool get_global_stop_on_not_reportable(void)
28bab8
+{
28bab8
+    assert_global_configuration_initialized();
28bab8
+
28bab8
+    char *env_create_private = getenv(STOP_ON_NOT_REPORTABLE);
28bab8
+
28bab8
+    if (env_create_private == NULL)
28bab8
+        return true;
28bab8
+
28bab8
+    return string_to_bool(env_create_private);
28bab8
+}
28bab8
+
28bab8
+void set_global_stop_on_not_reportable(bool enabled, int flags/*unused - persistent*/)
28bab8
+{
28bab8
+    assert_global_configuration_initialized();
28bab8
+
28bab8
+    if (enabled)
28bab8
+        xsetenv(STOP_ON_NOT_REPORTABLE, "1");
28bab8
+    else
28bab8
+        xsetenv(STOP_ON_NOT_REPORTABLE, "0");
28bab8
+}
28bab8
diff --git a/src/lib/report.c b/src/lib/report.c
28bab8
index 7a655fd..3380a52 100644
28bab8
--- a/src/lib/report.c
28bab8
+++ b/src/lib/report.c
28bab8
@@ -26,6 +26,12 @@ int report_problem_in_dir(const char *dirname, int flags)
28bab8
     if (prgname)
28bab8
         prgname = xasprintf("LIBREPORT_PRGNAME=%s", prgname);
28bab8
 
28bab8
+    if (flags & LIBREPORT_IGNORE_NOT_REPORTABLE)
28bab8
+    {
28bab8
+        load_global_configuration();
28bab8
+        set_global_stop_on_not_reportable(false, 0);
28bab8
+    }
28bab8
+
28bab8
     fflush(NULL);
28bab8
 
28bab8
     pid_t pid = fork();
28bab8
diff --git a/src/report-newt/report-newt.c b/src/report-newt/report-newt.c
28bab8
index f5fca76..278cfb7 100644
28bab8
--- a/src/report-newt/report-newt.c
28bab8
+++ b/src/report-newt/report-newt.c
28bab8
@@ -336,7 +336,9 @@ static int report(const char *dump_dir_name)
28bab8
         dd_close(dd);
28bab8
         newtWinMessage(_("Error"), _("Ok"), (char *)"%s", t);
28bab8
         free(t);
28bab8
-        return -1;
28bab8
+
28bab8
+        if (get_global_stop_on_not_reportable())
28bab8
+            return -1;
28bab8
     }
28bab8
 
28bab8
     dd_close(dd);
28bab8
diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c
28bab8
index b8154ae..4491fd4 100644
28bab8
--- a/src/report-python/reportmodule.c
28bab8
+++ b/src/report-python/reportmodule.c
28bab8
@@ -98,6 +98,7 @@ init_pyreport(void)
28bab8
     PyModule_AddObject(m, "LIBREPORT_DEL_DIR"    , Py_BuildValue("i", LIBREPORT_DEL_DIR    ));
28bab8
     PyModule_AddObject(m, "LIBREPORT_RUN_CLI"    , Py_BuildValue("i", LIBREPORT_RUN_CLI    ));
28bab8
     PyModule_AddObject(m, "LIBREPORT_RUN_NEWT"   , Py_BuildValue("i", LIBREPORT_RUN_NEWT  ));
28bab8
+    PyModule_AddObject(m, "LIBREPORT_IGNORE_NOT_REPORTABLE", Py_BuildValue("i", LIBREPORT_IGNORE_NOT_REPORTABLE));
28bab8
     PyModule_AddObject(m, "EXIT_CANCEL_BY_USER", Py_BuildValue("i", EXIT_CANCEL_BY_USER));
28bab8
     PyModule_AddObject(m, "EXIT_STOP_EVENT_RUN", Py_BuildValue("i", EXIT_STOP_EVENT_RUN));
28bab8
 }
28bab8
diff --git a/tests/global_config.at b/tests/global_config.at
28bab8
index 05a0ffa..1067128 100644
28bab8
--- a/tests/global_config.at
28bab8
+++ b/tests/global_config.at
28bab8
@@ -169,3 +169,70 @@ TS_MAIN
28bab8
 }
28bab8
 TS_RETURN_MAIN
28bab8
 ]])
28bab8
+
28bab8
+
28bab8
+## ---------------------- ##
28bab8
+## stop_on_not_reportable ##
28bab8
+## ---------------------- ##
28bab8
+
28bab8
+AT_TESTFUN([stop_on_not_reportable], [[
28bab8
+#include "testsuite.h"
28bab8
+
28bab8
+TS_MAIN
28bab8
+{
28bab8
+    char cwd_buf[PATH_MAX + 1];
28bab8
+    static const char *dirs[] = {
28bab8
+        NULL,
28bab8
+        NULL,
28bab8
+    };
28bab8
+    dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf));
28bab8
+
28bab8
+    static int dir_flags[] = {
28bab8
+        CONF_DIR_FLAG_NONE,
28bab8
+        -1,
28bab8
+    };
28bab8
+
28bab8
+    unlink("libreport.conf");
28bab8
+    FILE *lrf = fopen("libreport.conf", "wx");
28bab8
+    assert(lrf != NULL);
28bab8
+    fclose(lrf);
28bab8
+
28bab8
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
28bab8
+
28bab8
+    TS_ASSERT_TRUE_MESSAGE(get_global_stop_on_not_reportable(), "True by default");
28bab8
+
28bab8
+    set_global_stop_on_not_reportable(true, 0);
28bab8
+
28bab8
+    TS_ASSERT_TRUE_MESSAGE(get_global_stop_on_not_reportable(), "Still true");
28bab8
+
28bab8
+    set_global_stop_on_not_reportable(false, 0);
28bab8
+
28bab8
+    TS_ASSERT_FALSE_MESSAGE(get_global_stop_on_not_reportable(), "Configuration accepted");
28bab8
+    TS_ASSERT_STRING_EQ(getenv(STOP_ON_NOT_REPORTABLE), "0", "Correct ENVIRONMENT value");
28bab8
+
28bab8
+    set_global_stop_on_not_reportable(true, 0);
28bab8
+
28bab8
+    TS_ASSERT_TRUE_MESSAGE(get_global_stop_on_not_reportable(), "Configuration sanity");
28bab8
+    TS_ASSERT_STRING_EQ(getenv(STOP_ON_NOT_REPORTABLE), "1", "Correct ENVIRONMENT value");
28bab8
+
28bab8
+    set_global_stop_on_not_reportable(false, 0);
28bab8
+
28bab8
+    TS_ASSERT_FALSE_MESSAGE(get_global_stop_on_not_reportable(), "Reverted back to False");
28bab8
+    TS_ASSERT_STRING_EQ(getenv(STOP_ON_NOT_REPORTABLE), "0", "Correct ENVIRONMENT value");
28bab8
+
28bab8
+    xsetenv(STOP_ON_NOT_REPORTABLE, "1");
28bab8
+
28bab8
+    TS_ASSERT_TRUE_MESSAGE(get_global_stop_on_not_reportable(), "Loaded from environment");
28bab8
+
28bab8
+    unsetenv(STOP_ON_NOT_REPORTABLE);
28bab8
+
28bab8
+    TS_ASSERT_TRUE_MESSAGE(get_global_stop_on_not_reportable(), "Reflects environment");
28bab8
+
28bab8
+    xsetenv(STOP_ON_NOT_REPORTABLE, "0");
28bab8
+
28bab8
+    TS_ASSERT_FALSE_MESSAGE(get_global_stop_on_not_reportable(), "Zero is false");
28bab8
+
28bab8
+    free_global_configuration();
28bab8
+}
28bab8
+TS_RETURN_MAIN
28bab8
+]])
28bab8
-- 
28bab8
1.8.3.1
28bab8