...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package bpm
15
16 import (
17 "context"
18 "os/exec"
19 "strings"
20 "syscall"
21
22 "github.com/chaos-mesh/chaos-mesh/pkg/mock"
23 )
24
25
26 func (b *ProcessBuilder) Build() *ManagedProcess {
27 args := b.args
28 cmd := b.cmd
29
30 if len(b.nsOptions) > 0 {
31 args = append([]string{"--", cmd}, args...)
32 for _, option := range b.nsOptions {
33 args = append([]string{"-" + nsArgMap[option.Typ], option.Path}, args...)
34 }
35
36 if b.localMnt {
37 args = append([]string{"-l"}, args...)
38 }
39 cmd = nsexecPath
40 }
41
42 if b.pause {
43 args = append([]string{cmd}, args...)
44 cmd = pausePath
45 }
46
47 if c := mock.On("MockProcessBuild"); c != nil {
48 f := c.(func(context.Context, string, ...string) *exec.Cmd)
49 return &ManagedProcess{
50 Cmd: f(b.ctx, cmd, args...),
51 Identifier: b.identifier,
52 }
53 }
54
55 log.Info("build command", "command", cmd+" "+strings.Join(args, " "))
56
57 command := exec.CommandContext(b.ctx, cmd, args...)
58 command.SysProcAttr = &syscall.SysProcAttr{}
59 command.SysProcAttr.Pdeathsig = syscall.SIGTERM
60
61 return &ManagedProcess{
62 Cmd: command,
63 Identifier: b.identifier,
64 }
65 }
66