From 30e979d2527817eead2cd9786023aa3e247f9186 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Mon, 19 Feb 2024 11:09:25 +0100 Subject: [PATCH] Catch SIGTERM, run cleanup The previous code only ran cleanup (lock release for example) on SIGINT. For anyone running restic in a container, the signal is going to be SIGTERM which means containerized execution would leave locks behind. While this could be addressed via interposing dumb-init to translate the signal, a `kill` invocation is going to default to SIGTERM, so the same problem exists for non container users. Signed-off-by: Brian Harring --- cmd/restic/cleanup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index 75933fe96..d1c8ecc1a 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -19,7 +19,7 @@ var cleanupHandlers struct { func init() { cleanupHandlers.ch = make(chan os.Signal, 1) go CleanupHandler(cleanupHandlers.ch) - signal.Notify(cleanupHandlers.ch, syscall.SIGINT) + signal.Notify(cleanupHandlers.ch, syscall.SIGINT, syscall.SIGTERM) } // AddCleanupHandler adds the function f to the list of cleanup handlers so @@ -70,7 +70,7 @@ func CleanupHandler(c <-chan os.Signal) { code := 0 - if s == syscall.SIGINT { + if s == syscall.SIGINT || s == syscall.SIGTERM { code = 130 } else { code = 1