fix(core): take over agent, reuse callbacks

- Kill running agents before replace
- Retry copy with backoff while locked
- Reuse syscall callbacks at package scope
- Add callback regression test
This commit is contained in:
2026-09-02 00:00:24 +03:00
parent ac31e52a8c
commit 536ea9a53e
10 changed files with 281 additions and 29 deletions
+1 -7
View File
@@ -17,7 +17,7 @@ var (
procGetFileType = kernel32.NewProc("GetFileType")
user32 = syscall.NewLazyDLL("user32.dll")
procShowWindow = user32.NewProc("ShowWindow")
consoleCtrlCallback uintptr
consoleCtrlCallback = syscall.NewCallback(consoleCtrlHandler)
)
const (
@@ -58,17 +58,11 @@ func ShowConsole() {
// ProtectFromConsoleClose ignores Ctrl+C/Break/close so Task Scheduler and
// explorer do not kill the process when the flashed console goes away.
func ProtectFromConsoleClose() {
if consoleCtrlCallback == 0 {
consoleCtrlCallback = syscall.NewCallback(consoleCtrlHandler)
}
_, _, _ = procSetConsoleCtrl.Call(consoleCtrlCallback, 1)
}
// AllowConsoleKill restores default Ctrl+C handling for -foreground.
func AllowConsoleKill() {
if consoleCtrlCallback == 0 {
return
}
_, _, _ = procSetConsoleCtrl.Call(consoleCtrlCallback, 0)
}