aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/serv.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-30 21:07:23 +0100
committerGitHub <noreply@github.com>2021-06-30 22:07:23 +0200
commit302e8b6d02dc9ccac00284b3cdf9a69c001882c0 (patch)
treefd8a57a78924df719b8c6771d59c6577b163b659 /cmd/serv.go
parent365c4e9316bbcc8bdf9cf68ef237bf18ae8db315 (diff)
downloadgitea-302e8b6d02dc9ccac00284b3cdf9a69c001882c0.tar.gz
gitea-302e8b6d02dc9ccac00284b3cdf9a69c001882c0.zip
Prevent zombie processes (#16314)
Unfortunately go doesn't always ensure that execd processes are completely waited for. On linux this means that zombie processes can occur. This PR ensures that these are waited for by using signal notifier in serv and passing a context elsewhere. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'cmd/serv.go')
-rw-r--r--cmd/serv.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/cmd/serv.go b/cmd/serv.go
index 1c9f5dc44e..40f8b89c9a 100644
--- a/cmd/serv.go
+++ b/cmd/serv.go
@@ -6,14 +6,17 @@
package cmd
import (
+ "context"
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
+ "os/signal"
"regexp"
"strconv"
"strings"
+ "syscall"
"time"
"code.gitea.io/gitea/models"
@@ -273,12 +276,31 @@ func runServ(c *cli.Context) error {
verb = strings.Replace(verb, "-", " ", 1)
}
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ 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()
+ }()
+
var gitcmd *exec.Cmd
verbs := strings.Split(verb, " ")
if len(verbs) == 2 {
- gitcmd = exec.Command(verbs[0], verbs[1], repoPath)
+ gitcmd = exec.CommandContext(ctx, verbs[0], verbs[1], repoPath)
} else {
- gitcmd = exec.Command(verb, repoPath)
+ gitcmd = exec.CommandContext(ctx, verb, repoPath)
}
gitcmd.Dir = setting.RepoRootPath