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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user