Skip to content

Commit

Permalink
use closefrom(2) on platforms supports it to reduce race condition wi…
Browse files Browse the repository at this point in the history
…ndow
  • Loading branch information
michael-yuji authored and jakepetroules committed Jan 11, 2025
1 parent ba273eb commit b28cdfb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/Commands/SwiftRunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<number_fds {
close(i)
}
#endif /* os(FreeBSD) || os(OpenBSD) */
#endif

try TSCBasic.exec(path: path, args: args)
Expand Down

0 comments on commit b28cdfb

Please sign in to comment.