MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / commandOutput

Method commandOutput

pkg/funclet/runtime/runc/runc.go:93–131  ·  view source on GitHub ↗
(args ...string)

Source from the content-addressed store, hash-verified

91}
92
93func (r *RuncConfig) commandOutput(args ...string) (data []byte, err error) {
94 command := r.Command
95 if command == "" {
96 command = DefaultCommand
97 }
98 cmd := exec.Command(command, args...)
99 logs.V(9).Infof("start command %v", cmd.Args)
100 var stdout, stderr bytes.Buffer
101 cmd.Stdout = &stdout
102 cmd.Stderr = &stderr
103 if err := cmd.Start(); err != nil {
104 if exErr, ok := err.(*exec.Error); ok {
105 if exErr.Err == exec.ErrNotFound || exErr.Err == os.ErrNotExist {
106 return nil, fmt.Errorf("runc not installed on system")
107 }
108 }
109 return nil, err
110 }
111
112 if err := cmd.Wait(); err != nil {
113 if sysErr, ok := err.(*os.SyscallError); ok {
114 // ignore error "no child process"
115 if e := sysErr.Err.(syscall.Errno); e == syscall.ECHILD {
116 return stdout.Bytes(), nil
117 }
118 } else {
119 logs.Errorf("command [%s] cmd.Wait err %s", cmd.Args, err)
120 }
121 logs.V(9).Infof("command %s stdout %s stderr %s", cmd.Args, stdout.Bytes(), stderr.Bytes())
122 if exitErr, ok := err.(*exec.ExitError); ok {
123 if ws, ok := exitErr.Sys().(syscall.WaitStatus); ok {
124 logs.Errorf("exit code %+v %+v", ws, exitErr)
125 }
126 return stderr.Bytes(), fmt.Errorf("runc execution error")
127 }
128 return stderr.Bytes(), err
129 }
130 return stdout.Bytes(), nil
131}
132
133type CreateOpts struct {
134 ID string

Callers 2

StateMethod · 0.95
ListMethod · 0.95

Calls 7

VFunction · 0.92
ErrorfFunction · 0.92
InfofMethod · 0.80
ErrorfMethod · 0.80
BytesMethod · 0.80
StartMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected