Skip to content

Commit 1ed9bfb

Browse files
committed
Add native property to LinuxProcess
LinuxProcess with `native` property runs outside containerized environment.
1 parent 1437c67 commit 1ed9bfb

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

Sources/Containerization/LinuxContainer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ extension LinuxContainer {
936936

937937
/// Execute a new process in the container. The process is not started after this call, and must be manually started
938938
/// via the `start` method.
939-
public func exec(_ id: String, configuration: LinuxProcessConfiguration) async throws -> LinuxProcess {
939+
public func exec(_ id: String, configuration: LinuxProcessConfiguration, native: Bool = false) async throws -> LinuxProcess {
940940
try await self.state.withLock {
941941
var state = try $0.startedState("exec")
942942

@@ -955,6 +955,7 @@ extension LinuxContainer {
955955
containerID: self.id,
956956
spec: spec,
957957
io: stdio,
958+
native: native,
958959
ociRuntimePath: self.config.ociRuntimePath,
959960
agent: agent,
960961
vm: state.vm,

Sources/Containerization/LinuxProcess.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public final class LinuxProcess: Sendable {
9494

9595
private let state: Mutex<State>
9696
private let ioSetup: Stdio
97+
private let native: Bool
9798
private let agent: any VirtualMachineAgent
9899
private let vm: any VirtualMachineInstance
99100
private let ociRuntimePath: String?
@@ -105,6 +106,7 @@ public final class LinuxProcess: Sendable {
105106
containerID: String? = nil,
106107
spec: Spec,
107108
io: Stdio,
109+
native: Bool = false,
108110
ociRuntimePath: String?,
109111
agent: any VirtualMachineAgent,
110112
vm: any VirtualMachineInstance,
@@ -115,6 +117,7 @@ public final class LinuxProcess: Sendable {
115117
self.owningContainer = containerID
116118
self.state = Mutex<State>(.init(spec: spec, pid: -1, stdio: StdioHandles()))
117119
self.ioSetup = io
120+
self.native = native
118121
self.agent = agent
119122
self.ociRuntimePath = ociRuntimePath
120123
self.vm = vm
@@ -240,6 +243,11 @@ extension LinuxProcess {
240243
do {
241244
let spec = self.state.withLock { $0.spec }
242245
var listeners = [VsockListener?](repeating: nil, count: 3)
246+
247+
let options = try JSONEncoder().encode(
248+
CreateProcessOptions(native: self.native)
249+
)
250+
243251
if let stdin = self.ioSetup.stdin {
244252
listeners[0] = try self.vm.listen(stdin.port)
245253
}
@@ -268,7 +276,7 @@ extension LinuxProcess {
268276
stderrPort: self.ioSetup.stderr?.port,
269277
ociRuntimePath: self.ociRuntimePath,
270278
configuration: spec,
271-
options: nil
279+
options: options
272280
)
273281

274282
let result = try await t.value

Sources/Containerization/Vminitd.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ extension Vminitd: VirtualMachineAgent {
236236
if let ociRuntimePath {
237237
$0.ociRuntimePath = ociRuntimePath
238238
}
239+
if let options {
240+
$0.options = options
241+
}
239242
$0.configuration = try enc.encode(configuration)
240243
})
241244
}

vminitd/Sources/VminitdCore/ManagedContainer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ extension ManagedContainer {
162162
func createExec(
163163
id: String,
164164
stdio: HostStdio,
165-
process: ContainerizationOCI.Process
165+
process: ContainerizationOCI.Process,
166+
native: Bool
166167
) throws {
167168
log.debug("creating exec process with \(process)")
168169

vminitd/Sources/VminitdCore/Server+GRPC.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,18 @@ extension Initd: Com_Apple_Containerization_Sandbox_V3_SandboxContext.SimpleServ
798798
terminal: process.terminal
799799
)
800800

801+
let options = try JSONDecoder().decode(
802+
CreateProcessOptions.self,
803+
from: request.options
804+
)
805+
801806
// This is an exec.
802807
if let container = await self.state.containers[request.containerID] {
803808
try await container.createExec(
804809
id: request.id,
805810
stdio: stdioPorts,
806-
process: process
811+
process: process,
812+
native: options.native
807813
)
808814
} else {
809815
// We need to make our new fangled container.

0 commit comments

Comments
 (0)