From dde834dbb1295fbc710d88c584f5190bf6af2d30 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Sat, 2 Mar 2024 19:15:16 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- llvm/lib/Support/Unix/Process.inc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc index f94eec6963c18..ac80c199d028c 100644 --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -143,7 +143,18 @@ void Process::GetTimeUsage(TimePoint<> &elapsed, void Process::PreventCoreFiles() { #if HAVE_SETRLIMIT struct rlimit rlim; - rlim.rlim_cur = rlim.rlim_max = 0; + getrlimit(RLIMIT_CORE, &rlim); +#ifdef __linux__ + // On Linux, if the kernel.core_pattern sysctl starts with a '|' (i.e. it + // is being piped to a coredump handler such as systemd-coredumpd), the + // kernel ignores RLIMIT_CORE (since we aren't creating a file in the file + // system) except for the magic value of 1, that disables coredumps when + // piping. 1 byte is also too small for any kind of valid core dump, so it + // also disables coredumps if kernel.core_pattern creates files directly. + rlim.rlim_cur = std::min(1, rlim.rlim_max); +#else + rlim.rlim_cur = 0; +#endif setrlimit(RLIMIT_CORE, &rlim); #endif