github.com/MaximeAubanel/moby@v1.13.1/libcontainerd/process_windows.go (about)

     1  package libcontainerd
     2  
     3  import (
     4  	"io"
     5  	"sync"
     6  
     7  	"github.com/Microsoft/hcsshim"
     8  	"github.com/docker/docker/pkg/ioutils"
     9  )
    10  
    11  // process keeps the state for both main container process and exec process.
    12  type process struct {
    13  	processCommon
    14  
    15  	// Platform specific fields are below here.
    16  
    17  	// commandLine is to support returning summary information for docker top
    18  	commandLine string
    19  	hcsProcess  hcsshim.Process
    20  }
    21  
    22  type autoClosingReader struct {
    23  	io.ReadCloser
    24  	sync.Once
    25  }
    26  
    27  func (r *autoClosingReader) Read(b []byte) (n int, err error) {
    28  	n, err = r.ReadCloser.Read(b)
    29  	if err == io.EOF {
    30  		r.Once.Do(func() { r.ReadCloser.Close() })
    31  	}
    32  	return
    33  }
    34  
    35  func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) io.WriteCloser {
    36  	return ioutils.NewWriteCloserWrapper(pipe, func() error {
    37  		if err := pipe.Close(); err != nil {
    38  			return err
    39  		}
    40  
    41  		err := process.CloseStdin()
    42  		if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) {
    43  			// This error will occur if the compute system is currently shutting down
    44  			if perr, ok := err.(*hcsshim.ProcessError); ok && perr.Err != hcsshim.ErrVmcomputeOperationInvalidState {
    45  				return err
    46  			}
    47  		}
    48  
    49  		return nil
    50  	})
    51  }