Skip to content

Commit

Permalink
Merge pull request microsoft#1044 from katiewasnothere/fix_exec_in_sh…
Browse files Browse the repository at this point in the history
…im_host

use requested stdio in call  to exec in shim host
  • Loading branch information
katiewasnothere authored Jun 9, 2021
2 parents 106fa2a + 3b54b4f commit 43d3084
Showing 1 changed file with 11 additions and 4 deletions.
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
}
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
}

0 comments on commit 43d3084

Please sign in to comment.