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

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