mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
* Add managed background terminal sessions * Stop background terminals on TUI exit * Cover approved local network sandbox mode * Polish background terminal rendering * Tighten exec session cleanup guidance * Address background terminal review feedback * Kill exec session trees on Windows * Trigger CI for Windows cleanup
31 lines
912 B
Go
31 lines
912 B
Go
//go:build windows
|
|
|
|
package tools
|
|
|
|
import (
|
|
"os/exec"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// bashWaitDelay bounds how long Wait blocks for the I/O pipes to drain after the
|
|
// process has exited or the context's Cancel has run, so a backgrounded child
|
|
// holding the pipes cannot make Run() hang past the timeout. Var (not const) so
|
|
// tests can shorten it.
|
|
var bashWaitDelay = 2 * time.Second
|
|
|
|
// hardenProcessLifetime makes a Windows shell command killable as a process
|
|
// tree. cmd.exe starts helper commands as child processes, so killing only the
|
|
// shell can leave a long-running child alive and holding cwd/temp handles after
|
|
// Zero exits.
|
|
func hardenProcessLifetime(command *exec.Cmd) {
|
|
command.WaitDelay = bashWaitDelay
|
|
command.Cancel = func() error {
|
|
if command.Process == nil {
|
|
return nil
|
|
}
|
|
_ = exec.Command("taskkill.exe", "/T", "/F", "/PID", strconv.Itoa(command.Process.Pid)).Run()
|
|
return nil
|
|
}
|
|
}
|