Skip to content

Commit

Permalink
Do not error on installing duplicate shutdown handler
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mheon committed Dec 7, 2020
1 parent 4ceac05 commit dca4444
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 5 additions & 1 deletion libpod/shutdown/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/sirupsen/logrus"
)

var (
ErrHandlerExists error = errors.New("handler with given name already exists")
)

var (
stopped bool
sigChan chan os.Signal
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dca4444

Please sign in to comment.