2023-10-24 12:11:34 +02:00
|
|
|
//go:build !remote
|
2019-05-09 19:06:46 +02:00
|
|
|
|
2019-04-15 22:03:47 +02:00
|
|
|
package libpod
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-15 13:08:37 +01:00
|
|
|
"errors"
|
2019-05-08 13:44:06 +02:00
|
|
|
"fmt"
|
2019-05-09 19:06:46 +02:00
|
|
|
"os"
|
|
|
|
|
"strconv"
|
|
|
|
|
"syscall"
|
2019-04-15 22:03:47 +02:00
|
|
|
|
2025-10-23 08:18:28 -04:00
|
|
|
"github.com/containers/podman/v6/pkg/rootless"
|
|
|
|
|
"github.com/containers/podman/v6/pkg/util"
|
2026-01-15 13:08:37 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-04-15 22:03:47 +02:00
|
|
|
)
|
|
|
|
|
|
2020-12-02 10:05:34 -05:00
|
|
|
func (r *Runtime) stopPauseProcess() error {
|
2019-05-09 19:06:46 +02:00
|
|
|
if rootless.IsRootless() {
|
2026-01-15 13:08:37 +01:00
|
|
|
stateDir, err := util.GetRootlessStateDir()
|
2019-05-09 19:06:46 +02:00
|
|
|
if err != nil {
|
2026-01-15 13:08:37 +01:00
|
|
|
return fmt.Errorf("could not get rootless state directory: %w", err)
|
2019-05-09 19:06:46 +02:00
|
|
|
}
|
2026-01-15 13:08:37 +01:00
|
|
|
|
|
|
|
|
nsHandlesPath := rootless.GetNamespaceHandlesPath(stateDir)
|
|
|
|
|
if err := os.Remove(nsHandlesPath); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
|
|
|
logrus.Warnf("Failed to remove namespace handles file %s: %v", nsHandlesPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pausePidPath := rootless.GetPausePidPath(stateDir)
|
2022-09-20 09:59:28 -04:00
|
|
|
data, err := os.ReadFile(pausePidPath)
|
2019-05-09 19:06:46 +02:00
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2022-06-30 16:47:21 +02:00
|
|
|
return fmt.Errorf("cannot read pause process pid file: %w", err)
|
2019-05-09 19:06:46 +02:00
|
|
|
}
|
|
|
|
|
pausePid, err := strconv.Atoi(string(data))
|
|
|
|
|
if err != nil {
|
2022-06-30 16:47:21 +02:00
|
|
|
return fmt.Errorf("cannot parse pause pid file %s: %w", pausePidPath, err)
|
2019-05-09 19:06:46 +02:00
|
|
|
}
|
|
|
|
|
if err := os.Remove(pausePidPath); err != nil {
|
2022-06-30 16:47:21 +02:00
|
|
|
return fmt.Errorf("cannot delete pause pid file %s: %w", pausePidPath, err)
|
2019-05-09 19:06:46 +02:00
|
|
|
}
|
2019-07-03 15:37:17 -05:00
|
|
|
if err := syscall.Kill(pausePid, syscall.SIGKILL); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2019-05-09 19:06:46 +02:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|