Skip to content

[Support] Fix Process::PreventCoreFiles() when coredumps are piped #83703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion llvm/lib/Support/Unix/Process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,26 @@ 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, which disables coredumps when
// piping. 1 byte is too small for any kind of valid core dump, so it
// also disables coredumps if kernel.core_pattern creates files directly.
// While most piped coredump handlers do respect the crashing processes'
// RLIMIT_CORE, this is notable not the case for Debian's systemd-coredump
// due to a local patch that changes sysctl.d/50-coredump.conf to ignore
// the specified limit and instead use RLIM_INFINITY.
//
// The alternative to using RLIMIT_CORE=1 would be to use prctl() with the
// PR_SET_DUMPABLE flag, however that also prevents ptrace(), so makes it
// impossible to attach a debugger.
rlim.rlim_cur = std::min<rlim_t>(1, rlim.rlim_max);
#else
rlim.rlim_cur = 0;
#endif
setrlimit(RLIMIT_CORE, &rlim);
#endif

Expand Down