Skip to content

Commit 43d3084

Browse files
author
Kathryn Baldauf
authored
Merge pull request microsoft#1044 from katiewasnothere/fix_exec_in_shim_host
use requested stdio in call to exec in shim host
2 parents 106fa2a + 3b54b4f commit 43d3084

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

internal/cmd/diag.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/Microsoft/hcsshim/internal/logfields"
1010
"github.com/Microsoft/hcsshim/internal/shimdiag"
1111
"github.com/Microsoft/hcsshim/internal/uvm"
12-
errorspkg "github.com/pkg/errors"
1312
)
1413

1514
// ExecInUvm is a helper function used to execute commands specified in `req` inside the given UVM.
@@ -48,13 +47,21 @@ func ExecInShimHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int,
4847
if len(req.Args) > 1 {
4948
cmdArgsWithoutName = req.Args[1:]
5049
}
50+
np, err := NewNpipeIO(ctx, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
51+
if err != nil {
52+
return 0, err
53+
}
54+
defer np.Close(ctx)
5155
cmd := exec.Command(req.Args[0], cmdArgsWithoutName...)
52-
output, err := cmd.CombinedOutput()
56+
cmd.Stdin = np.Stdin()
57+
cmd.Stdout = np.Stdout()
58+
cmd.Stderr = np.Stderr()
59+
err = cmd.Run()
5360
if err != nil {
5461
if exiterr, ok := err.(*exec.ExitError); ok {
55-
return exiterr.ExitCode(), errorspkg.Wrapf(exiterr, "command output: %v", string(output))
62+
return exiterr.ExitCode(), exiterr
5663
}
57-
return -1, errorspkg.Wrapf(err, "command output: %v", string(output))
64+
return -1, err
5865
}
5966
return 0, nil
6067
}

0 commit comments

Comments
 (0)