2026-10-24 09:49:16 +02:00
|
|
|
//go:build windows
|
|
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os/exec"
|
|
|
|
|
"syscall"
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-24 11:15:35 +02:00
|
|
|
// detachedProcess is the Win32 flag DETACHED_PROCESS: no console window, no
|
|
|
|
|
// binding to the caller's console.
|
2026-10-24 09:49:16 +02:00
|
|
|
const detachedProcess = 0x00000008
|
|
|
|
|
|
2026-10-24 11:43:42 +02:00
|
|
|
// createBreakawayFromJob is the Win32 flag CREATE_BREAKAWAY_FROM_JOB: the
|
|
|
|
|
// child leaves the parent's job object, so a session-bound job (WinRM, SSH,
|
|
|
|
|
// CI) does not take the daemon down with it. Only works when the job allows
|
|
|
|
|
// it; Spawn falls back to a start without the flag otherwise.
|
|
|
|
|
const createBreakawayFromJob = 0x01000000
|
|
|
|
|
|
2026-10-24 11:15:35 +02:00
|
|
|
// detach detaches the child from the console: own process group (no Ctrl-C
|
|
|
|
|
// from the shell) and no console (no flashing window).
|
2026-10-24 11:43:42 +02:00
|
|
|
func detach(cmd *exec.Cmd, breakaway bool) {
|
|
|
|
|
flags := uint32(syscall.CREATE_NEW_PROCESS_GROUP | detachedProcess)
|
|
|
|
|
if breakaway {
|
|
|
|
|
flags |= createBreakawayFromJob
|
2026-10-24 09:49:16 +02:00
|
|
|
}
|
2026-10-24 11:43:42 +02:00
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: flags}
|
2026-10-24 09:49:16 +02:00
|
|
|
}
|