From 3f15df9e3ccdcee831d4cde691eb671ebfeb4e79 Mon Sep 17 00:00:00 2001 From: Yibo Zhuang Date: Mon, 7 Sep 2026 09:37:51 -0700 Subject: [PATCH] Preserve stdout when running Softnet without a control FD (#1329) --- Sources/tart/Network/Softnet.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/tart/Network/Softnet.swift b/Sources/tart/Network/Softnet.swift index 4159514..b23dcfe 100644 --- a/Sources/tart/Network/Softnet.swift +++ b/Sources/tart/Network/Softnet.swift @@ -11,14 +11,13 @@ enum SoftnetError: Error { class Softnet: Network { private let process = Process() + private var controlFileHandle: FileHandle? private var monitorTask: Task? = nil private let monitorTaskFinished = ManagedAtomic(false) let vmFD: Int32 init(vmMACAddress: String, extraArguments: [String] = [], controlFD: Int32? = nil) throws { - var controlFileHandle: FileHandle? - if let controlFD = controlFD { guard controlFD > STDERR_FILENO else { throw SoftnetError.InitializationFailed(why: "Softnet control file descriptor must be greater than 2") @@ -95,7 +94,7 @@ class Softnet: Network { } func run(_ sema: AsyncSemaphore) throws { - defer { try? (process.standardOutput as? FileHandle)?.close() } + defer { try? controlFileHandle?.close() } try process.run()