summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2020-12-07 10:00:36 -0500
committerMatthew Heon <mheon@redhat.com>2020-12-07 14:32:34 -0500
commitdca4444486a08b169862135ea5079856473f2c80 (patch)
tree06e35d53ba1d7506c8cfc351a07d644dfe93cd87
parent4ceac05eacc37ee4cb0af03290c1c8a0f491e302 (diff)
downloadpodman-dca4444486a08b169862135ea5079856473f2c80.tar.gz
podman-dca4444486a08b169862135ea5079856473f2c80.tar.bz2
podman-dca4444486a08b169862135ea5079856473f2c80.zip
Do not error on installing duplicate shutdown handler
Installing a duplicate shutdown handler fails, but if a handler with the same name is already present, we should be set to go. There's no reason to print a user-facing error about it. This comes up almost nowhere because Podman never makes more than one Libpod runtime, but there is one exception (`system reset`) and the error messages, while harmless, were making people very confused (we got several bug reports that `system reset` was nonfunctional). Signed-off-by: Matthew Heon <mheon@redhat.com>
-rw-r--r--libpod/runtime.go2
-rw-r--r--libpod/shutdown/handler.go6
2 files changed, 6 insertions, 2 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index df3dfae2b..73d73fb5d 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -190,7 +190,7 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
if err := shutdown.Register("libpod", func(sig os.Signal) error {
os.Exit(1)
return nil
- }); err != nil {
+ }); err != nil && errors.Cause(err) != shutdown.ErrHandlerExists {
logrus.Errorf("Error registering shutdown handler for libpod: %v", err)
}
diff --git a/libpod/shutdown/handler.go b/libpod/shutdown/handler.go
index 87538dec9..f0f228b19 100644
--- a/libpod/shutdown/handler.go
+++ b/libpod/shutdown/handler.go
@@ -11,6 +11,10 @@ import (
)
var (
+ ErrHandlerExists error = errors.New("handler with given name already exists")
+)
+
+var (
stopped bool
sigChan chan os.Signal
cancelChan chan bool
@@ -98,7 +102,7 @@ func Register(name string, handler func(os.Signal) error) error {
}
if _, ok := handlers[name]; ok {
- return errors.Errorf("handler with name %s already exists", name)
+ return ErrHandlerExists
}
handlers[name] = handler