aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/init.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-23 08:02:03 +0900
committerOphestra <cat@gensokyo.uk>2025-10-23 08:02:03 +0900
commit57231d4acf41ac01aa96a558c8d3017054b15269 (patch)
tree433e514e4bca7dd901d001260ef46bf90089f5e6 /container/init.go
parentc5aefe5e9d28a8d4dad68bc06b38e42101656fe9 (diff)
container/init: improve signal handling
The SIGTERM signal is delivered in many other cases and can lead to strange behaviour. The unconditional resume of the logger also causes strange behaviour in the cancellation forwarding path. This change also passes through additional signals. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/init.go')
-rw-r--r--container/init.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/container/init.go b/container/init.go
index 4e2345b3..0f5edb19 100644
--- a/container/init.go
+++ b/container/init.go
@@ -390,7 +390,8 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
// handle signals to dump withheld messages
sig := make(chan os.Signal, 2)
- k.notify(sig, os.Interrupt, CancelSignal)
+ k.notify(sig, CancelSignal,
+ os.Interrupt, SIGTERM, SIGQUIT)
// closed after residualProcessTimeout has elapsed after initial process death
timeout := make(chan struct{})
@@ -399,18 +400,28 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
for {
select {
case s := <-sig:
- if msg.Resume() {
- msg.Verbosef("%s after process start", s.String())
- } else {
- msg.Verbosef("got %s", s.String())
- }
if s == CancelSignal && params.ForwardCancel && cmd.Process != nil {
+ msg.Resume()
msg.Verbose("forwarding context cancellation")
if err := k.signal(cmd, os.Interrupt); err != nil {
k.printf(msg, "cannot forward cancellation: %v", err)
}
continue
}
+
+ if s == SIGTERM || s == SIGQUIT {
+ msg.Verbosef("got %s, forwarding to initial process", s.String())
+ if err := k.signal(cmd, s); err != nil {
+ k.printf(msg, "cannot forward signal: %v", err)
+ }
+ continue
+ }
+
+ if msg.Resume() {
+ msg.Verbosef("%s after process start", s.String())
+ } else {
+ msg.Verbosef("got %s", s.String())
+ }
msg.BeforeExit()
k.exit(0)