LCOW: Capture stderr on external process. Log actual error rather than throwaway

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2018-08-14 15:07:46 -07:00
parent f586fe5637
commit dffc966165
2 changed files with 20 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"strings"
"github.com/containerd/continuity/driver"
@ -173,6 +174,9 @@ func StatAt(remote builder.Source, path string) (os.FileInfo, error) {
func FullPath(remote builder.Source, path string) (string, error) {
fullPath, err := remote.Root().ResolveScopedPath(path, true)
if err != nil {
if runtime.GOOS == "windows" {
return "", fmt.Errorf("failed to resolve scoped path %s (%s): %s. Possible cause is a forbidden path outside the build context", path, fullPath, err)
}
return "", fmt.Errorf("Forbidden path outside the build context: %s (%s)", path, fullPath) // backwards compat with old error
}
return fullPath, nil

View file

@ -3,6 +3,7 @@
package lcow // import "github.com/docker/docker/daemon/graphdriver/lcow"
import (
"bytes"
"errors"
"fmt"
"io"
@ -385,7 +386,15 @@ func (svm *serviceVM) deleteUnionMount(mountName string, disks ...hcsshim.Mapped
}
func (svm *serviceVM) runProcess(command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
process, err := svm.config.RunProcess(command, stdin, stdout, stderr)
var process hcsshim.Process
var err error
errOut := &bytes.Buffer{}
if stderr != nil {
process, err = svm.config.RunProcess(command, stdin, stdout, stderr)
} else {
process, err = svm.config.RunProcess(command, stdin, stdout, errOut)
}
if err != nil {
return err
}
@ -398,7 +407,12 @@ func (svm *serviceVM) runProcess(command string, stdin io.Reader, stdout io.Writ
}
if exitCode != 0 {
return fmt.Errorf("svm.runProcess: command %s failed with exit code %d", command, exitCode)
// If the caller isn't explicitly capturing stderr output, then capture it here instead.
e := fmt.Sprintf("svm.runProcess: command %s failed with exit code %d", command, exitCode)
if stderr == nil {
e = fmt.Sprintf("%s. (%s)", e, errOut.String())
}
return fmt.Errorf(e)
}
return nil
}