diff --git a/vminitd/Package.resolved b/vminitd/Package.resolved index a5c8dcdd..dbbf216e 100644 --- a/vminitd/Package.resolved +++ b/vminitd/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "317bd17e5e8ea1d37ffc5ec5f87172d8d348613454782e2fe0ac36ae707e87f9", + "originHash" : "4038f23a0edd12a9ff5bf2cae9327f6ac704134c6d503e0fd08ab254c601cb75", "pins" : [ { "identity" : "async-http-client", @@ -195,8 +195,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "61e4ca4b81b9e09e2ec863b00c340eb13497dac6", - "version" : "1.5.0" + "revision" : "395a77f0aa927f0ff73941d7ac35f2b46d47c9db", + "version" : "1.6.3" } } ], diff --git a/vminitd/Package.swift b/vminitd/Package.swift index c47d3f75..75dae5d1 100644 --- a/vminitd/Package.swift +++ b/vminitd/Package.swift @@ -29,7 +29,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"), - .package(url: "https://github.com/apple/swift-system.git", from: "1.4.0"), + .package(url: "https://github.com/apple/swift-system.git", from: "1.6.3"), .package(name: "containerization", path: "../"), ], targets: [ @@ -63,6 +63,7 @@ let package = Package( dependencies: [ .product(name: "Logging", package: "swift-log"), .product(name: "ArgumentParser", package: "swift-argument-parser"), + .product(name: "SystemPackage", package: "swift-system"), .product(name: "Containerization", package: "containerization"), .product(name: "ContainerizationOS", package: "containerization"), "LCShim", diff --git a/vminitd/Sources/vmexec/Console.swift b/vminitd/Sources/vmexec/Console.swift index 034955c8..fddc28e6 100644 --- a/vminitd/Sources/vmexec/Console.swift +++ b/vminitd/Sources/vmexec/Console.swift @@ -14,7 +14,7 @@ // limitations under the License. //===----------------------------------------------------------------------===// -import Foundation +import FoundationEssentials import Musl class Console { diff --git a/vminitd/Sources/vmexec/ExecCommand.swift b/vminitd/Sources/vmexec/ExecCommand.swift index 701d82c6..b2f90133 100644 --- a/vminitd/Sources/vmexec/ExecCommand.swift +++ b/vminitd/Sources/vmexec/ExecCommand.swift @@ -17,10 +17,11 @@ import ArgumentParser import ContainerizationOCI import ContainerizationOS -import Foundation +import FoundationEssentials import LCShim import Logging import Musl +import SystemPackage struct ExecCommand: ParsableCommand { static let configuration = CommandConfiguration( @@ -56,8 +57,8 @@ struct ExecCommand: ParsableCommand { } private func execInNamespaces(process: ContainerizationOCI.Process) throws { - let syncPipe = FileHandle(fileDescriptor: 3) - let ackPipe = FileHandle(fileDescriptor: 4) + let syncPipe = FileDescriptor(rawValue: 3) + let ackPipe = FileDescriptor(rawValue: 4) let pidFd = CZ_pidfd_open(Int32(parentPid), 0) guard pidFd > 0 else { @@ -79,12 +80,14 @@ struct ExecCommand: ParsableCommand { if processID == 0 { // child // Wait for the grandparent to tell us that they acked our pid. - guard let data = try ackPipe.read(upToCount: App.ackPid.count) else { - throw App.Failure(message: "read ack pipe") + var pidAckBuffer = [UInt8](repeating: 0, count: App.ackPid.count) + let pidAckBytesRead = try pidAckBuffer.withUnsafeMutableBytes { buffer in + try ackPipe.read(into: buffer) } - guard let pidAckStr = String(data: data, encoding: .utf8) else { - throw App.Failure(message: "convert ack pipe data to string") + guard pidAckBytesRead > 0 else { + throw App.Failure(message: "read ack pipe") } + let pidAckStr = String(decoding: pidAckBuffer[.. 0 else { + throw App.Failure(message: "read ack pipe") } + let consoleAckStr = String(decoding: consoleAckBuffer[.. 0 else { + throw App.Failure(message: "read ack pipe") } + let pidAckStr = String(decoding: pidAckBuffer[.. 0 else { + throw App.Failure(message: "read ack pipe") } + let consoleAckStr = String(decoding: consoleAckBuffer[..