Commit 8b14e2e8 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Run git-xxx-pack in its own process group

parent bfac1947
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"path" "path"
"regexp" "regexp"
"strings" "strings"
"syscall"
) )
type gitService struct { type gitService struct {
...@@ -176,8 +177,7 @@ func handleGetInfoRefs(env gitEnv, _ string, path string, w http.ResponseWriter, ...@@ -176,8 +177,7 @@ func handleGetInfoRefs(env gitEnv, _ string, path string, w http.ResponseWriter,
} }
// Prepare our Git subprocess // Prepare our Git subprocess
cmd := exec.Command("git", subCommand(rpc), "--stateless-rpc", "--advertise-refs", path) cmd := gitCommand(env, "git", subCommand(rpc), "--stateless-rpc", "--advertise-refs", path)
setCmdEnv(cmd, env)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
fail500(w, err) fail500(w, err)
...@@ -212,11 +212,16 @@ func subCommand(rpc string) string { ...@@ -212,11 +212,16 @@ func subCommand(rpc string) string {
return strings.TrimPrefix(rpc, "git-") return strings.TrimPrefix(rpc, "git-")
} }
func setCmdEnv(cmd *exec.Cmd, env gitEnv) { func gitCommand(env gitEnv, name string, args ...string) *exec.Cmd {
cmd := exec.Command(name, args...)
// Start the command in its own process group (nice for signalling)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
// Explicitly set the environment for the Git command
cmd.Env = []string{ cmd.Env = []string{
fmt.Sprintf("PATH=%s", os.Getenv("PATH")), fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
fmt.Sprintf("GL_ID=%s", env.GL_ID), fmt.Sprintf("GL_ID=%s", env.GL_ID),
} }
return cmd
} }
func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r *http.Request) { func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r *http.Request) {
...@@ -235,8 +240,7 @@ func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r ...@@ -235,8 +240,7 @@ func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r
} }
// Prepare our Git subprocess // Prepare our Git subprocess
cmd := exec.Command("git", subCommand(rpc), "--stateless-rpc", path) cmd := gitCommand(env, "git", subCommand(rpc), "--stateless-rpc", path)
setCmdEnv(cmd, env)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
fail500(w, err) fail500(w, err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment