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

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