Skip to content

Commit

Permalink
fix: initd exec endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-jacques committed Jan 15, 2025
1 parent 80ffba0 commit b7c7260
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions initd/exec/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ func Exec(ctx context.Context, opts api.ExecOptions) (*api.ExecResult, error) {
return nil, errdefs.NewInvalidArgument("cmd cannot be empty")
}

name := opts.Cmd[0]
args := opts.Cmd[1:]

stdout := bytes.Buffer{}
stderr := bytes.Buffer{}

timeoutCtx, cancel := context.WithTimeout(ctx, opts.GetTimeout())
defer cancel()

cmd := exec.CommandContext(timeoutCtx, opts.Cmd[0])

cmd.Path = opts.Cmd[0]
cmd.Args = opts.Cmd
cmd := exec.CommandContext(timeoutCtx, name, args...)
if cmd.Err != nil {
return nil, errdefs.NewInvalidArgument(cmd.Err.Error())
}

cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Stdin = nil

if err := cmd.Run(); err != nil {
if _, ok := err.(*exec.ExitError); !ok {
return nil, err
return nil, errdefs.NewInvalidArgument(err.Error())
}
}

Expand Down

0 comments on commit b7c7260

Please sign in to comment.