Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions internal/cmd/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/Microsoft/hcsshim/internal/logfields"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/internal/uvm"
errorspkg "github.com/pkg/errors"
)

// ExecInUvm is a helper function used to execute commands specified in `req` inside the given UVM.
Expand Down Expand Up @@ -48,13 +47,21 @@ func ExecInShimHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int,
if len(req.Args) > 1 {
cmdArgsWithoutName = req.Args[1:]
}
np, err := NewNpipeIO(ctx, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
if err != nil {
return 0, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return -1 here?

Copy link
Copy Markdown
Contributor

@dcantah dcantah Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh we don't for ExecInUvm in this case either or for there being no args, I usually return the error case if err != nil but this is just a nit anyways.

}
defer np.Close(ctx)
cmd := exec.Command(req.Args[0], cmdArgsWithoutName...)
output, err := cmd.CombinedOutput()
cmd.Stdin = np.Stdin()
cmd.Stdout = np.Stdout()
cmd.Stderr = np.Stderr()
err = cmd.Run()
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
return exiterr.ExitCode(), errorspkg.Wrapf(exiterr, "command output: %v", string(output))
return exiterr.ExitCode(), exiterr
}
return -1, errorspkg.Wrapf(err, "command output: %v", string(output))
return -1, err
}
return 0, nil
}