Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions githttpxfer/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path"
"syscall"
)

func newGit(rootPath string, binPath string, uploadPack bool, receivePack bool) *git {
Expand Down Expand Up @@ -49,6 +50,7 @@ func (g *git) Exists(repoPath string) bool {
func (g *git) GitCommand(repoPath string, args ...string) *exec.Cmd {
command := exec.Command(g.binPath, args...)
command.Dir = g.GetAbsolutePath(repoPath)
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
return command
}

Expand Down
4 changes: 3 additions & 1 deletion githttpxfer/githttpxfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {
args := []string{rpc, "--stateless-rpc", "."}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()
defer cleanUpProcessGroup(cmd)

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

if err = cmd.Start(); err != nil {
err = cmd.Start()
if err != nil {
ghx.logger.Error("failed to starts the specified command. ", err.Error())
RenderInternalServerError(res.Writer)
return
Expand Down
12 changes: 12 additions & 0 deletions githttpxfer/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package githttpxfer

import (
"net/http"
"os/exec"
"strings"
"syscall"
)

func getServiceType(req *http.Request) string {
Expand All @@ -12,3 +14,13 @@ func getServiceType(req *http.Request) string {
}
return strings.Replace(serviceType, "git-", "", 1)
}

func cleanUpProcessGroup(cmd *exec.Cmd) {
if cmd == nil {
return
}
if process := cmd.Process; process != nil && process.Pid > 0 {
syscall.Kill(-process.Pid, syscall.SIGTERM)
}
cmd.Wait()
}