aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/cmd.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-07-14 15:43:13 +0100
committerGitHub <noreply@github.com>2021-07-14 10:43:13 -0400
commit3dcb3e9073d825a4ada184f832892cf4bd5836a3 (patch)
treeaab77b7726f0e20f34b452df166113950ff5fc62 /cmd/cmd.go
parentee43d70a0c237ef9c02b99b9b49d1af348840319 (diff)
downloadgitea-3dcb3e9073d825a4ada184f832892cf4bd5836a3.tar.gz
gitea-3dcb3e9073d825a4ada184f832892cf4bd5836a3.zip
Second attempt at preventing zombies (#16326)
* Second attempt at preventing zombies * Ensure that the pipes are closed in ssh.go * Ensure that a cancellable context is passed up in cmd/* http requests * Make cmd.fail return properly so defers are obeyed * Ensure that something is sent to stdout in case of blocks here Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint 2 Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint 3 Signed-off-by: Andrew Thornton <art27@cantab.net> * fixup Signed-off-by: Andrew Thornton <art27@cantab.net> * Apply suggestions from code review Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'cmd/cmd.go')
-rw-r--r--cmd/cmd.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/cmd.go b/cmd/cmd.go
index bb768cc159..8d9d1ee077 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -7,9 +7,13 @@
package cmd
import (
+ "context"
"errors"
"fmt"
+ "os"
+ "os/signal"
"strings"
+ "syscall"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
@@ -66,3 +70,25 @@ func initDBDisableConsole(disableConsole bool) error {
}
return nil
}
+
+func installSignals() (context.Context, context.CancelFunc) {
+ ctx, cancel := context.WithCancel(context.Background())
+ go func() {
+ // install notify
+ signalChannel := make(chan os.Signal, 1)
+
+ signal.Notify(
+ signalChannel,
+ syscall.SIGINT,
+ syscall.SIGTERM,
+ )
+ select {
+ case <-signalChannel:
+ case <-ctx.Done():
+ }
+ cancel()
+ signal.Reset()
+ }()
+
+ return ctx, cancel
+}