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