Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public protocol ClientProcess: Sendable {
func resize(_ size: Terminal.Size) async throws
/// Send a signal to the process `id`.
/// Kill does not wait for the process to exit, it only delivers the signal.
func kill(_ signal: Int32) async throws
func kill(_ signal: String) async throws
/// Wait for the process `id` to complete and return its exit code.
/// This method blocks until the process exits and the code is obtained.
func wait() async throws -> Int32
Expand Down Expand Up @@ -76,11 +76,11 @@ struct ClientProcessImpl: ClientProcess, Sendable {
}

/// Send a signal to the process.
public func kill(_ signal: Int32) async throws {
public func kill(_ signal: String) async throws {
let request = XPCMessage(route: .containerKill)
request.set(key: .id, value: containerId)
request.set(key: .processIdentifier, value: id)
request.set(key: .signal, value: Int64(signal))
request.set(key: .signal, value: signal)

try await xpcClient.send(request)
}
Expand Down
18 changes: 16 additions & 2 deletions Sources/Services/ContainerAPIService/Client/ProcessIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,23 @@ public struct ProcessIO: Sendable {
SIGINT,
SIGUSR1,
SIGUSR2,
SIGWINCH,
]

static func signalName(_ signal: Int32) -> String {
switch signal {
case SIGTERM:
"SIGTERM"
case SIGINT:
"SIGINT"
case SIGUSR1:
"SIGUSR1"
case SIGUSR2:
"SIGUSR2"
default:
"\(signal)"
}
}

public struct IoTracker: Sendable {
let stream: AsyncStream<Void>
let cont: AsyncStream<Void>.Continuation
Expand Down Expand Up @@ -198,7 +212,7 @@ public struct ProcessIO: Sendable {
_ = group.addTaskUnlessCancelled {
for await sig in signals.signals {
do {
try await process.kill(sig)
try await process.kill(Self.signalName(sig))
} catch {
log.error(
"failed to send signal",
Expand Down
35 changes: 35 additions & 0 deletions Tests/ContainerAPIClientTests/ProcessIOTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
// Copyright © 2026 Apple Inc. and the container project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

import Darwin
import Testing

@testable import ContainerAPIClient

struct ProcessIOTests {
@Test("Forwarded process signals are encoded as names")
func forwardedSignalNames() {
#expect(ProcessIO.signalName(SIGTERM) == "SIGTERM")
#expect(ProcessIO.signalName(SIGINT) == "SIGINT")
#expect(ProcessIO.signalName(SIGUSR1) == "SIGUSR1")
#expect(ProcessIO.signalName(SIGUSR2) == "SIGUSR2")
}

@Test("Terminal resize signal is handled by the resize path")
func terminalResizeSignalIsNotForwardedAsKill() {
#expect(!ProcessIO.signalSet.contains(SIGWINCH))
}
}