summaryrefslogtreecommitdiff
path: root/go/internal/handler/handler.go
blob: 927998d542f14b592368cd35619eb4b3a3b599f5 (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
package handler

import (
	"os"
	"os/exec"
	"syscall"

	"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
	"gitlab.com/gitlab-org/gitlab-shell/go/internal/logger"
)

func Prepare() error {
	cfg, err := config.New()
	if err != nil {
		return err
	}

	if err := logger.Configure(cfg); err != nil {
		return err
	}

	// Use a working directory that won't get removed or unmounted.
	if err := os.Chdir("/"); err != nil {
		return err
	}

	return nil
}

func execCommand(command string, args ...string) error {
	binPath, err := exec.LookPath(command)
	if err != nil {
		return err
	}

	args = append([]string{binPath}, args...)
	return syscall.Exec(binPath, args, os.Environ())
}