Skip to content

Commit b28cdfb

Browse files
michael-yujijakepetroules
authored andcommitted
use closefrom(2) on platforms supports it to reduce race condition window
1 parent ba273eb commit b28cdfb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/Commands/SwiftRunCommand.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,20 @@ public struct SwiftRunCommand: AsyncSwiftCommand {
312312
sigfillset(&sig_set_all)
313313
sigprocmask(SIG_UNBLOCK, &sig_set_all, nil)
314314

315+
#if os(FreeBSD) || os(OpenBSD)
316+
closefrom(3)
317+
#else
315318
#if os(Android)
316319
let number_fds = Int32(sysconf(_SC_OPEN_MAX))
317320
#else
318321
let number_fds = getdtablesize()
319-
#endif
322+
#endif /* os(Android) */
320323

321324
// 2. close all file descriptors.
322325
for i in 3..<number_fds {
323326
close(i)
324327
}
328+
#endif /* os(FreeBSD) || os(OpenBSD) */
325329
#endif
326330

327331
try TSCBasic.exec(path: path, args: args)

0 commit comments

Comments
 (0)