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 <ferringb@gmail.com>
This commit is contained in:
Brian Harring 2024-02-19 11:09:25 +01:00
parent cfbeb2cde5
commit 30e979d252
No known key found for this signature in database
GPG Key ID: AAF3CB6981BFAE49
1 changed files with 2 additions and 2 deletions

View File

@ -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