Extract platform-specific syscall code into proc_unix.go and proc_windows.go with appropriate build tags. This fixes TestCrossPlatformBuild which failed because syscall.SysProcAttr.Setpgid is Unix-only. Changes: - setSysProcAttr(): Sets process group on Unix, no-op on Windows - isProcessAlive(): Uses Signal(0) on Unix, nil signal on Windows - sendTermSignal(): SIGTERM on Unix, Kill() on Windows - sendKillSignal(): SIGKILL on Unix, Kill() on Windows Fixes gt-3078ed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
33 lines
733 B
Go
33 lines
733 B
Go
//go:build unix
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// setSysProcAttr sets platform-specific process attributes.
|
|
// On Unix, we detach from the process group so the server survives daemon restart.
|
|
func setSysProcAttr(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
Setpgid: true,
|
|
}
|
|
}
|
|
|
|
// isProcessAlive checks if a process is still running.
|
|
func isProcessAlive(p *os.Process) bool {
|
|
return p.Signal(syscall.Signal(0)) == nil
|
|
}
|
|
|
|
// sendTermSignal sends SIGTERM for graceful shutdown.
|
|
func sendTermSignal(p *os.Process) error {
|
|
return p.Signal(syscall.SIGTERM)
|
|
}
|
|
|
|
// sendKillSignal sends SIGKILL for forced termination.
|
|
func sendKillSignal(p *os.Process) error {
|
|
return p.Signal(syscall.SIGKILL)
|
|
}
|