From d3ca580a6d638d780bb91325626f2f65bf773439 Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Thu, 3 Jul 2025 07:44:01 -0700 Subject: [PATCH] ContainerizationOS: Alter Terminal.close() (#195) Change to calling close on the underlying FileHandle as it already has logic to set the fd to an invalid value and prevent double closes. --- Sources/ContainerizationOS/Terminal.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/ContainerizationOS/Terminal.swift b/Sources/ContainerizationOS/Terminal.swift index 7fffa558..7b4afc33 100644 --- a/Sources/ContainerizationOS/Terminal.swift +++ b/Sources/ContainerizationOS/Terminal.swift @@ -176,7 +176,16 @@ extension Terminal { extension Terminal { /// Close this pty's file descriptor. public func close() throws { - try fromSyscall(Foundation.close(self.descriptor)) + do { + // Use FileHandle's close directly as it sets the underlying fd in the object + // to -1 for us. + try self.handle.close() + } catch { + if let error = error as NSError?, error.domain == NSPOSIXErrorDomain { + throw POSIXError(.init(rawValue: Int32(error.code))!) + } + throw error + } } /// Reset the pty to its initial state.