//go:build linux package host import ( "errors" "os" "path/filepath" "strconv" "strings" "testing" "github.com/carlosframework/platform/internal/hostbox" ) // journal-migrate holds the registry through a child it runs as the service // user. The quiesce scan must not count that child (or any other direct // child of the migration) as a running service process, or the migration // refuses itself every time; any other service-user process still refuses. func TestQuiesceScanSkipsOwnChildren(t *testing.T) { uid := os.Getuid() self := 4242 proc := t.TempDir() mk := func(pid, ppid int) { dir := filepath.Join(proc, strconv.Itoa(pid)) if err := os.Mkdir(dir, 0o755); err != nil { t.Fatal(err) } // /proc//stat: "pid (comm) state ppid ..." stat := strconv.Itoa(pid) + " (carlos x) S " + strconv.Itoa(ppid) + " 1 1 0\n" if err := os.WriteFile(filepath.Join(dir, "stat"), []byte(stat), 0o644); err != nil { t.Fatal(err) } } mk(5000, self) // the registry child if err := scanQuiesceProcs(proc, uid, self); err != nil { t.Fatalf("own child refused: %v", err) } mk(5001, 1) // any other service-user process err := scanQuiesceProcs(proc, uid, self) if !errors.Is(err, hostbox.ErrTypedJournal) || !strings.Contains(err.Error(), "5001") { t.Fatalf("foreign process not refused by pid: %v", err) } }