diff options
author | Matthew Heon <mheon@redhat.com> | 2021-01-25 15:29:00 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2021-01-29 15:24:24 -0500 |
commit | 07f2df472cdbb4c1e533dbb6e17a6c04bd2f76fe (patch) | |
tree | e214ebdd47ce40da11cac2d533cfbe4dd54b16f9 /libpod/runtime.go | |
parent | c48753bfa0d56b855f71dc6ad62e8eff62cf98e1 (diff) | |
download | podman-07f2df472cdbb4c1e533dbb6e17a6c04bd2f76fe.tar.gz podman-07f2df472cdbb4c1e533dbb6e17a6c04bd2f76fe.tar.bz2 podman-07f2df472cdbb4c1e533dbb6e17a6c04bd2f76fe.zip |
Ensure shutdown handler access is syncronized
There was a potential race where two handlers could be added at
the same time. Go Maps are not thread-safe, so that could do
unpleasant things. Add a mutex to keep things safe.
Also, swap the order or Register and Start for the handlers in
Libpod runtime created. As written, there was a small gap between
Start and Register where SIGTERM/SIGINT would be completely
ignored, instead of stopping Podman. Swapping the two closes this
gap.
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r-- | libpod/runtime.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index 34c737a67..0dc220b52 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -180,6 +180,13 @@ 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 && errors.Cause(err) != shutdown.ErrHandlerExists { + logrus.Errorf("Error registering shutdown handler for libpod: %v", err) + } + if err := shutdown.Start(); err != nil { return nil, errors.Wrapf(err, "error starting shutdown signal handler") } @@ -188,13 +195,6 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R return nil, err } - if err := shutdown.Register("libpod", func(sig os.Signal) error { - os.Exit(1) - return nil - }); err != nil && errors.Cause(err) != shutdown.ErrHandlerExists { - logrus.Errorf("Error registering shutdown handler for libpod: %v", err) - } - return runtime, nil } |