aboutsummaryrefslogtreecommitdiff
path: root/test/e2e/common_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-01-05 17:52:39 +0100
committerGitHub <noreply@github.com>2022-01-05 17:52:39 +0100
commit2157414cf83a3b99accc2f52ac8da3f2f05bd8dd (patch)
tree5dafd4f151f0085b4a1e77e74903f2cb1f8cac43 /test/e2e/common_test.go
parentcbb2b68fc9630ef8cadd19674ab591b7fee9c7d0 (diff)
parentf6a3eddd2cbe6434c87cf1db04aaa56aac935e5c (diff)
downloadpodman-2157414cf83a3b99accc2f52ac8da3f2f05bd8dd.tar.gz
podman-2157414cf83a3b99accc2f52ac8da3f2f05bd8dd.tar.bz2
podman-2157414cf83a3b99accc2f52ac8da3f2f05bd8dd.zip
Merge pull request #12168 from mtrmac/socket-collision
Avoid RemoteSocket collisions in e2e tests
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r--test/e2e/common_test.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 6e1a62b99..bd744aa78 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -274,14 +274,32 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
}
if remote {
- uuid := stringid.GenerateNonCryptoID()
+ var pathPrefix string
if !rootless.IsRootless() {
- p.RemoteSocket = fmt.Sprintf("unix:/run/podman/podman-%s.sock", uuid)
+ pathPrefix = "/run/podman/podman"
} else {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
- socket := fmt.Sprintf("podman-%s.sock", uuid)
- fqpath := filepath.Join(runtimeDir, socket)
- p.RemoteSocket = fmt.Sprintf("unix:%s", fqpath)
+ pathPrefix = filepath.Join(runtimeDir, "podman")
+ }
+ // We want to avoid collisions in socket paths, but using the
+ // socket directly for a collision check doesn’t work; bind(2) on AF_UNIX
+ // creates the file, and we need to pass a unique path now before the bind(2)
+ // happens. So, use a podman-%s.sock-lock empty file as a marker.
+ tries := 0
+ for {
+ uuid := stringid.GenerateNonCryptoID()
+ lockPath := fmt.Sprintf("%s-%s.sock-lock", pathPrefix, uuid)
+ lockFile, err := os.OpenFile(lockPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0700)
+ if err == nil {
+ lockFile.Close()
+ p.RemoteSocketLock = lockPath
+ p.RemoteSocket = fmt.Sprintf("unix:%s-%s.sock", pathPrefix, uuid)
+ break
+ }
+ tries++
+ if tries >= 1000 {
+ panic("Too many RemoteSocket collisions")
+ }
}
}