Skip to content

Commit ff85a48

Browse files
committed
DefaultCommand signal behavior improvements for plugins
Correct signal semantics for plugins: We exec into plugin binaries. If the parent CLI keeps SIGINT/SIGTERM handlers installed, it can intercept/alter signal behavior intended for the plugin (e.g., preventing graceful shutdown in foreground workflows).
1 parent 81e51b2 commit ff85a48

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Sources/CLI/DefaultCommand.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ArgumentParser
1818
import Foundation
1919
import ContainerClient
2020
import ContainerPlugin
21+
import Darwin
2122

2223
struct DefaultCommand: AsyncParsableCommand {
2324
static let configuration = CommandConfiguration(
@@ -84,7 +85,17 @@ struct DefaultCommand: AsyncParsableCommand {
8485
"""
8586
)
8687
}
88+
// Before execing into the plugin, restore default SIGINT/SIGTERM so the plugin can manage signals.
89+
Self.resetSignalsForPluginExec()
8790
// Exec performs execvp (with no fork).
8891
try plugin.exec(args: remaining)
8992
}
9093
}
94+
95+
extension DefaultCommand {
96+
// Exposed for tests to verify signal reset semantics.
97+
static func resetSignalsForPluginExec() {
98+
signal(SIGINT, SIG_DFL)
99+
signal(SIGTERM, SIG_DFL)
100+
}
101+
}

0 commit comments

Comments
 (0)