2016-03-18 21:53:27 +03:00
|
|
|
package libcontainerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2016-10-15 02:31:27 +03:00
|
|
|
"sync"
|
2016-05-21 05:04:20 +03:00
|
|
|
|
2016-05-24 02:12:06 +03:00
|
|
|
"github.com/Microsoft/hcsshim"
|
2016-08-16 02:51:45 +03:00
|
|
|
"github.com/docker/docker/pkg/ioutils"
|
2016-03-18 21:53:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// process keeps the state for both main container process and exec process.
|
|
|
|
type process struct {
|
|
|
|
processCommon
|
2016-03-19 06:29:27 +03:00
|
|
|
|
2016-03-21 01:58:23 +03:00
|
|
|
// Platform specific fields are below here.
|
2017-02-02 22:16:11 +03:00
|
|
|
hcsProcess hcsshim.Process
|
2016-03-18 21:53:27 +03:00
|
|
|
}
|
|
|
|
|
2016-10-15 02:31:27 +03:00
|
|
|
type autoClosingReader struct {
|
|
|
|
io.ReadCloser
|
|
|
|
sync.Once
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *autoClosingReader) Read(b []byte) (n int, err error) {
|
|
|
|
n, err = r.ReadCloser.Read(b)
|
|
|
|
if err == io.EOF {
|
|
|
|
r.Once.Do(func() { r.ReadCloser.Close() })
|
|
|
|
}
|
|
|
|
return
|
2016-03-18 21:53:27 +03:00
|
|
|
}
|
2016-05-21 05:04:20 +03:00
|
|
|
|
2016-08-16 02:51:45 +03: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-24 02:12:06 +03:00
|
|
|
|
2016-08-16 02:51:45 +03:00
|
|
|
err := process.CloseStdin()
|
2016-10-12 04:03:12 +03:00
|
|
|
if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) {
|
2016-08-16 02:51:45 +03: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-24 02:12:06 +03:00
|
|
|
|
2016-10-12 04:03:12 +03:00
|
|
|
return nil
|
2016-08-16 02:51:45 +03:00
|
|
|
})
|
2016-05-24 02:12:06 +03:00
|
|
|
}
|