summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2021-11-17 10:06:26 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2021-11-17 10:13:33 +0100
commitee62711136339c5daf38e38859227d85b06fc32a (patch)
tree83a2706db6a84b5db078645bf914f1b5eb9ea8d6 /utils
parentc6616648780881ac717817cf79de84084ce7c02f (diff)
downloadpodman-ee62711136339c5daf38e38859227d85b06fc32a.tar.gz
podman-ee62711136339c5daf38e38859227d85b06fc32a.tar.bz2
podman-ee62711136339c5daf38e38859227d85b06fc32a.zip
utils: use podman-pause-$RANDOM.scope name
we try hard to re-use the existing podman-pause.scope name when it already exists, causing any sort of race errors when the already existing scope is terminating. There is no such a requirement though, so just try with a random name. Closes: https://github.com/containers/podman/issues/12065 [NO NEW TESTS NEEDED] it fixes a race in the CI Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.go12
-rw-r--r--utils/utils_supported.go9
2 files changed, 11 insertions, 10 deletions
diff --git a/utils/utils.go b/utils/utils.go
index 109ae088b..f2e7beef9 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "math/rand"
"os"
"os/exec"
"strconv"
@@ -203,7 +204,16 @@ func moveProcessToScope(pidPath, slice, scope string) error {
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
// a separate scope.
func MovePauseProcessToScope(pausePidPath string) {
- err := moveProcessToScope(pausePidPath, "user.slice", "podman-pause.scope")
+ var err error
+
+ for i := 0; i < 3; i++ {
+ r := rand.Int()
+ err = moveProcessToScope(pausePidPath, "user.slice", fmt.Sprintf("podman-pause-%d.scope", r))
+ if err == nil {
+ return
+ }
+ }
+
if err != nil {
unified, err2 := cgroups.IsCgroup2UnifiedMode()
if err2 != nil {
diff --git a/utils/utils_supported.go b/utils/utils_supported.go
index 1404e3194..0f0c9a9ba 100644
--- a/utils/utils_supported.go
+++ b/utils/utils_supported.go
@@ -44,15 +44,6 @@ func RunUnderSystemdScope(pid int, slice string, unitName string) error {
ch := make(chan string)
_, err = conn.StartTransientUnit(unitName, "replace", properties, ch)
if err != nil {
- // On errors check if the cgroup already exists, if it does move the process there
- if props, err := conn.GetUnitTypeProperties(unitName, "Scope"); err == nil {
- if cgroup, ok := props["ControlGroup"].(string); ok && cgroup != "" {
- if err := moveUnderCgroup(cgroup, "", []uint32{uint32(pid)}); err == nil {
- return nil
- }
- // On errors return the original error message we got from StartTransientUnit.
- }
- }
return err
}