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

process.go « tableflip « cloudflare « github.com « vendor - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c918a88c888481453109a54bb332777c2e418766 (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
41
42
43
44
45
46
47
package tableflip

import (
	"fmt"
	"os"
	"os/exec"
)

var initialWD, _ = os.Getwd()

type process interface {
	fmt.Stringer
	Signal(sig os.Signal) error
	Wait() error
}

type osProcess struct {
	cmd *exec.Cmd
}

func newOSProcess(executable string, args []string, files []*os.File, env []string) (process, error) {
	cmd := exec.Command(executable, args...)
	cmd.Dir = initialWD
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.ExtraFiles = files
	cmd.Env = env

	if err := cmd.Start(); err != nil {
		return nil, err
	}

	return &osProcess{cmd}, nil
}

func (osp *osProcess) Signal(sig os.Signal) error {
	return osp.cmd.Process.Signal(sig)
}

func (osp *osProcess) Wait() error {
	return osp.cmd.Wait()
}

func (osp *osProcess) String() string {
	return fmt.Sprintf("pid=%d", osp.cmd.Process.Pid)
}