Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions vminitd/Sources/vmexec/ExecCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the Containerization project authors.
// Copyright © 2025-2026 Apple Inc. and the Containerization project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,16 +36,13 @@ struct ExecCommand: ParsableCommand {

func run() throws {
do {
LoggingSystem.bootstrap(App.standardError)
let log = Logger(label: "vmexec")

let src = URL(fileURLWithPath: processPath)
let processBytes = try Data(contentsOf: src)
let process = try JSONDecoder().decode(
ContainerizationOCI.Process.self,
from: processBytes
)
try execInNamespaces(process: process, log: log)
try execInNamespaces(process: process)
} catch {
App.writeError(error)
throw error
Expand All @@ -58,10 +55,7 @@ struct ExecCommand: ParsableCommand {
}
}

private func execInNamespaces(
process: ContainerizationOCI.Process,
log: Logger
) throws {
private func execInNamespaces(process: ContainerizationOCI.Process) throws {
let syncPipe = FileHandle(fileDescriptor: 3)
let ackPipe = FileHandle(fileDescriptor: 4)

Expand Down
14 changes: 5 additions & 9 deletions vminitd/Sources/vmexec/RunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,21 @@ struct RunCommand: ParsableCommand {

mutating func run() throws {
do {
LoggingSystem.bootstrap(App.standardError)
let log = Logger(label: "vmexec")

let spec: ContainerizationOCI.Spec
do {
let bundle = try ContainerizationOCI.Bundle.load(path: URL(filePath: bundlePath))
spec = try bundle.loadConfig()
} catch {
throw App.Failure(message: "failed to load OCI bundle at \(bundlePath): \(error)")
}
try execInNamespace(spec: spec, log: log)
try execInNamespace(spec: spec)
} catch {
App.writeError(error)
throw error
}
}

private func childRootSetup(rootfs: ContainerizationOCI.Root, mounts: [ContainerizationOCI.Mount], log: Logger) throws {
private func childRootSetup(rootfs: ContainerizationOCI.Root, mounts: [ContainerizationOCI.Mount]) throws {
// setup rootfs
try prepareRoot(rootfs: rootfs.path)
try mountRootfs(rootfs: rootfs.path, mounts: mounts)
Expand Down Expand Up @@ -90,7 +87,6 @@ struct RunCommand: ParsableCommand {
spec: ContainerizationOCI.Spec,
ackPipe: FileHandle,
syncPipe: FileHandle,
log: Logger
) throws {
guard let process = spec.process else {
throw App.Failure(message: "no process configuration found in runtime spec")
Expand Down Expand Up @@ -119,7 +115,7 @@ struct RunCommand: ParsableCommand {
throw App.Errno(stage: "setsid()")
}

try childRootSetup(rootfs: root, mounts: spec.mounts, log: log)
try childRootSetup(rootfs: root, mounts: spec.mounts)

if process.terminal {
let pty = try Console()
Expand Down Expand Up @@ -223,7 +219,7 @@ struct RunCommand: ParsableCommand {
return unshareFlags
}

private func execInNamespace(spec: ContainerizationOCI.Spec, log: Logger) throws {
private func execInNamespace(spec: ContainerizationOCI.Spec) throws {
let syncPipe = FileHandle(fileDescriptor: 3)
let ackPipe = FileHandle(fileDescriptor: 4)

Expand All @@ -241,7 +237,7 @@ struct RunCommand: ParsableCommand {
}

if processID == 0 { // child
try childSetup(spec: spec, ackPipe: ackPipe, syncPipe: syncPipe, log: log)
try childSetup(spec: spec, ackPipe: ackPipe, syncPipe: syncPipe)
} else { // parent process
// Setup cgroup before child enters cgroup namespace
if let linux = spec.linux {
Expand Down
11 changes: 1 addition & 10 deletions vminitd/Sources/vmexec/vmexec.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the Containerization project authors.
// Copyright © 2025-2026 Apple Inc. and the Containerization project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,15 +41,6 @@ struct App: ParsableCommand {
RunCommand.self,
]
)

static let standardErrorLock = NSLock()

@Sendable
static func standardError(label: String) -> StreamLogHandler {
standardErrorLock.withLock {
StreamLogHandler.standardError(label: label)
}
}
}

extension App {
Expand Down