We should check if '/usr/sbin' in environment variable PATH or not before append it.
// ExecReq executes the supplied Request by starting a child process
// to service the request. Returns a Response if successful.
func ExecReq(parent context.Context, log logging.Logger, binPath string, req *Request) (res *Response, err error) {
if req == nil {
return nil, errors.New("nil request")
}
ctx, killChild := context.WithCancel(parent)
defer killChild()
child := exec.CommandContext(ctx, binPath)
child.Stderr = &cmdLogger{
logFn: log.Error,
prefix: binPath,
}
toChild, err := child.StdinPipe()
if err != nil {
return nil, err
}
fromChild, err := child.StdoutPipe()
if err != nil {
return nil, err
}
conn := NewStdioConn("server", binPath, fromChild, toChild)
// ensure that /usr/sbin is in $PATH
os.Setenv("PATH", os.Getenv("PATH")+":/usr/sbin")
child.Env = os.Environ()