Blame SOURCES/0210-ccpp-add-IgnoredPath-option.patch

06486d
From 4f1770991a3b5da7dadd4c4e9b1a48c7d96f6808 Mon Sep 17 00:00:00 2001
06486d
From: Matej Habrnal <mhabrnal@redhat.com>
06486d
Date: Mon, 21 Mar 2016 15:25:35 +0100
06486d
Subject: [PATCH] ccpp: add IgnoredPath option
06486d
06486d
ABRT will ignore crashes in executables for which absolute path matches one of
06486d
specified patterns.
06486d
06486d
Related to rhbz#1277848
06486d
06486d
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
06486d
---
06486d
 doc/abrt-CCpp.conf.txt     |  4 +++
06486d
 src/hooks/CCpp.conf        |  5 ++++
06486d
 src/hooks/abrt-hook-ccpp.c | 71 +++++++++++++++++++++++++++++++++-------------
06486d
 3 files changed, 61 insertions(+), 19 deletions(-)
06486d
06486d
diff --git a/doc/abrt-CCpp.conf.txt b/doc/abrt-CCpp.conf.txt
06486d
index 42981fd..4db4b54 100644
06486d
--- a/doc/abrt-CCpp.conf.txt
06486d
+++ b/doc/abrt-CCpp.conf.txt
06486d
@@ -39,6 +39,10 @@ SaveFullCore = 'yes' / 'no' ...::
06486d
    directory.
06486d
    Default is 'yes'.
06486d
 
06486d
+IgnoredPaths = /path/to/ignore/*, */another/ignored/path* ...::
06486d
+   ABRT will ignore crashes in executables whose absolute path matches one of
06486d
+   specified patterns.
06486d
+
06486d
 VerboseLog = NUM::
06486d
    Used to make the hook more verbose
06486d
 
06486d
diff --git a/src/hooks/CCpp.conf b/src/hooks/CCpp.conf
06486d
index 08d1b28..be55e05 100644
06486d
--- a/src/hooks/CCpp.conf
06486d
+++ b/src/hooks/CCpp.conf
06486d
@@ -32,3 +32,8 @@ SaveFullCore = yes
06486d
 # Specify where you want to store debuginfos (default: /var/cache/abrt-di)
06486d
 #
06486d
 #DebuginfoLocation = /var/cache/abrt-di
06486d
+
06486d
+# ABRT will ignore crashes in executables whose absolute path matches one of
06486d
+# specified patterns.
06486d
+#
06486d
+#IgnoredPaths =
06486d
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
06486d
index 9648b16..18cd608 100644
06486d
--- a/src/hooks/abrt-hook-ccpp.c
06486d
+++ b/src/hooks/abrt-hook-ccpp.c
06486d
@@ -18,6 +18,7 @@
06486d
     with this program; if not, write to the Free Software Foundation, Inc.,
06486d
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
06486d
 */
06486d
+#include <fnmatch.h>
06486d
 #include <sys/utsname.h>
06486d
 #include "libabrt.h"
06486d
 #include <selinux/selinux.h>
06486d
@@ -631,6 +632,19 @@ finito:
06486d
     return err;
06486d
 }
06486d
 
06486d
+static bool is_path_ignored(const GList *list, const char *path)
06486d
+{
06486d
+    const GList *li;
06486d
+    for (li = list; li != NULL; li = g_list_next(li))
06486d
+    {
06486d
+        if (fnmatch((char*)li->data, path, /*flags:*/ 0) == 0)
06486d
+        {
06486d
+            return true;
06486d
+        }
06486d
+    }
06486d
+    return false;
06486d
+}
06486d
+
06486d
 static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCoreBacktrace)
06486d
 {
06486d
     if (!setting_SaveFullCore && !setting_CreateCoreBacktrace)
06486d
@@ -643,6 +657,26 @@ static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCore
06486d
     return 0;
06486d
 }
06486d
 
06486d
+static void error_msg_not_process_crash(const char *pid_str, const char *process_str,
06486d
+        long unsigned uid, int signal_no, const char *signame, const char *message, ...)
06486d
+{
06486d
+    va_list p;
06486d
+    va_start(p, message);
06486d
+    char *message_full = xvasprintf(message, p);
06486d
+    va_end(p);
06486d
+
06486d
+    if (signame)
06486d
+        error_msg("Process %s (%s) of user %lu killed by SIG%s - %s", pid_str,
06486d
+                        process_str, uid, signame, message_full);
06486d
+    else
06486d
+        error_msg("Process %s (%s) of user %lu killed by signal %d - %s", pid_str,
06486d
+                        process_str, uid, signal_no, message_full);
06486d
+
06486d
+    free(message_full);
06486d
+
06486d
+    return;
06486d
+}
06486d
+
06486d
 int main(int argc, char** argv)
06486d
 {
06486d
     int err = 1;
06486d
@@ -666,6 +700,7 @@ int main(int argc, char** argv)
06486d
     bool setting_SaveBinaryImage;
06486d
     bool setting_SaveFullCore;
06486d
     bool setting_CreateCoreBacktrace;
06486d
+    GList *setting_ignored_paths = NULL;
06486d
     {
06486d
         map_string_t *settings = new_map_string();
06486d
         load_abrt_plugin_conf_file("CCpp.conf", settings);
06486d
@@ -677,6 +712,10 @@ int main(int argc, char** argv)
06486d
         value = get_map_string_item_or_NULL(settings, "SaveFullCore");
06486d
         setting_SaveFullCore = value ? string_to_bool(value) : true;
06486d
         value = get_map_string_item_or_NULL(settings, "CreateCoreBacktrace");
06486d
+        value = get_map_string_item_or_NULL(settings, "IgnoredPaths");
06486d
+        if (value)
06486d
+            setting_ignored_paths = parse_list(value);
06486d
+
06486d
         setting_CreateCoreBacktrace = value ? string_to_bool(value) : true;
06486d
         value = get_map_string_item_or_NULL(settings, "VerboseLog");
06486d
         if (value)
06486d
@@ -712,6 +751,8 @@ int main(int argc, char** argv)
06486d
     errno = 0;
06486d
     const char* signal_str = argv[1];
06486d
     int signal_no = xatoi_positive(signal_str);
06486d
+    const char *signame = NULL;
06486d
+    bool signal_is_fatal_bool = signal_is_fatal(signal_no, &signame);
06486d
     off_t ulimit_c = strtoull(argv[2], NULL, 10);
06486d
     if (ulimit_c < 0) /* unlimited? */
06486d
     {
06486d
@@ -753,6 +794,15 @@ int main(int argc, char** argv)
06486d
                         (long)pid, executable);
06486d
     }
06486d
 
06486d
+    const char *last_slash = strrchr(executable, '/');
06486d
+    if (executable && is_path_ignored(setting_ignored_paths, executable))
06486d
+    {
06486d
+        error_msg_not_process_crash(pid_str, last_slash + 1, (long unsigned)uid, signal_no,
06486d
+                signame, "ignoring (listed in 'IgnoredPaths')");
06486d
+
06486d
+        return 0;
06486d
+    }
06486d
+
06486d
     user_pwd = get_cwd(pid);
06486d
     log_notice("user_pwd:'%s'", user_pwd);
06486d
 
06486d
@@ -793,24 +843,8 @@ int main(int argc, char** argv)
06486d
         return create_user_core(user_core_fd, pid, ulimit_c);
06486d
     }
06486d
 
06486d
-    const char *signame = NULL;
06486d
-    switch (signal_no)
06486d
-    {
06486d
-        case SIGILL : signame = "ILL" ; break;
06486d
-        case SIGFPE : signame = "FPE" ; break;
06486d
-        case SIGSEGV: signame = "SEGV"; break;
06486d
-        case SIGBUS : signame = "BUS" ; break; //Bus error (bad memory access)
06486d
-        case SIGABRT: signame = "ABRT"; break; //usually when abort() was called
06486d
-    // We have real-world reports from users who see buggy programs
06486d
-    // dying with SIGTRAP, uncommented it too:
06486d
-        case SIGTRAP: signame = "TRAP"; break; //Trace/breakpoint trap
06486d
-    // These usually aren't caused by bugs:
06486d
-      //case SIGQUIT: signame = "QUIT"; break; //Quit from keyboard
06486d
-      //case SIGSYS : signame = "SYS" ; break; //Bad argument to routine (SVr4)
06486d
-      //case SIGXCPU: signame = "XCPU"; break; //CPU time limit exceeded (4.2BSD)
06486d
-      //case SIGXFSZ: signame = "XFSZ"; break; //File size limit exceeded (4.2BSD)
06486d
-        default: return create_user_core(user_core_fd, pid, ulimit_c); // not a signal we care about
06486d
-    }
06486d
+    if (!signal_is_fatal_bool)
06486d
+        return create_user_core(user_core_fd, pid, ulimit_c); // not a signal we care about
06486d
 
06486d
     if (!daemon_is_ok())
06486d
     {
06486d
@@ -839,7 +873,6 @@ int main(int argc, char** argv)
06486d
         return create_user_core(user_core_fd, pid, ulimit_c);
06486d
     }
06486d
 
06486d
-    const char *last_slash = strrchr(executable, '/');
06486d
     if (last_slash && strncmp(++last_slash, "abrt", 4) == 0)
06486d
     {
06486d
         if (g_settings_debug_level == 0)
06486d
-- 
06486d
1.8.3.1
06486d