2016-03-18 18:53:27 +00:00
|
|
|
package libcontainerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2016-10-14 23:31:27 +00:00
|
|
|
"sync"
|
2016-05-21 02:04:20 +00:00
|
|
|
|
2016-05-23 23:12:06 +00:00
|
|
|
"github.com/Microsoft/hcsshim"
|
2016-08-15 23:51:45 +00:00
|
|
|
"github.com/docker/docker/pkg/ioutils"
|
2016-03-18 18:53:27 +00:00
|
|
|
)
|
|
|
|
|
2016-10-14 23:31:27 +00:00
|
|
|
type autoClosingReader struct {
|
|
|
|
io.ReadCloser
|
|
|
|
sync.Once
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *autoClosingReader) Read(b []byte) (n int, err error) {
|
|
|
|
n, err = r.ReadCloser.Read(b)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2016-10-14 23:31:27 +00:00
|
|
|
r.Once.Do(func() { r.ReadCloser.Close() })
|
|
|
|
}
|
|
|
|
return
|
2016-03-18 18:53:27 +00:00
|
|
|
}
|
2016-05-21 02:04:20 +00:00
|
|
|
|
2016-08-15 23:51:45 +00:00
|
|
|
func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) io.WriteCloser {
|
|
|
|
return ioutils.NewWriteCloserWrapper(pipe, func() error {
|
|
|
|
if err := pipe.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-23 23:12:06 +00:00
|
|
|
|
2016-08-15 23:51:45 +00:00
|
|
|
err := process.CloseStdin()
|
2016-10-12 01:03:12 +00:00
|
|
|
if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) {
|
2016-08-15 23:51:45 +00:00
|
|
|
// This error will occur if the compute system is currently shutting down
|
|
|
|
if perr, ok := err.(*hcsshim.ProcessError); ok && perr.Err != hcsshim.ErrVmcomputeOperationInvalidState {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 23:12:06 +00:00
|
|
|
|
2016-10-12 01:03:12 +00:00
|
|
|
return nil
|
2016-08-15 23:51:45 +00:00
|
|
|
})
|
2016-05-23 23:12:06 +00:00
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
func (p *process) Cleanup() error {
|
|
|
|
return nil
|
|
|
|
}
|