From 45a09c76ff5aa5439c17823eb775864423ba2994 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 23 Sep 2017 11:12:44 +0200 Subject: [PATCH] Allow suspending SIGINT handler --- cmd/restic/cleanup.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index 12dbdc142..09559595b 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -12,17 +12,27 @@ import ( var cleanupHandlers struct { sync.Mutex - list []func() error - done bool + list []func() error + done bool + sigintCh chan os.Signal } var stderr = os.Stderr func init() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT) + cleanupHandlers.sigintCh = make(chan os.Signal) + go CleanupHandler(cleanupHandlers.sigintCh) + InstallSignalHandler() +} - go CleanupHandler(c) +// InstallSignalHandler listens for SIGINT and triggers the cleanup handlers. +func InstallSignalHandler() { + signal.Notify(cleanupHandlers.sigintCh, syscall.SIGINT) +} + +// SuspendSignalHandler removes the signal handler for SIGINT. +func SuspendSignalHandler() { + signal.Reset(syscall.SIGINT) } // AddCleanupHandler adds the function f to the list of cleanup handlers so