arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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