Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Sources/CLI/RunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,28 @@ struct ProcessIO {
var stdio = [FileHandle?](repeating: nil, count: 3)

let stdin: Pipe? = {
if !interactive && !tty {
if !interactive {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ProcessIO live in the CLI target, or ContainerClient, at this point?

return nil
}
return Pipe()
}()

if let stdin {
if interactive {
let pin = FileHandle.standardInput
let stdinOSFile = OSFile(fd: pin.fileDescriptor)
let pipeOSFile = OSFile(fd: stdin.fileHandleForWriting.fileDescriptor)
try stdinOSFile.makeNonBlocking()
nonisolated(unsafe) let buf = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: Int(getpagesize()))

pin.readabilityHandler = { _ in
Self.streamStdin(
from: stdinOSFile,
to: pipeOSFile,
buffer: buf,
) {
pin.readabilityHandler = nil
buf.deallocate()
try? stdin.fileHandleForWriting.close()
}
let pin = FileHandle.standardInput
let stdinOSFile = OSFile(fd: pin.fileDescriptor)
let pipeOSFile = OSFile(fd: stdin.fileHandleForWriting.fileDescriptor)
try stdinOSFile.makeNonBlocking()
nonisolated(unsafe) let buf = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: Int(getpagesize()))

pin.readabilityHandler = { _ in
Self.streamStdin(
from: stdinOSFile,
to: pipeOSFile,
buffer: buf,
) {
pin.readabilityHandler = nil
buf.deallocate()
try? stdin.fileHandleForWriting.close()
}
}
stdio[0] = stdin.fileHandleForReading
Expand Down