mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-14 03:31:58 +08:00
merge: resolve signal handling conflict preserving testability and Windows support
Integrate Windows compatibility (conditional SIGTERM) from upstream while retaining signalNotifyFn injection hook for testing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -978,21 +979,30 @@ func (b *tailBuffer) String() string {
|
||||
|
||||
func forwardSignals(ctx context.Context, cmd *exec.Cmd, logErrorFn func(string)) {
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signalNotifyFn(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
||||
signals := []os.Signal{syscall.SIGINT}
|
||||
if runtime.GOOS != "windows" {
|
||||
signals = append(signals, syscall.SIGTERM)
|
||||
}
|
||||
signalNotifyFn(sigCh, signals...)
|
||||
|
||||
go func() {
|
||||
defer signalStopFn(sigCh)
|
||||
select {
|
||||
case sig := <-sigCh:
|
||||
logErrorFn(fmt.Sprintf("Received signal: %v", sig))
|
||||
if cmd.Process != nil {
|
||||
cmd.Process.Signal(syscall.SIGTERM)
|
||||
time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {
|
||||
if cmd.Process != nil {
|
||||
cmd.Process.Kill()
|
||||
}
|
||||
})
|
||||
if cmd.Process == nil {
|
||||
return
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
_ = cmd.Process.Kill()
|
||||
return
|
||||
}
|
||||
_ = cmd.Process.Signal(syscall.SIGTERM)
|
||||
time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {
|
||||
if cmd.Process != nil {
|
||||
_ = cmd.Process.Kill()
|
||||
}
|
||||
})
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}()
|
||||
@@ -1015,6 +1025,11 @@ func terminateProcess(cmd *exec.Cmd) *time.Timer {
|
||||
return nil
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
_ = cmd.Process.Kill()
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = cmd.Process.Signal(syscall.SIGTERM)
|
||||
|
||||
return time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {
|
||||
|
||||
Reference in New Issue
Block a user