Skip to content

Commit

Permalink
Merge pull request #45 from nulab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vvatanabe authored Nov 15, 2018
2 parents 38c9348 + 1be2b36 commit 7dc706c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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()
}

0 comments on commit 7dc706c

Please sign in to comment.