Skip to content

Commit 1a3b973

Browse files
authored
Merge pull request #64 from AkihiroSuda/lima-home
Follow-up to "Follow-up to \"Implement LIMA_HOME to override ~/.lima location\""
2 parents f21596f + 3d18382 commit 1a3b973

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

cmd/limactl/start.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/AkihiroSuda/lima/pkg/limayaml"
12+
"github.com/AkihiroSuda/lima/pkg/osutil"
1213
"github.com/AkihiroSuda/lima/pkg/start"
1314
"github.com/AkihiroSuda/lima/pkg/store"
1415
"github.com/AkihiroSuda/lima/pkg/store/filenames"
@@ -82,11 +83,11 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
8283
return nil, err
8384
}
8485

85-
// the full path of the socket name can be at most 104 chars.
86+
// the full path of the socket name must be less than UNIX_PATH_MAX chars.
8687
maxSockName := filepath.Join(instDir, filenames.LongestSock)
87-
if len(maxSockName) > 104 {
88-
return nil, errors.Errorf("instance name %q too long: %q can be at most 104 characers, but is %d",
89-
instName, maxSockName, len(maxSockName))
88+
if len(maxSockName) >= osutil.UnixPathMax {
89+
return nil, errors.Errorf("instance name %q too long: %q must be less than UNIX_PATH_MAX=%d characers, but is %d",
90+
instName, maxSockName, osutil.UnixPathMax, len(maxSockName))
9091
}
9192
if _, err := os.Stat(instDir); !errors.Is(err, os.ErrNotExist) {
9293
return nil, errors.Errorf("instance %q already exists (%q)", instName, instDir)

docs/internal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Defaults to `~/.lima`.
77
Note that we intentionally avoid using `~/Library/Application Support/Lima` on macOS.
88

99
We use `~/.lima` so that we can have enough space for the length of the socket path,
10-
which can be only 104 characters on macOS.
10+
which must be less than 104 characters on macOS.
1111

1212
### Instance directory (`${LIMA_HOME}/<INSTANCE>`)
1313

pkg/osutil/osutil_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package osutil
2+
3+
// UnixPathMax is the value of UNIX_PATH_MAX.
4+
const UnixPathMax = 108

pkg/osutil/osutil_others.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// +build !linux
2+
3+
package osutil
4+
5+
// UnixPathMax is the value of UNIX_PATH_MAX.
6+
const UnixPathMax = 104

pkg/sshutil/sshutil.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package sshutil
33
import (
44
"os"
55
"path/filepath"
6-
"runtime"
76
"strings"
87

8+
"github.com/AkihiroSuda/lima/pkg/osutil"
99
"github.com/AkihiroSuda/lima/pkg/store/filenames"
1010
"github.com/pkg/errors"
1111
"github.com/sirupsen/logrus"
@@ -48,16 +48,8 @@ func DefaultPubKeys() []PubKey {
4848

4949
func SSHArgs(instDir string) ([]string, error) {
5050
controlSock := filepath.Join(instDir, filenames.SSHSock)
51-
maxSockLen := 104
52-
if runtime.GOOS == "linux" {
53-
maxSockLen = 108
54-
}
55-
if len(controlSock) >= maxSockLen {
56-
// If the instDir was under `~/Library/Application Support/Lima`,
57-
// we could only have 54 chars for the user name and the inst name at maximum:
58-
// len("/Users/32charsXXXXXXXXXXXXXXXXXXXXXXXXX/Library/Application Support/Lima/22charsXXXXXXXXXXXXXXX/ssh.sock") = 104
59-
// So we do not use `~/Library/Application Support`.
60-
return nil, errors.Errorf("socket path %q is too long: > UNIX_PATH_MAX=%d", controlSock, maxSockLen)
51+
if len(controlSock) >= osutil.UnixPathMax {
52+
return nil, errors.Errorf("socket path %q is too long: >= UNIX_PATH_MAX=%d", controlSock, osutil.UnixPathMax)
6153
}
6254
args := []string{
6355
"-o", "ControlMaster=auto",

pkg/store/filenames/filenames.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const (
2020
)
2121

2222
// LongestSock is the longest socket name.
23-
// On macOS, the full path of the socket can be at most 104 characters.
23+
// On macOS, the full path of the socket (excluding the NUL terminator) must be less than 104 characters.
2424
// See unix(4).
2525
//
26-
// On Linux, the max length is 108.
26+
// On Linux, the full path must be less than 108 characters.
2727
const LongestSock = SerialSock

0 commit comments

Comments
 (0)