Skip to content

Commit bf1479e

Browse files
authored
Set RLIMIT_CORE=1 instead of =0 on Linux. (#737)
1 parent 050d2f2 commit bf1479e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ public struct ExitTest: Sendable, ~Copyable {
5151
EXCEPTION_DEFAULT,
5252
THREAD_STATE_NONE
5353
)
54-
#elseif os(Linux) || os(FreeBSD)
55-
// On Linux and FreeBSD, disable the generation of core files (although they
56-
// will often be disabled by default.) If a particular Linux distro performs
57-
// additional crash diagnostics, we may want to special-case them as well if we can.
54+
#elseif os(Linux)
55+
// On Linux, disable the generation of core files. They may or may not be
56+
// disabled by default; if they are enabled, they significantly slow down
57+
// the performance of exit tests. The kernel special-cases RLIMIT_CORE=1 to
58+
// mean core files should not be generated even if they are being written to
59+
// a pipe instead of a regular file; that gets us our performance back.
60+
// SEE: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/coredump.c#n610
61+
var rl = rlimit(rlim_cur: 1, rlim_max: 1)
62+
_ = setrlimit(CInt(RLIMIT_CORE.rawValue), &rl)
63+
#elseif os(FreeBSD)
64+
// As with Linux, disable the generation core files. FreeBSD does not, as
65+
// far as I can tell, special-case RLIMIT_CORE=1.
5866
var rl = rlimit(rlim_cur: 0, rlim_max: 0)
5967
_ = setrlimit(CInt(RLIMIT_CORE.rawValue), &rl)
6068
#elseif os(Windows)
@@ -63,6 +71,8 @@ public struct ExitTest: Sendable, ~Copyable {
6371
// these functions, so we don't attempt to preserve any previously-set bits.
6472
_ = SetErrorMode(UINT(SEM_NOGPFAULTERRORBOX))
6573
_ = WerSetFlags(DWORD(WER_FAULT_REPORTING_NO_UI))
74+
#else
75+
#warning("Platform-specific implementation missing: unable to disable crash reporting")
6676
#endif
6777
}
6878

0 commit comments

Comments
 (0)