Welcome to mirror list, hosted at ThFree Co, Russian Federation.

helper.go « helper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9886afd69eb2d6c4a7921e0fdc6a4235e1af6104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package helper

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

func Fail500(w http.ResponseWriter, r *http.Request, err error) {
	http.Error(w, "Internal server error", 500)
	printError(r, err)
}

func LogError(r *http.Request, err error) {
	printError(r, err)
}

func printError(r *http.Request, err error) {
	if r != nil {
		log.Printf("error: %s %q: %v", r.Method, r.RequestURI, err)
	} else {
		log.Printf("error: %v", err)
	}
}

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

	process := cmd.Process
	if process != nil && process.Pid > 0 {
		// Send SIGTERM to the process group of cmd
		syscall.Kill(-process.Pid, syscall.SIGTERM)
	}

	// reap our child process
	cmd.Wait()
}