Open cfergeau opened 1 week ago
We should also report a proper error when the path length is too long
Possible solutions:
Tentative patch for the 2nd option is
diff --git a/pkg/vf/virtionet.go b/pkg/vf/virtionet.go
index 72fd73c..28e257d 100644
--- a/pkg/vf/virtionet.go
+++ b/pkg/vf/virtionet.go
@@ -19,20 +19,12 @@ type VirtioNet struct {
localAddr *net.UnixAddr
}
-func localUnixSocketPath() (string, error) {
- homeDir, err := os.UserHomeDir()
+func localUnixSocketPath(dir string) (string, error) {
+ tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("vfkit-%d-*.sock", os.Getpid()))
if err != nil {
return "", err
}
- dir := filepath.Join(homeDir, "Library", "Application Support", "vfkit")
- if err := os.MkdirAll(dir, 0755); err != nil {
- return "", err
- }
- tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("net-%d-*.sock", os.Getpid()))
- if err != nil {
- return "", err
- }
- // slightly racy, but this is in a directory only user-writable
+ // slightly racy, but hopefully this is in a directory only user-writable
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())
@@ -44,7 +36,7 @@ func (dev *VirtioNet) connectUnixPath() error {
Name: dev.UnixSocketPath,
Net: "unixgram",
}
- localSocketPath, err := localUnixSocketPath()
+ localSocketPath, err := localUnixSocketPath(filepath.Dir(dev.UnixSocketPath))
if err != nil {
return err
}
(not even compile tested)
unix socket paths have a very limited length, 104 bytes on macos, 108 on linux
Podman is currently hitting this limit with vfkit:
This path is generated in https://github.com/crc-org/vfkit/blob/966a9282673dbe36c7fa1b0f2c09750839501d43/pkg/vf/virtionet.go#L21-L41