diff --git a/vminitd/Sources/vminitd/CgroupManager.swift b/vminitd/Sources/vminitd/CgroupManager.swift index 17a93400..1f410c1c 100644 --- a/vminitd/Sources/vminitd/CgroupManager.swift +++ b/vminitd/Sources/vminitd/CgroupManager.swift @@ -19,7 +19,7 @@ import Foundation import Logging import Musl -enum CgroupController: String { +enum Cgroup2Controller: String { case pids case memory case cpuset @@ -30,7 +30,7 @@ enum CgroupController: String { // Extremely simple cgroup manager. Our needs are simple for now, and this is // reflected in the type. -internal struct CgroupManager { +internal struct Cgroup2Manager { static let defaultMountPoint = URL(filePath: "/sys/fs/cgroup") static let killFile = "cgroup.kill" @@ -71,7 +71,7 @@ internal struct CgroupManager { if fd == -1 { throw Error.errno(errno: errno, message: "failed to open \(file.path)") } - defer { Musl.close(fd) } + defer { close(fd) } let bytes = Array(value.utf8) let res = Syscall.retrying { @@ -82,7 +82,7 @@ internal struct CgroupManager { } } - func toggleSubtreeControllers(controllers: [CgroupController], enable: Bool) throws { + func toggleSubtreeControllers(controllers: [Cgroup2Controller], enable: Bool) throws { let value = controllers.map { (enable ? "+" : "-") + $0.rawValue }.joined(separator: " ") let mountComponents = self.mountPoint.pathComponents let pathComponents = self.path.pathComponents @@ -134,7 +134,7 @@ internal struct CgroupManager { } } -extension CgroupManager { +extension Cgroup2Manager { enum Error: Swift.Error, CustomStringConvertible { case errno(errno: Int32, message: String) diff --git a/vminitd/Sources/vminitd/ManagedContainer.swift b/vminitd/Sources/vminitd/ManagedContainer.swift index 293145c0..ed15a2ae 100644 --- a/vminitd/Sources/vminitd/ManagedContainer.swift +++ b/vminitd/Sources/vminitd/ManagedContainer.swift @@ -24,7 +24,7 @@ actor ManagedContainer { let id: String let initProcess: ManagedProcess - private let cgroupManager: CgroupManager + private let cgroupManager: Cgroup2Manager private let log: Logger private let bundle: ContainerizationOCI.Bundle private var execs: [String: ManagedProcess] = [:] @@ -52,7 +52,7 @@ actor ManagedContainer { cgroupsPath = "/container/\(id)" } - let cgManager = try CgroupManager( + let cgManager = try Cgroup2Manager( path: URL(filePath: cgroupsPath), logger: log ) diff --git a/vminitd/Sources/vminitd/ManagedProcess.swift b/vminitd/Sources/vminitd/ManagedProcess.swift index dbe1b53b..ebec8736 100644 --- a/vminitd/Sources/vminitd/ManagedProcess.swift +++ b/vminitd/Sources/vminitd/ManagedProcess.swift @@ -34,7 +34,7 @@ final class ManagedProcess: Sendable { private let syncPipe: FileHandle private let terminal: Bool private let bundle: ContainerizationOCI.Bundle - private let cgroupManager: CgroupManager + private let cgroupManager: Cgroup2Manager private struct State { init(io: IO) { @@ -75,7 +75,7 @@ final class ManagedProcess: Sendable { id: String, stdio: HostStdio, bundle: ContainerizationOCI.Bundle, - cgroupManager: CgroupManager, + cgroupManager: Cgroup2Manager, owningPid: Int32? = nil, log: Logger ) throws {