Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion internal/interrupt_handler/interrupt_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ func (handler *InterruptHandler) registerForInterrupts() {
var interruptCause InterruptCause
for {
select {
case <-signalChannel:
case signal := <-signalChannel:
interruptCause = InterruptCauseSignal
signalChildren(signal)
case <-abortChannel:
interruptCause = InterruptCauseAbortByOtherProcess
case <-handler.stop:
Expand Down Expand Up @@ -158,6 +159,19 @@ func (handler *InterruptHandler) registerForInterrupts() {
}(abortChannel)
}

// Propagate the signal to all child processes.
func signalChildren(osSignal os.Signal) {
sysSignal := syscall.SIGTERM
if osSignal == os.Interrupt {
sysSignal = syscall.SIGINT
}
// Minus sign is for PGID rather than PID.
err := syscall.Kill(-syscall.Getpid(), sysSignal)
if err != nil {
os.Stderr.WriteString("Failed to signal child processes: " + err.Error() + "\n")
}
}

func (handler *InterruptHandler) Status() InterruptStatus {
handler.lock.Lock()
status := InterruptStatus{
Expand Down