mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
run/proxy.confined said how the child was confined, but not which broker said it. After a downgrade, an older devvm starts the VM's proxy as one process and never writes the file, so the newer devvm's file stayed and devvm doctor took the older devvm's unconfined proxy for a confined one. The broker now writes a second line naming itself, its pid and its start as the system tells it (proxy.BrokerID, through IO.Started), and ReadConfined takes the file only when it names the running broker, which doctor finds by the pid file and platform.ProcessStart (kern.proc.pid's p_starttime on macOS, /proc's starttime on Linux). A file that names another broker, or none, is one that hasn't said, so another binary's proxy gets proxy_old, and when doctor can't read the running broker's start it says it can't tell (proxy_confinement_unknown). The e2e broker check reads the file's first line and checks the second names run/proxy.pid's broker. Tests: TestUnconfinedStaleMarker, TestReadConfined, TestProcessStart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
//go:build darwin || linux
|
|
|
|
package platform
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A process's start is one word of digits and dots, the same at each read while it runs, a
|
|
// child's is another than the init process's, which started at boot, and a pid no process has
|
|
// gets none.
|
|
func TestProcessStart(t *testing.T) {
|
|
self, err := ProcessStart(os.Getpid())
|
|
if err != nil || self == "" || strings.IndexFunc(self, func(r rune) bool { return (r < '0' || r > '9') && r != '.' }) >= 0 {
|
|
t.Fatalf("ProcessStart(self) = %q, %v", self, err)
|
|
}
|
|
if again, err := ProcessStart(os.Getpid()); err != nil || again != self {
|
|
t.Errorf("again = %q, %v, want %q", again, err, self)
|
|
}
|
|
cmd := exec.CommandContext(t.Context(), "sleep", "30")
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { _ = cmd.Process.Kill(); _ = cmd.Wait() }()
|
|
other, err := ProcessStart(cmd.Process.Pid)
|
|
if init, ierr := ProcessStart(1); err != nil || ierr != nil || other == init {
|
|
t.Errorf("a child's start = %q, %v; init's %q, %v", other, err, init, ierr)
|
|
}
|
|
if got, err := ProcessStart(1 << 30); err == nil {
|
|
t.Errorf("no process: %q", got)
|
|
}
|
|
}
|