2016-03-18 14:53:27 -04:00
|
|
|
package libcontainerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2016-10-14 19:31:27 -04:00
|
|
|
"sync"
|
2016-05-20 22:04:20 -04:00
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
"github.com/Microsoft/hcsshim"
|
2016-08-15 19:51:45 -04:00
|
|
|
"github.com/docker/docker/pkg/ioutils"
|
2016-03-18 14:53:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// process keeps the state for both main container process and exec process.
|
|
|
|
type process struct {
|
|
|
|
processCommon
|
2016-03-18 23:29:27 -04:00
|
|
|
|
2016-03-20 18:58:23 -04:00
|
|
|
// Platform specific fields are below here.
|
|
|
|
|
|
|
|
// commandLine is to support returning summary information for docker top
|
|
|
|
commandLine string
|
2016-05-23 19:12:06 -04:00
|
|
|
hcsProcess hcsshim.Process
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
2016-10-14 19:31:27 -04: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 14:53:27 -04:00
|
|
|
}
|
2016-05-20 22:04:20 -04:00
|
|
|
|
2016-08-15 19:51:45 -04: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 19:12:06 -04:00
|
|
|
|
2016-08-15 19:51:45 -04:00
|
|
|
// We do not need to lock container ID here, even though
|
|
|
|
// we are calling into hcsshim. This is safe, because the
|
|
|
|
// only place that closes this process handle is this method.
|
|
|
|
err := process.CloseStdin()
|
|
|
|
if err != nil && !hcsshim.IsNotExist(err) {
|
|
|
|
// 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 19:12:06 -04:00
|
|
|
|
2016-09-20 20:31:24 -04:00
|
|
|
return err
|
2016-08-15 19:51:45 -04:00
|
|
|
})
|
2016-05-23 19:12:06 -04:00
|
|
|
}
|