Skip to content

Commit

Permalink
Remove the usage of process groups
Browse files Browse the repository at this point in the history
This unblocks support for Windows, since Windows has a different
construct than process groups and we don't really need process groups
since we don't spawn multiple child/grandchildren processes.

Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed May 24, 2022
1 parent c056745 commit c18eb31
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os/exec"
"path"
"strings"
"syscall"
)

type service struct {
Expand Down Expand Up @@ -145,7 +144,7 @@ func (s *Server) getInfoRefs(_ string, w http.ResponseWriter, r *Request) {
fail500(w, context, err)
return
}
defer cleanUpProcessGroup(cmd)
defer cleanUpProcess(cmd)

w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc))
w.Header().Add("Cache-Control", "no-cache")
Expand Down Expand Up @@ -197,7 +196,7 @@ func (s *Server) postRPC(rpc string, w http.ResponseWriter, r *Request) {
fail500(w, context, err)
return
}
defer cleanUpProcessGroup(cmd)
defer cleanUpProcess(cmd)

if _, err := io.Copy(stdin, body); err != nil {
fail500(w, context, err)
Expand Down Expand Up @@ -243,7 +242,6 @@ func repoExists(p string) bool {

func gitCommand(name string, args ...string) (*exec.Cmd, io.Reader) {
cmd := exec.Command(name, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.Env = os.Environ()

r, _ := cmd.StdoutPipe()
Expand Down
5 changes: 2 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os/exec"
"regexp"
"strings"
"syscall"
)

var reSlashDedup = regexp.MustCompile(`\/{2,}`)
Expand All @@ -26,14 +25,14 @@ func logInfo(context string, message string) {
log.Printf("%s: %s\n", context, message)
}

func cleanUpProcessGroup(cmd *exec.Cmd) {
func cleanUpProcess(cmd *exec.Cmd) {
if cmd == nil {
return
}

process := cmd.Process
if process != nil && process.Pid > 0 {
syscall.Kill(-process.Pid, syscall.SIGTERM)
process.Kill()
}

go cmd.Wait()
Expand Down

0 comments on commit c18eb31

Please sign in to comment.