mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 14:33:17 -10:00
fix(lima): VM names leave the NUL byte out of the ssh socket's path (#25)
`NameMax` budgets for `paths.SocketMax - 1`, as `ControlMax` does, and the Lima package's own copy of the limit goes, so `paths.SocketMax` is the one owner. On the edge case above, devvm now picks a one-character-shorter folder part, `devvm-jyrkki-webs-fbe3918054ffd3`, and the VM is made. The Lima limits page says a socket path has fewer than 104 characters. Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
72b648df31
commit
72f6284eb9
3 files changed
+9
-12
No files matched your search
@@ -68,7 +68,7 @@ Set the variables in the VM's shell or in your project's scripts, before the too
|
||||
|
||||
## Limits
|
||||
|
||||
- **Folder names in VM names are cut short.** Lima keeps each VM's ssh socket in the VM's folder in its home, and a socket path has at most 104 characters. A long Lima home leaves less room for the name, so set `DEVVM_LIMA_HOME` to a shorter folder if devvm says the home is too long, or that a VM's name leaves no room for the folder's name ([VM names](../internals/backends.md#vm-names)).
|
||||
- **Folder names in VM names are cut short.** Lima keeps each VM's ssh socket in the VM's folder in its home, and a socket path has fewer than 104 characters. A long Lima home leaves less room for the name, so set `DEVVM_LIMA_HOME` to a shorter folder if devvm says the home is too long, or that a VM's name leaves no room for the folder's name ([VM names](../internals/backends.md#vm-names)).
|
||||
- **Paths can't contain commas.** Lima and QEMU split mount options on commas, so devvm refuses to mount a project folder whose path has one, and it leaves out an agent's folder whose path has one, with a warning.
|
||||
- **Disks can grow but not shrink.**
|
||||
- **Mounts on Linux are 9p.** A 9p share mounts once per guest, and file watchers in the VM miss changes in its subfolders ([file watchers](#file-watchers)).
|
||||
|
||||
@@ -323,17 +323,14 @@ func (l *Lima) Caps() backend.Caps {
|
||||
}
|
||||
}
|
||||
|
||||
// socketMax is the longest unix socket path macOS takes (Linux takes 108).
|
||||
// sshSocketExtra is what OpenSSH adds to the socket's name while making it.
|
||||
const (
|
||||
socketMax = 104
|
||||
sshSocketExtra = 17
|
||||
)
|
||||
const sshSocketExtra = 17
|
||||
|
||||
// NameMax is the longest VM name whose ssh socket fits: Lima keeps it in
|
||||
// the VM's folder (<Lima home>/<vm>/ssh.sock).
|
||||
// the VM's folder (<Lima home>/<vm>/ssh.sock) and refuses a path of
|
||||
// paths.SocketMax characters or more, as the last byte is the NUL.
|
||||
func (l *host) NameMax() int {
|
||||
return max(0, socketMax-sshSocketExtra-len(l.Dirs.Lima)-len("/")-len("/ssh.sock"))
|
||||
return max(0, paths.SocketMax-1-sshSocketExtra-len(l.Dirs.Lima)-len("/")-len("/ssh.sock"))
|
||||
}
|
||||
|
||||
// imageKey returns the key of an image's instance, and whether it is one.
|
||||
|
||||
@@ -336,13 +336,13 @@ func TestStartRefusesGlobalConfigsAndNetworks(t *testing.T) {
|
||||
}
|
||||
|
||||
// Lima keeps a VM's ssh socket in its folder, OpenSSH adds 17 characters
|
||||
// while making it, and a socket path has at most 104: the name gets what's
|
||||
// left.
|
||||
// while making it, and Lima refuses a socket path of paths.SocketMax
|
||||
// characters or more: the name gets what's left.
|
||||
func TestNameMax(t *testing.T) {
|
||||
l, f, _ := testLima(t, "darwin")
|
||||
n := l.NameMax()
|
||||
if len(l.Dirs.Lima)+1+n+len("/ssh.sock")+17 != 104 {
|
||||
t.Errorf("NameMax %d for a Lima home of %d characters", n, len(l.Dirs.Lima))
|
||||
if sock := len(l.Dirs.Lima) + 1 + n + len("/ssh.sock") + 17; sock != paths.SocketMax-1 {
|
||||
t.Errorf("NameMax %d gives a socket path of %d characters for a Lima home of %d", n, sock, len(l.Dirs.Lima))
|
||||
}
|
||||
long := "devvm-" + strings.Repeat("x", n) + "-0123456789abcd"
|
||||
err := l.CreateVM(t.Context(), "k", backend.VMSpec{Name: long})
|
||||
|
||||
Reference in new issue
Block a user