Enforce LIFO ordering for shutdown handlers

This allows us to run both the Libpod and Server handlers at the
same time without unregistering one.

Also, pass the signal that killed us into the handlers, in case
they want to use it to determine what to do (e.g. what exit code
to set).

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon
2020-10-13 14:00:35 -04:00
parent 83e6e4ccdd
commit f58d2f5e75
3 changed files with 32 additions and 17 deletions

View File

@ -185,14 +185,11 @@ func (s *APIServer) Serve() error {
if err := shutdown.Start(); err != nil {
return err
}
if err := shutdown.Register("server", func() error {
if err := shutdown.Register("server", func(sig os.Signal) error {
return s.Shutdown()
}); err != nil {
return err
}
// Unregister the libpod handler, which just calls exit(1).
// Ignore errors if it doesn't exist.
_ = shutdown.Unregister("libpod")
errChan := make(chan error, 1)