From 5a12e3e229e112e6b316c9ee9f762e36f321271d Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 14 Jun 2025 01:29:40 +0200 Subject: Call atexit handlers on SIGINT and SIGTERM --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index fdde5e8..a9b9ea7 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( "flag" "os" + "os/signal" "path/filepath" "syscall" @@ -39,6 +40,14 @@ func main() { "database name or ‘:memory:’ for an in-memory database") flag.Parse() + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + go func() { + <-sigs + atexit.Exec() + os.Exit(0) + }() + if *debugp { path := Try2(os.Executable()) go watch.File(path, func() { -- cgit v1.2.3