diff options
author | Miloslav Trmač <mitr@redhat.com> | 2021-11-03 16:37:49 +0100 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2022-01-03 12:31:47 +0100 |
commit | 90e74e794cc0c2c34112877821ed9ff0e7f51c28 (patch) | |
tree | 07458228d1b4df7b792080cafa62767eb0f0c46f /test/e2e | |
parent | ee146a9ab0721ec6fe2c6e3092928c34a9b3b6d7 (diff) | |
download | podman-90e74e794cc0c2c34112877821ed9ff0e7f51c28.tar.gz podman-90e74e794cc0c2c34112877821ed9ff0e7f51c28.tar.bz2 podman-90e74e794cc0c2c34112877821ed9ff0e7f51c28.zip |
Avoid collisions on RemoteSocket paths
Add lock files and re-generate the UUID if we
are not a known-unique user of the socket path.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'test/e2e')
-rw-r--r-- | test/e2e/common_test.go | 22 | ||||
-rw-r--r-- | test/e2e/libpod_suite_remote_test.go | 6 |
2 files changed, 26 insertions, 2 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 456e2bab1..bd744aa78 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -281,8 +281,26 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { runtimeDir := os.Getenv("XDG_RUNTIME_DIR") pathPrefix = filepath.Join(runtimeDir, "podman") } - uuid := stringid.GenerateNonCryptoID() - p.RemoteSocket = fmt.Sprintf("unix:%s-%s.sock", pathPrefix, uuid) + // 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") + } + } } // Setup registries.conf ENV variable diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index d60383029..4644e3748 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -1,3 +1,4 @@ +//go:build remote // +build remote package integration @@ -143,6 +144,11 @@ func (p *PodmanTestIntegration) StopRemoteService() { if err := os.Remove(socket); err != nil { fmt.Println(err) } + if p.RemoteSocketLock != "" { + if err := os.Remove(p.RemoteSocketLock); err != nil { + fmt.Println(err) + } + } } //MakeOptions assembles all the podman main options |