~sircmpwn/tokidoki-devel

Add handling of SIGINT and SIGTERM v1 APPLIED

Krystian Chachuła: 1
 Add handling of SIGINT and SIGTERM

 1 files changed, 21 insertions(+), 7 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/tokidoki-devel/patches/53623/mbox | git am -3
Learn more about email & git

[PATCH] Add handling of SIGINT and SIGTERM Export this patch

Handle exit signals so that deferred calls are executed. It's mainly
to unlink the socket before exiting.
---
 cmd/tokidoki/main.go | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/cmd/tokidoki/main.go b/cmd/tokidoki/main.go
index 06b817c..9d706fd 100644
--- a/cmd/tokidoki/main.go
+++ b/cmd/tokidoki/main.go
@@ -8,7 +8,9 @@ import (
	"net"
	"net/http"
	"os"
	"os/signal"
	"strings"
	"syscall"

	"github.com/emersion/go-webdav"
	"github.com/emersion/go-webdav/caldav"
@@ -189,12 +191,24 @@ func main() {
	log.Info().Str("address", addr).Msg("starting server")
	log.Debug().Msg("debug output enabled")

	if (cert != "") && (key != "") {
		err = server.ServeTLS(ln, cert, key)
	} else {
		err = server.Serve(ln)
	}
	if err != http.ErrServerClosed {
		log.Fatal().Err(err).Msg("ListenAndServe() error")
	go func() {
		if (cert != "") && (key != "") {
			err = server.ServeTLS(ln, cert, key)
		} else {
			err = server.Serve(ln)
		}
		if err != http.ErrServerClosed {
			log.Fatal().Err(err).Msg("ListenAndServe() error")
		}
	}()

	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
	for sig := range sigCh {
		switch sig {
		case syscall.SIGINT, syscall.SIGTERM:
			server.Shutdown(context.Background())
			return
		}
	}
}
-- 
2.45.1
Thanks!

to git@git.sr.ht:~sircmpwn/tokidoki
  4ca7d8c..7969df1  master -> master