perf(uucore): call rt_sigaction once not 62 times

`./coreutils true` becomes 6% faster. For some unknown reason,
`capture_startup_state` runs 62 times, so I'll just hotfix it to
immediately return from the second time onwards.

When 2d7a3bf2e0 introduced the fcntl
calls, each group of 3 calls was repeated 4 times. Some time later, it
became 62 times. Now it runs only 1 time.
This commit is contained in:
Daniel Tang
2026-04-04 10:34:54 +02:00
committed by Sylvestre Ledru
parent 0260f21974
commit 49e7a6b532
+8
View File
@@ -538,6 +538,9 @@ static STDERR_WAS_CLOSED: AtomicBool = AtomicBool::new(false);
#[cfg(unix)]
static SIGPIPE_WAS_IGNORED: AtomicBool = AtomicBool::new(false);
#[cfg(unix)]
static STARTUP_STATE_WAS_CAPTURED: AtomicBool = AtomicBool::new(false);
/// Captures stdio and SIGPIPE state at process initialization, before main() runs.
///
/// # Safety
@@ -549,6 +552,11 @@ pub unsafe extern "C" fn capture_startup_state() {
use std::mem::MaybeUninit;
use std::ptr;
// No spinlock because we're single-threaded at this point
if STARTUP_STATE_WAS_CAPTURED.swap(true, Ordering::Relaxed) {
return;
}
// Capture stdio state
unsafe {
STDIN_WAS_CLOSED.store(