From 934155437bfdfbc042a6c1693187a1361cac6bdb Mon Sep 17 00:00:00 2001 From: John Kim Date: Wed, 25 Oct 2023 23:20:50 +0000 Subject: [PATCH] process: also handle SIGHUP in `onInterruptSignal` `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. --- process.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/process.go b/process.go index 3f62f39..d7802f6 100644 --- a/process.go +++ b/process.go @@ -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()