Closed
Description
Previous ID | SR-11354 |
Radar | rdar://problem/54600455 |
Original Reporter | @weissi |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
Additional Detail from JIRA
Votes | 1 |
Component/s | Foundation |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: 6bb31ba0bafc6fc1de60d481ac760a2d
Issue Description:
The following program when compiled and run like swiftc test.swift && ./test
should print
ok1
the line above should read 'ok1'
which is does on Darwin. The reason is that Foundation.Process
is supposed to close the parents file descriptors so that they're not inherited into the child.
However, on Linux, this is not the case:
$ docker run -it --rm -v "$PWD:$PWD" -w "$PWD" swift:5.0.2 bash -c 'swiftc test.swift && ./test'
ok1
THIS IS BAD
the line above should read 'ok1'
#if os(Linux)
import Glibc
#else
import Darwin
#endif
import Foundation
if let stdout2 = CommandLine.arguments.dropFirst().first.flatMap(CInt.init) {
write(stdout2, "THIS IS BAD\n", 12)
print("the line above should read 'ok1'")
} else {
let stdout2 = dup(1)
write(stdout2, "ok1\n", 4)
let p = Process()
p.executableURL = URL(fileURLWithPath: CommandLine.arguments.first!)
p.arguments = [ "\(stdout2)" ]
try! p.run()
p.waitUntilExit()
}