mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
On Linux, a start of a VM whose protection is on pins .git, its git dirs and every lock path read-only in a user and mount namespace that devvm _qemu pinned makes around QEMU. It keeps the pins while QEMU runs, records each re-pin, refuses hard links and fails closed on watches and records; doctor says why a host can't lock, and such hosts watch .git instead. The pins' events file is read through safefile, and the command-line check takes "devvm lock" in prose as English. Co-Authored-By: Claude Opus 5.5 <[email protected]>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"github.com/devvmhq/devvm/internal/backend"
|
|
"github.com/devvmhq/devvm/internal/backend/lima"
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
"github.com/devvmhq/devvm/internal/platform"
|
|
)
|
|
|
|
// pinsCheck is doctor's check of .git protection on a Linux host, which
|
|
// locks .git in a user namespace around each VM's QEMU: whether the host
|
|
// lets devvm do that, and why not. Tests set its fields.
|
|
type pinsCheck struct {
|
|
// Probe is the backend's probe (lima.Lima's Pins): nil when this host
|
|
// pins, else why not; a nil Probe is a host that doesn't lock this way
|
|
// (macOS).
|
|
Probe func() error
|
|
// Limit is why the kernel's settings refuse it (platform.UsernsLimit).
|
|
Limit func() string
|
|
}
|
|
|
|
// newPinsCheck is the check of the host's pins, Lima's probe's: on a
|
|
// Linux host only.
|
|
func newPinsCheck(reg *backend.Registry) pinsCheck {
|
|
c := pinsCheck{Limit: platform.UsernsLimit}
|
|
if runtime.GOOS != "linux" || reg == nil {
|
|
return c
|
|
}
|
|
if b, ok := reg.Lookup(lima.Name); ok {
|
|
if l, ok := backend.As[*lima.Lima](b); ok {
|
|
c.Probe = l.Pins
|
|
}
|
|
}
|
|
return c
|
|
}
|
|
|
|
// warning is doctor's warning when this host can't lock .git: what the
|
|
// kernel's settings say, or the probe's error.
|
|
func (c pinsCheck) warning() (msg.M, bool) {
|
|
if c.Probe == nil {
|
|
return msg.M{}, false
|
|
}
|
|
err := c.Probe()
|
|
if err == nil {
|
|
return msg.M{}, false
|
|
}
|
|
switch c.Limit() {
|
|
case "apparmor":
|
|
return msg.DoctorPinsApparmor(), true
|
|
case "sysctl":
|
|
return msg.DoctorPinsSysctl(), true
|
|
case "max":
|
|
return msg.DoctorPinsMax(), true
|
|
}
|
|
return msg.DoctorPinsFailed(err.Error()).Because(err), true
|
|
}
|