Skip to content

Commit

Permalink
process: also handle SIGHUP in onInterruptSignal
Browse files Browse the repository at this point in the history
`onInterruptSignal` is a function that accepts a cleanup function and
runs it on SIGINT and SIGTERM. Update to also run cleanup on SIGHUP.
Major use case is to handle broken SSH connections.
  • Loading branch information
johnwonkim committed Oct 26, 2023
1 parent 5ec3351 commit b358b1d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"syscall"
)

// OnInterruptSignal invokes fn when SIGNINT/SIGTERM is received.
// OnInterruptSignal invokes fn when an interrupt signal is received.
// We loosely define the interrupt signal as SIGINT, SIGTERM, and SIGHUP.
func onInterruptSignal(fn func()) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
go func() {
<-signalChan
fn()
Expand Down

0 comments on commit b358b1d

Please sign in to comment.