Files
docker-cli/components/engine/vendor/src/github.com/Microsoft/hcsshim/utils.go
T
Darren Stahl 97adc78725 Revendor hcsshim
Signed-off-by: Darren Stahl <darst@microsoft.com>
Upstream-commit: c58d0358c359e391707698b12850524137ef56ae
Component: engine
2016-08-16 17:28:49 -07:00

40 lines
818 B
Go

package hcsshim
import (
"io"
"syscall"
"github.com/Microsoft/go-winio"
)
var (
vmcomputedll = syscall.NewLazyDLL("vmcompute.dll")
hcsCallbackAPI = vmcomputedll.NewProc("HcsRegisterComputeSystemCallback")
hcsCallbacksSupported = hcsCallbackAPI.Find() == nil
)
// makeOpenFiles calls winio.MakeOpenFile for each handle in a slice but closes all the handles
// if there is an error.
func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
fs := make([]io.ReadWriteCloser, len(hs))
for i, h := range hs {
if h != syscall.Handle(0) {
if err == nil {
fs[i], err = winio.MakeOpenFile(h)
}
if err != nil {
syscall.Close(h)
}
}
}
if err != nil {
for _, f := range fs {
if f != nil {
f.Close()
}
}
return nil, err
}
return fs, nil
}