Skip to content

Commit

Permalink
Merge pull request #7 from aryan9600/remove-process-groups
Browse files Browse the repository at this point in the history
Add support for Windows by removing the usage of process groups
  • Loading branch information
pjbgf authored May 24, 2022
2 parents c056745 + c18eb31 commit 727baad
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 727baad

Please sign in to comment.