Skip to content

Commit 5ab9c95

Browse files
committed
Add native property to LinuxProcess
LinuxProcess with `native` property runs outside containerized environment.
1 parent 9d2b579 commit 5ab9c95

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
@@ -916,7 +916,7 @@ extension LinuxContainer {
916916

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

@@ -935,6 +935,7 @@ extension LinuxContainer {
935935
containerID: self.id,
936936
spec: spec,
937937
io: stdio,
938+
native: native,
938939
ociRuntimePath: self.config.ociRuntimePath,
939940
agent: agent,
940941
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
@@ -231,6 +231,9 @@ extension Vminitd: VirtualMachineAgent {
231231
if let ociRuntimePath {
232232
$0.ociRuntimePath = ociRuntimePath
233233
}
234+
if let options {
235+
$0.options = options
236+
}
234237
$0.configuration = try enc.encode(configuration)
235238
})
236239
}

vminitd/Sources/VminitdCore/ManagedContainer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ extension ManagedContainer {
160160
func createExec(
161161
id: String,
162162
stdio: HostStdio,
163-
process: ContainerizationOCI.Process
163+
process: ContainerizationOCI.Process,
164+
native: Bool
164165
) throws {
165166
log.debug("creating exec process with \(process)")
166167

vminitd/Sources/VminitdCore/Server+GRPC.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,18 @@ extension Initd: Com_Apple_Containerization_Sandbox_V3_SandboxContext.SimpleServ
789789
terminal: process.terminal
790790
)
791791

792+
let options = try JSONDecoder().decode(
793+
CreateProcessOptions.self,
794+
from: request.options
795+
)
796+
792797
// This is an exec.
793798
if let container = await self.state.containers[request.containerID] {
794799
try await container.createExec(
795800
id: request.id,
796801
stdio: stdioPorts,
797-
process: process
802+
process: process,
803+
native: options.native
798804
)
799805
} else {
800806
// We need to make our new fangled container.

0 commit comments

Comments
 (0)