//go:build !windows package version import ( "errors" "os" "os/exec" "syscall" "golang.org/x/sys/unix" ) func processAlive(pid int) bool { if pid <= 0 { return false } err := unix.Kill(pid, 0) return err == nil || errors.Is(err, unix.EPERM) } func processMatches(pid int, expectedToken string) bool { if !processAlive(pid) { return false } if expectedToken == "" { // Backward compatibility for journals written before process identity // tokens were introduced. return true } actualToken, err := processIdentityToken(pid) return err == nil && actualToken == expectedToken } // configureIdentityCommand gives the identity probe its own process group and // replaces CommandContext's cancellation hook so descendants cannot survive a // timed-out or cancelled probe. func configureIdentityCommand(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} cmd.Cancel = func() error { if cmd.Process == nil { return os.ErrProcessDone } err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) if errors.Is(err, syscall.ESRCH) { return os.ErrProcessDone } return err } }