From d82ae69625cbfceb33af8e26d71b8a46eeb1a10c Mon Sep 17 00:00:00 2001 From: Catherine Date: Sun, 23 Nov 2025 03:03:04 +0000 Subject: [PATCH] Simplify SIGINT handling code. NFC --- src/main.go | 7 ++----- src/signal_other.go | 6 ++++-- src/signal_posix.go | 9 +++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main.go b/src/main.go index 696648f..22ec43e 100644 --- a/src/main.go +++ b/src/main.go @@ -385,10 +385,7 @@ func Main() { log.Println("serve: ready") } - interrupt := make(chan struct{}) - OnInterrupt(func() { interrupt <- struct{}{} }) - <-interrupt - - log.Println("exiting gracefully") + WaitForInterrupt() + log.Println("serve: exiting") } } diff --git a/src/signal_other.go b/src/signal_other.go index ecb6b48..ac617f4 100644 --- a/src/signal_other.go +++ b/src/signal_other.go @@ -6,6 +6,8 @@ func OnReload(handler func()) { // not implemented } -func OnInterrupt(handler func()) { - // not implemented +func WaitForInterrupt() { + for { + // Ctrl+C not supported + } } diff --git a/src/signal_posix.go b/src/signal_posix.go index c6955bf..b38531a 100644 --- a/src/signal_posix.go +++ b/src/signal_posix.go @@ -19,12 +19,9 @@ func OnReload(handler func()) { }() } -func OnInterrupt(handler func()) { +func WaitForInterrupt() { sigint := make(chan os.Signal, 1) signal.Notify(sigint, syscall.SIGINT) - go func() { - <-sigint - signal.Stop(sigint) - handler() - }() + <-sigint + signal.Stop(sigint) }