From a9c61691389ed373ada399d25f55a9d10405b4ea Mon Sep 17 00:00:00 2001 From: Amit Krishnan Date: Mon, 14 Mar 2016 13:22:05 -0700 Subject: [PATCH] Remove flush(stdout) in pkg/chrootarchive/diff_unix.go and improve error reporting of flush() to fix #21103 pkg/chrootarchive/diff_unix.go erroneously calls flush on stdout, which tries to read from stdout returning an error. This has been fixed by removing the call and by modifying flush to return errors and checking for these errors on calls to flush. Signed-off-by: Amit Krishnan --- pkg/chrootarchive/archive_unix.go | 5 ++++- pkg/chrootarchive/diff_unix.go | 6 ++++-- pkg/chrootarchive/init_unix.go | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/chrootarchive/archive_unix.go b/pkg/chrootarchive/archive_unix.go index 51a43f67d3..9b26856693 100644 --- a/pkg/chrootarchive/archive_unix.go +++ b/pkg/chrootarchive/archive_unix.go @@ -46,7 +46,10 @@ func untar() { fatal(err) } // fully consume stdin in case it is zero padded - flush(os.Stdin) + if _, err := flush(os.Stdin); err != nil { + fatal(err) + } + os.Exit(0) } diff --git a/pkg/chrootarchive/diff_unix.go b/pkg/chrootarchive/diff_unix.go index 4196dd4b1a..a4adb74d58 100644 --- a/pkg/chrootarchive/diff_unix.go +++ b/pkg/chrootarchive/diff_unix.go @@ -65,8 +65,10 @@ func applyLayer() { fatal(fmt.Errorf("unable to encode layerSize JSON: %s", err)) } - flush(os.Stdout) - flush(os.Stdin) + if _, err := flush(os.Stdin); err != nil { + fatal(err) + } + os.Exit(0) } diff --git a/pkg/chrootarchive/init_unix.go b/pkg/chrootarchive/init_unix.go index 49fcacce90..4f637f17b8 100644 --- a/pkg/chrootarchive/init_unix.go +++ b/pkg/chrootarchive/init_unix.go @@ -23,6 +23,6 @@ func fatal(err error) { // flush consumes all the bytes from the reader discarding // any errors -func flush(r io.Reader) { - io.Copy(ioutil.Discard, r) +func flush(r io.Reader) (bytes int64, err error) { + return io.Copy(ioutil.Discard, r) }