diff --git a/cmd/podman/root.go b/cmd/podman/root.go index a373a3aa18..1ad2cc18be 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -16,6 +16,7 @@ import ( "github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/libpod/define" + "github.com/containers/podman/v5/libpod/shutdown" "github.com/containers/podman/v5/pkg/bindings" "github.com/containers/podman/v5/pkg/checkpoint/crutils" "github.com/containers/podman/v5/pkg/domain/entities" @@ -124,9 +125,11 @@ func Execute() { fmt.Fprintln(os.Stderr, formatError(err)) } + _ = shutdown.Stop() + if requireCleanup { // The cobra post-run is not being executed in case of - // a previous error , so make sure that the engine(s) + // a previous error, so make sure that the engine(s) // are correctly shutdown. // // See https://github.com/spf13/cobra/issues/914 diff --git a/libpod/runtime.go b/libpod/runtime.go index 565a74645e..4c7d06f1f9 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -210,7 +210,14 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R } } + if err := makeRuntime(ctx, runtime); err != nil { + return nil, err + } + if err := shutdown.Register("libpod", func(sig os.Signal) error { + if runtime.store != nil { + _, _ = runtime.store.Shutdown(false) + } // For `systemctl stop podman.service` support, exit code should be 0 if sig == syscall.SIGTERM { os.Exit(0) @@ -225,10 +232,6 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R return nil, fmt.Errorf("starting shutdown signal handler: %w", err) } - if err := makeRuntime(ctx, runtime); err != nil { - return nil, err - } - runtime.config.CheckCgroupsAndAdjustConfig() return runtime, nil diff --git a/libpod/shutdown/handler.go b/libpod/shutdown/handler.go index 2b30a95768..d7fd5b5323 100644 --- a/libpod/shutdown/handler.go +++ b/libpod/shutdown/handler.go @@ -91,6 +91,11 @@ func Stop() error { return nil } + // if the signal handler is running, wait that it terminates + handlerLock.Lock() + defer handlerLock.Unlock() + // it doesn't need to be in the critical section, but staticcheck complains if + // the critical section is empty. cancelChan <- true return nil diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index a3c9c72df4..5e0d1df72b 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -33,7 +33,6 @@ import ( . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" ) var ( @@ -1057,16 +1056,6 @@ func rmAll(podmanBin string, path string) { GinkgoWriter.Printf("%v\n", err) } } else { - // When using overlay as root, podman leaves a stray mount behind. - // This leak causes remote tests to take a loooooong time, which - // then causes Cirrus to time out. Unmount that stray. - overlayPath := path + "/root/overlay" - if _, err := os.Stat(overlayPath); err == nil { - if err = unix.Unmount(overlayPath, unix.MNT_DETACH); err != nil { - GinkgoWriter.Printf("Error unmounting %s: %v\n", overlayPath, err) - } - } - if err = os.RemoveAll(path); err != nil { GinkgoWriter.Printf("%q\n", err) } diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index 4c7a7c96f1..44a79eaf36 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -103,7 +103,7 @@ func (p *PodmanTestIntegration) StartRemoteService() { } func (p *PodmanTestIntegration) StopRemoteService() { - if err := p.RemoteSession.Kill(); err != nil { + if err := p.RemoteSession.Signal(syscall.SIGTERM); err != nil { GinkgoWriter.Printf("unable to clean up service %d, %v\n", p.RemoteSession.Pid, err) } if _, err := p.RemoteSession.Wait(); err != nil { diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 7c10296290..5cba515e9d 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -277,7 +277,7 @@ run_podman --noout system connection ls run_podman --log-level=debug run --rm $IMAGE true is "$output" ".*Shutting down engines.*" run_podman 125 --log-level=debug run dockah://rien.de/rien:latest - is "${lines[-1]}" ".*Shutting down engines" + is "$output" ".*Shutting down engines.*" } # vim: filetype=sh