Skip to content

Commit 7dc706c

Browse files
authored
Merge pull request #45 from nulab/develop
Develop
2 parents 38c9348 + 1be2b36 commit 7dc706c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

githttpxfer/git.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path"
9+
"syscall"
910
)
1011

1112
func newGit(rootPath string, binPath string, uploadPack bool, receivePack bool) *git {
@@ -49,6 +50,7 @@ func (g *git) Exists(repoPath string) bool {
4950
func (g *git) GitCommand(repoPath string, args ...string) *exec.Cmd {
5051
command := exec.Command(g.binPath, args...)
5152
command.Dir = g.GetAbsolutePath(repoPath)
53+
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
5254
return command
5355
}
5456

githttpxfer/githttpxfer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {
266266
args := []string{rpc, "--stateless-rpc", "."}
267267
cmd := ghx.Git.GitCommand(repoPath, args...)
268268
cmd.Env = ctx.Env()
269+
defer cleanUpProcessGroup(cmd)
269270

270271
stdin, err := cmd.StdinPipe()
271272
if err != nil {
@@ -283,7 +284,8 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {
283284
}
284285
defer stdout.Close()
285286

286-
if err = cmd.Start(); err != nil {
287+
err = cmd.Start()
288+
if err != nil {
287289
ghx.logger.Error("failed to starts the specified command. ", err.Error())
288290
RenderInternalServerError(res.Writer)
289291
return

githttpxfer/support.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package githttpxfer
22

33
import (
44
"net/http"
5+
"os/exec"
56
"strings"
7+
"syscall"
68
)
79

810
func getServiceType(req *http.Request) string {
@@ -12,3 +14,13 @@ func getServiceType(req *http.Request) string {
1214
}
1315
return strings.Replace(serviceType, "git-", "", 1)
1416
}
17+
18+
func cleanUpProcessGroup(cmd *exec.Cmd) {
19+
if cmd == nil {
20+
return
21+
}
22+
if process := cmd.Process; process != nil && process.Pid > 0 {
23+
syscall.Kill(-process.Pid, syscall.SIGTERM)
24+
}
25+
cmd.Wait()
26+
}

0 commit comments

Comments
 (0)