diff --git a/vminitd/Sources/vminitd/ManagedProcess.swift b/vminitd/Sources/vminitd/ManagedProcess.swift index 7196a365..cb359e81 100644 --- a/vminitd/Sources/vminitd/ManagedProcess.swift +++ b/vminitd/Sources/vminitd/ManagedProcess.swift @@ -25,17 +25,16 @@ import Logging import Synchronization final class ManagedProcess: Sendable { - let id: String - - private let log: Logger - private let command: Command - private let state: Mutex - private let owningPid: Int32? - private let ackPipe: Pipe - private let syncPipe: Pipe - private let terminal: Bool - private let bundle: ContainerizationOCI.Bundle - private let cgroupManager: Cgroup2Manager? + // swiftlint: disable type_name + protocol IO { + func attach(pid: Int32, fd: Int32) throws + func start(process: inout Command) throws + func resize(size: Terminal.Size) throws + func close() throws + func closeStdin() throws + func closeAfterExec() throws + } + // swiftlint: enable type_name struct ExitStatus { var exitStatus: Int32 @@ -53,26 +52,27 @@ final class ManagedProcess: Sendable { var pid: Int32 = 0 } + private static let ackPid = "AckPid" + private static let ackConsole = "AckConsole" + + let id: String + + private let log: Logger + private let command: Command + private let state: Mutex + private let owningPid: Int32? + private let ackPipe: Pipe + private let syncPipe: Pipe + private let terminal: Bool + private let bundle: ContainerizationOCI.Bundle + private let cgroupManager: Cgroup2Manager? + var pid: Int32 { self.state.withLock { $0.pid } } - // swiftlint: disable type_name - protocol IO { - func attach(pid: Int32, fd: Int32) throws - func start(process: inout Command) throws - func resize(size: Terminal.Size) throws - func close() throws - func closeStdin() throws - func closeAfterExec() throws - } - // swiftlint: enable type_name - - private static let ackPid = "AckPid" - private static let ackConsole = "AckConsole" - init( id: String, stdio: HostStdio, diff --git a/vminitd/Sources/vminitd/OSFile.swift b/vminitd/Sources/vminitd/OSFile.swift index 81a3d0e2..c62a8009 100644 --- a/vminitd/Sources/vminitd/OSFile.swift +++ b/vminitd/Sources/vminitd/OSFile.swift @@ -17,8 +17,6 @@ import Foundation struct OSFile: Sendable { - private let fd: Int32 - enum IOAction: Equatable { case eof case again @@ -27,6 +25,8 @@ struct OSFile: Sendable { case error(_ errno: Int32) } + private let fd: Int32 + var closed: Bool { Foundation.fcntl(fd, F_GETFD) == -1 && errno == EBADF } diff --git a/vminitd/Sources/vminitd/Server.swift b/vminitd/Sources/vminitd/Server.swift index b2052aa8..17a1fe54 100644 --- a/vminitd/Sources/vminitd/Server.swift +++ b/vminitd/Sources/vminitd/Server.swift @@ -22,10 +22,6 @@ import NIOCore import NIOPosix final class Initd: Sendable { - let log: Logger - let state: State - let group: EventLoopGroup - actor State { var containers: [String: ManagedContainer] = [:] var proxies: [String: VsockProxy] = [:] @@ -80,6 +76,10 @@ final class Initd: Sendable { } } + let log: Logger + let state: State + let group: EventLoopGroup + init(log: Logger, group: EventLoopGroup) { self.log = log self.group = group diff --git a/vminitd/Sources/vminitd/VsockProxy.swift b/vminitd/Sources/vminitd/VsockProxy.swift index a2fb92b5..2c2c637e 100644 --- a/vminitd/Sources/vminitd/VsockProxy.swift +++ b/vminitd/Sources/vminitd/VsockProxy.swift @@ -30,6 +30,16 @@ actor VsockProxy { case vsock } + public let id: String + private let path: URL + private let action: Action + private let port: UInt32 + private let udsPerms: UInt32? + private let log: Logger? + + private var listener: Socket? + private var task: Task<(), Never>? + init( id: String, action: Action, @@ -45,16 +55,6 @@ actor VsockProxy { self.udsPerms = udsPerms self.log = log } - - public let id: String - private let path: URL - private let action: Action - private let port: UInt32 - private let udsPerms: UInt32? - private let log: Logger? - - private var listener: Socket? - private var task: Task<(), Never>? } extension VsockProxy {