From b28cdfbcf4458e603043fbfd608d4baf97559664 Mon Sep 17 00:00:00 2001 From: Michael Chiu Date: Mon, 6 Jan 2025 18:17:17 -0800 Subject: [PATCH] use closefrom(2) on platforms supports it to reduce race condition window --- Sources/Commands/SwiftRunCommand.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Commands/SwiftRunCommand.swift b/Sources/Commands/SwiftRunCommand.swift index 5bc94fb8bdc..1acf3ddebaa 100644 --- a/Sources/Commands/SwiftRunCommand.swift +++ b/Sources/Commands/SwiftRunCommand.swift @@ -312,16 +312,20 @@ public struct SwiftRunCommand: AsyncSwiftCommand { sigfillset(&sig_set_all) sigprocmask(SIG_UNBLOCK, &sig_set_all, nil) + #if os(FreeBSD) || os(OpenBSD) + closefrom(3) + #else #if os(Android) let number_fds = Int32(sysconf(_SC_OPEN_MAX)) #else let number_fds = getdtablesize() - #endif + #endif /* os(Android) */ // 2. close all file descriptors. for i in 3..