Null-DRM-Official/apps/streamd/internal/supervisor/proc_windows.go
404errordeveloper 5b6f38c9cf
All checks were successful
release / build-and-upload (push) Successful in 6m56s
streamd v0.2.3: fix NRE Spectre crash under daemon (Linux PTY)
Wrap N_m3u8DL-RE with util-linux script so Spectre gets a real TTY; drop
subtitles; pin COLUMNS/LINES; kill process group on stop. Fixes immediate
'downloader exited before any media arrived' on serve start.
2026-10-10 19:54:41 +02:00

60 lines
1.4 KiB
Go

//go:build windows
package supervisor
import (
"io"
"os"
"os/exec"
"strconv"
"syscall"
)
func hideWindow(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
CreationFlags: 0x08000000, // CREATE_NO_WINDOW
}
}
func killProcessTree(cmd *exec.Cmd) error {
if cmd == nil || cmd.Process == nil {
return nil
}
pid := cmd.Process.Pid
return exec.Command("taskkill", "/T", "/F", "/PID", strconv.Itoa(pid)).Run()
}
// startNRELogged attaches logFile as Stdout/Stderr. Windows CREATE_NO_WINDOW
// avoids the Spectre pipe-width crash that hits Linux daemons.
func startNRELogged(cmd *exec.Cmd, logFile *os.File) (io.Closer, bool, error) {
cmd.Stdout = logFile
cmd.Stderr = logFile
if err := cmd.Start(); err != nil {
return nil, true, err
}
return nopCloser{}, true, nil
}
type nopCloser struct{}
func (nopCloser) Close() error { return nil }
func processDead(pid int) bool {
p, err := os.FindProcess(pid)
if err != nil {
return true
}
// On Windows, FindProcess always succeeds; OpenProcess is needed.
// tasklist-style: try duplicate handle via Signal is unsupported.
// Use Windows API indirectly: if Wait with timeout 0 isn't available,
// check via tasklist is heavy — use syscall OpenProcess.
const PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
h, err := syscall.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return true
}
_ = p
syscall.CloseHandle(h)
return false
}