Skip to content

Commit

Permalink
ccpp: add IgnoredPath option
Browse files Browse the repository at this point in the history
ABRT will ignore crashes in executables for which absolute path matches one of
specified patterns.

Related to rhbz#1208713

Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
  • Loading branch information
Matej Habrnal committed Dec 10, 2015
1 parent 4951127 commit fc9ea4b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/abrt-CCpp.conf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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

Expand Down
5 changes: 5 additions & 0 deletions src/hooks/CCpp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ SaveFullCore = yes
# is not running.
#
# StandaloneHook = yes

# ABRT will ignore crashes in executables whose absolute path matches one of
# specified patterns.
#
#IgnoredPaths =
51 changes: 49 additions & 2 deletions src/hooks/abrt-hook-ccpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fnmatch.h>
#include <sys/utsname.h>
#include "libabrt.h"
#include <selinux/selinux.h>
Expand Down Expand Up @@ -457,6 +458,19 @@ static int create_user_core(int user_core_fd, pid_t pid, off_t ulimit_c)
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)
Expand Down Expand Up @@ -497,6 +511,26 @@ static int save_crashing_binary(pid_t pid, struct dump_dir *dd)
return fsync(dst_fd) != 0 || close(dst_fd) != 0 || sz < 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)
{
/* Kernel starts us with all fd's closed.
Expand All @@ -522,6 +556,7 @@ int main(int argc, char** argv)
bool setting_CreateCoreBacktrace;
bool setting_SaveContainerizedPackageData;
bool setting_StandaloneHook;
GList *setting_ignored_paths = NULL;
{
map_string_t *settings = new_map_string();
load_abrt_plugin_conf_file("CCpp.conf", settings);
Expand All @@ -534,6 +569,9 @@ int main(int argc, char** argv)
setting_SaveFullCore = value ? string_to_bool(value) : true;
value = get_map_string_item_or_NULL(settings, "CreateCoreBacktrace");
setting_CreateCoreBacktrace = value ? string_to_bool(value) : true;
value = get_map_string_item_or_NULL(settings, "IgnoredPaths");
if (value)
setting_ignored_paths = parse_list(value);

value = get_map_string_item_or_NULL(settings, "SaveContainerizedPackageData");
setting_SaveContainerizedPackageData = value && string_to_bool(value);
Expand Down Expand Up @@ -582,6 +620,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? */
{
Expand Down Expand Up @@ -623,6 +663,14 @@ int main(int argc, char** argv)
(long)pid, executable);
}

if (executable && is_path_ignored(setting_ignored_paths, executable))
{
error_msg_not_process_crash(pid_str, argv[7], (long unsigned)uid, signal_no,
signame, "ignoring (listed in 'IgnoredPaths')");

return 0;
}

user_pwd = get_cwd(pid); /* may be NULL on error */
log_notice("user_pwd:'%s'", user_pwd);

Expand Down Expand Up @@ -665,8 +713,7 @@ int main(int argc, char** argv)
return create_user_core(user_core_fd, pid, ulimit_c);
}

const char *signame = NULL;
if (!signal_is_fatal(signal_no, &signame))
if (!signal_is_fatal_bool)
return create_user_core(user_core_fd, pid, ulimit_c); // not a signal we care about

const int abrtd_running = daemon_is_ok();
Expand Down

0 comments on commit fc9ea4b

Please sign in to comment.