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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/helper/helper.go')
-rw-r--r--internal/helper/helper.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/helper/helper.go b/internal/helper/helper.go
new file mode 100644
index 000000000..9886afd69
--- /dev/null
+++ b/internal/helper/helper.go
@@ -0,0 +1,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()
+}