From 90b7418f9d83946b98222e7fc24308bf55d3e164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0brahim=20G=C3=BCng=C3=B6r?= Date: Mon, 12 Sep 2022 11:09:12 +0300 Subject: [PATCH] main: use `signal.NotifyContext` to handle signals (#510) --- README.md | 2 +- main.go | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2a78a846a..f4fc7f776 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ For macOS, a [homebrew](https://brew.sh) tap is provided: ### Unofficial Releases (by Community) [![Packaging status](https://repology.org/badge/tiny-repos/s5cmd.svg)](https://repology.org/project/s5cmd/versions) -> **Warning** +> **Warning** > These releases are maintained by the community. They might be out of date compared to the official releases. #### MacPorts diff --git a/main.go b/main.go index 557fb5dad..678321a1b 100644 --- a/main.go +++ b/main.go @@ -10,15 +10,8 @@ import ( ) func main() { - ctx, cancel := context.WithCancel(context.Background()) - - go func() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, syscall.SIGTERM) - <-ch - cancel() - signal.Stop(ch) - }() + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer cancel() if err := command.Main(ctx, os.Args); err != nil { os.Exit(1)