From 1acc6126870e0299c3833ffeb98c83629ef99c5e Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Tue, 6 Aug 2024 20:57:29 -0500 Subject: [PATCH] tests: Avoid generating cores in softsig-helper Our opr/softsig-t tests run softsig-helper to generate SIGSEGV and SIGBUS signals (among other things), which may generate core files (if 'ulimit -c' is nonzero). The core files are useless, since we expect those signals to be generated. Usually the core files are generated in the build tree (where we run the tests from), which is a minor annoyance. But some systems may be configured to store core files in a central location (e.g. /var/lib/systemd/coredump), which starts to build up over time after many builds. To avoid this, prevent core files from being generated in softsig-helper for the SIGSEGV and SIGBUS cases by calling setrlimit(). Change-Id: Ice71e79009cf2b44d4cbe32233d3a7ee12e08d2d Reviewed-on: https://gerrit.openafs.org/15795 Reviewed-by: Mark Vitale Tested-by: Mark Vitale Reviewed-by: Michael Meffie --- tests/opr/softsig-helper.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/opr/softsig-helper.c b/tests/opr/softsig-helper.c index 416f07ca1f..12c36559c6 100644 --- a/tests/opr/softsig-helper.c +++ b/tests/opr/softsig-helper.c @@ -32,6 +32,9 @@ #include #include #include +#ifdef HAVE_SYS_RESOURCE_H +# include +#endif #include #include @@ -79,8 +82,27 @@ mythread(void *arg) { return NULL; } +static void +disable_core(void) +{ +#ifdef HAVE_GETRLIMIT + struct rlimit rlp; + + memset(&rlp, 0, sizeof(rlp)); + + /* + * Set our core limit to 0 for SIGSEGV/SIGBUS, so we don't litter core + * files around when running the test. + */ + if (setrlimit(RLIMIT_CORE, &rlp) < 0) { + perror("setrlimit(RLIMIT_CORE)"); + } +#endif +} + static void * crashingThread(void *arg) { + disable_core(); *(char *)1 = 'a'; /* raises SIGSEGV */ return NULL; /* Ha! */ } @@ -90,6 +112,7 @@ thrownUnderTheBusThread(void *arg) { char *path = arg; int fd = open(path, O_CREAT | O_APPEND, 0660); char *m = mmap(NULL, 10, PROT_WRITE, MAP_PRIVATE, fd, 0); + disable_core(); *(m + 11) = 'a'; /* raises SIGBUS */ return NULL; }