|
@@ -3,6 +3,7 @@ package hcsshim
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"runtime"
|
|
"runtime"
|
|
|
|
+ "sync"
|
|
"syscall"
|
|
"syscall"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -20,12 +21,14 @@ const (
|
|
)
|
|
)
|
|
|
|
|
|
type container struct {
|
|
type container struct {
|
|
|
|
+ handleLock sync.RWMutex
|
|
handle hcsSystem
|
|
handle hcsSystem
|
|
id string
|
|
id string
|
|
callbackNumber uintptr
|
|
callbackNumber uintptr
|
|
}
|
|
}
|
|
|
|
|
|
-type containerProperties struct {
|
|
|
|
|
|
+// ContainerProperties holds the properties for a container and the processes running in that container
|
|
|
|
+type ContainerProperties struct {
|
|
ID string `json:"Id"`
|
|
ID string `json:"Id"`
|
|
Name string
|
|
Name string
|
|
SystemType string
|
|
SystemType string
|
|
@@ -33,6 +36,8 @@ type containerProperties struct {
|
|
SiloGUID string `json:"SiloGuid,omitempty"`
|
|
SiloGUID string `json:"SiloGuid,omitempty"`
|
|
IsDummy bool `json:",omitempty"`
|
|
IsDummy bool `json:",omitempty"`
|
|
RuntimeID string `json:"RuntimeId,omitempty"`
|
|
RuntimeID string `json:"RuntimeId,omitempty"`
|
|
|
|
+ IsRuntimeTemplate bool `json:",omitempty"`
|
|
|
|
+ RuntimeImagePath string `json:",omitempty"`
|
|
Stopped bool `json:",omitempty"`
|
|
Stopped bool `json:",omitempty"`
|
|
ExitType string `json:",omitempty"`
|
|
ExitType string `json:",omitempty"`
|
|
AreUpdatesPending bool `json:",omitempty"`
|
|
AreUpdatesPending bool `json:",omitempty"`
|
|
@@ -116,20 +121,15 @@ func CreateContainer(id string, c *ContainerConfig) (Container, error) {
|
|
logrus.Debugf(title+" id=%s config=%s", id, configuration)
|
|
logrus.Debugf(title+" id=%s config=%s", id, configuration)
|
|
|
|
|
|
var (
|
|
var (
|
|
- resultp *uint16
|
|
|
|
- createError error
|
|
|
|
|
|
+ resultp *uint16
|
|
|
|
+ identity syscall.Handle
|
|
)
|
|
)
|
|
- if hcsCallbacksSupported {
|
|
|
|
- var identity syscall.Handle
|
|
|
|
- createError = hcsCreateComputeSystem(id, configuration, identity, &container.handle, &resultp)
|
|
|
|
-
|
|
|
|
- if createError == nil || IsPending(createError) {
|
|
|
|
- if err := container.registerCallback(); err != nil {
|
|
|
|
- return nil, makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ createError := hcsCreateComputeSystem(id, configuration, identity, &container.handle, &resultp)
|
|
|
|
+
|
|
|
|
+ if createError == nil || IsPending(createError) {
|
|
|
|
+ if err := container.registerCallback(); err != nil {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- createError = hcsCreateComputeSystemTP5(id, configuration, &container.handle, &resultp)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
err = processAsyncHcsResult(createError, resultp, container.callbackNumber, hcsNotificationSystemCreateCompleted, &defaultTimeout)
|
|
err = processAsyncHcsResult(createError, resultp, container.callbackNumber, hcsNotificationSystemCreateCompleted, &defaultTimeout)
|
|
@@ -164,19 +164,61 @@ func OpenContainer(id string) (Container, error) {
|
|
|
|
|
|
container.handle = handle
|
|
container.handle = handle
|
|
|
|
|
|
|
|
+ if err := container.registerCallback(); err != nil {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
logrus.Debugf(title+" succeeded id=%s handle=%d", id, handle)
|
|
logrus.Debugf(title+" succeeded id=%s handle=%d", id, handle)
|
|
runtime.SetFinalizer(container, closeContainer)
|
|
runtime.SetFinalizer(container, closeContainer)
|
|
return container, nil
|
|
return container, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetContainers gets a list of the containers on the system that match the query
|
|
|
|
+func GetContainers(q ComputeSystemQuery) ([]ContainerProperties, error) {
|
|
|
|
+ operation := "GetContainers"
|
|
|
|
+ title := "HCSShim::" + operation
|
|
|
|
+
|
|
|
|
+ queryb, err := json.Marshal(q)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ query := string(queryb)
|
|
|
|
+ logrus.Debugf(title+" query=%s", query)
|
|
|
|
+
|
|
|
|
+ var (
|
|
|
|
+ resultp *uint16
|
|
|
|
+ computeSystemsp *uint16
|
|
|
|
+ )
|
|
|
|
+ err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
|
|
|
|
+ err = processHcsResult(err, resultp)
|
|
|
|
+ if computeSystemsp == nil {
|
|
|
|
+ return nil, ErrUnexpectedValue
|
|
|
|
+ }
|
|
|
|
+ computeSystemsRaw := convertAndFreeCoTaskMemBytes(computeSystemsp)
|
|
|
|
+ computeSystems := []ContainerProperties{}
|
|
|
|
+ if err := json.Unmarshal(computeSystemsRaw, &computeSystems); err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logrus.Debugf(title + " succeeded")
|
|
|
|
+ return computeSystems, nil
|
|
|
|
+}
|
|
|
|
+
|
|
// Start synchronously starts the container.
|
|
// Start synchronously starts the container.
|
|
func (container *container) Start() error {
|
|
func (container *container) Start() error {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Start"
|
|
operation := "Start"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
var resultp *uint16
|
|
var resultp *uint16
|
|
- err := hcsStartComputeSystemTP5(container.handle, nil, &resultp)
|
|
|
|
|
|
+ err := hcsStartComputeSystem(container.handle, "", &resultp)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)
|
|
if err != nil {
|
|
if err != nil {
|
|
return makeContainerError(container, operation, "", err)
|
|
return makeContainerError(container, operation, "", err)
|
|
@@ -189,12 +231,18 @@ func (container *container) Start() error {
|
|
// Shutdown requests a container shutdown, if IsPending() on the error returned is true,
|
|
// Shutdown requests a container shutdown, if IsPending() on the error returned is true,
|
|
// it may not actually be shut down until Wait() succeeds.
|
|
// it may not actually be shut down until Wait() succeeds.
|
|
func (container *container) Shutdown() error {
|
|
func (container *container) Shutdown() error {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Shutdown"
|
|
operation := "Shutdown"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
var resultp *uint16
|
|
var resultp *uint16
|
|
- err := hcsShutdownComputeSystemTP5(container.handle, nil, &resultp)
|
|
|
|
|
|
+ err := hcsShutdownComputeSystem(container.handle, "", &resultp)
|
|
err = processHcsResult(err, resultp)
|
|
err = processHcsResult(err, resultp)
|
|
if err != nil {
|
|
if err != nil {
|
|
return makeContainerError(container, operation, "", err)
|
|
return makeContainerError(container, operation, "", err)
|
|
@@ -207,12 +255,18 @@ func (container *container) Shutdown() error {
|
|
// Terminate requests a container terminate, if IsPending() on the error returned is true,
|
|
// Terminate requests a container terminate, if IsPending() on the error returned is true,
|
|
// it may not actually be shut down until Wait() succeeds.
|
|
// it may not actually be shut down until Wait() succeeds.
|
|
func (container *container) Terminate() error {
|
|
func (container *container) Terminate() error {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Terminate"
|
|
operation := "Terminate"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
var resultp *uint16
|
|
var resultp *uint16
|
|
- err := hcsTerminateComputeSystemTP5(container.handle, nil, &resultp)
|
|
|
|
|
|
+ err := hcsTerminateComputeSystem(container.handle, "", &resultp)
|
|
err = processHcsResult(err, resultp)
|
|
err = processHcsResult(err, resultp)
|
|
if err != nil {
|
|
if err != nil {
|
|
return makeContainerError(container, operation, "", err)
|
|
return makeContainerError(container, operation, "", err)
|
|
@@ -228,26 +282,15 @@ func (container *container) Wait() error {
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
- if hcsCallbacksSupported {
|
|
|
|
- err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
|
|
|
|
- if err != nil {
|
|
|
|
- return makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- _, err := container.waitTimeoutInternal(syscall.INFINITE)
|
|
|
|
- if err != nil {
|
|
|
|
- return makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
|
|
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (container *container) waitTimeoutInternal(timeout uint32) (bool, error) {
|
|
|
|
- return waitTimeoutInternalHelper(container, timeout)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// WaitTimeout synchronously waits for the container to terminate or the duration to elapse.
|
|
// WaitTimeout synchronously waits for the container to terminate or the duration to elapse.
|
|
// If the timeout expires, IsTimeout(err) == true
|
|
// If the timeout expires, IsTimeout(err) == true
|
|
func (container *container) WaitTimeout(timeout time.Duration) error {
|
|
func (container *container) WaitTimeout(timeout time.Duration) error {
|
|
@@ -255,42 +298,16 @@ func (container *container) WaitTimeout(timeout time.Duration) error {
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
- if hcsCallbacksSupported {
|
|
|
|
- err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
|
|
|
|
- if err != nil {
|
|
|
|
- return makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- finished, err := waitTimeoutHelper(container, timeout)
|
|
|
|
- if !finished {
|
|
|
|
- err = ErrTimeout
|
|
|
|
- }
|
|
|
|
- if err != nil {
|
|
|
|
- return makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
|
|
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (container *container) hcsWait(timeout uint32) (bool, error) {
|
|
|
|
- var (
|
|
|
|
- resultp *uint16
|
|
|
|
- exitEvent syscall.Handle
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- err := hcsCreateComputeSystemWait(container.handle, &exitEvent, &resultp)
|
|
|
|
- err = processHcsResult(err, resultp)
|
|
|
|
- if err != nil {
|
|
|
|
- return false, err
|
|
|
|
- }
|
|
|
|
- defer syscall.CloseHandle(exitEvent)
|
|
|
|
-
|
|
|
|
- return waitForSingleObject(exitEvent, timeout)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (container *container) properties(query string) (*containerProperties, error) {
|
|
|
|
|
|
+func (container *container) properties(query string) (*ContainerProperties, error) {
|
|
var (
|
|
var (
|
|
resultp *uint16
|
|
resultp *uint16
|
|
propertiesp *uint16
|
|
propertiesp *uint16
|
|
@@ -305,7 +322,7 @@ func (container *container) properties(query string) (*containerProperties, erro
|
|
return nil, ErrUnexpectedValue
|
|
return nil, ErrUnexpectedValue
|
|
}
|
|
}
|
|
propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
|
|
propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
|
|
- properties := &containerProperties{}
|
|
|
|
|
|
+ properties := &ContainerProperties{}
|
|
if err := json.Unmarshal(propertiesRaw, properties); err != nil {
|
|
if err := json.Unmarshal(propertiesRaw, properties); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -314,9 +331,16 @@ func (container *container) properties(query string) (*containerProperties, erro
|
|
|
|
|
|
// HasPendingUpdates returns true if the container has updates pending to install
|
|
// HasPendingUpdates returns true if the container has updates pending to install
|
|
func (container *container) HasPendingUpdates() (bool, error) {
|
|
func (container *container) HasPendingUpdates() (bool, error) {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "HasPendingUpdates"
|
|
operation := "HasPendingUpdates"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
+
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return false, makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
properties, err := container.properties(pendingUpdatesQuery)
|
|
properties, err := container.properties(pendingUpdatesQuery)
|
|
if err != nil {
|
|
if err != nil {
|
|
return false, makeContainerError(container, operation, "", err)
|
|
return false, makeContainerError(container, operation, "", err)
|
|
@@ -328,9 +352,16 @@ func (container *container) HasPendingUpdates() (bool, error) {
|
|
|
|
|
|
// Statistics returns statistics for the container
|
|
// Statistics returns statistics for the container
|
|
func (container *container) Statistics() (Statistics, error) {
|
|
func (container *container) Statistics() (Statistics, error) {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Statistics"
|
|
operation := "Statistics"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
+
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return Statistics{}, makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
properties, err := container.properties(statisticsQuery)
|
|
properties, err := container.properties(statisticsQuery)
|
|
if err != nil {
|
|
if err != nil {
|
|
return Statistics{}, makeContainerError(container, operation, "", err)
|
|
return Statistics{}, makeContainerError(container, operation, "", err)
|
|
@@ -342,9 +373,16 @@ func (container *container) Statistics() (Statistics, error) {
|
|
|
|
|
|
// ProcessList returns an array of ProcessListItems for the container
|
|
// ProcessList returns an array of ProcessListItems for the container
|
|
func (container *container) ProcessList() ([]ProcessListItem, error) {
|
|
func (container *container) ProcessList() ([]ProcessListItem, error) {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "ProcessList"
|
|
operation := "ProcessList"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
+
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
properties, err := container.properties(processListQuery)
|
|
properties, err := container.properties(processListQuery)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, makeContainerError(container, operation, "", err)
|
|
return nil, makeContainerError(container, operation, "", err)
|
|
@@ -356,12 +394,18 @@ func (container *container) ProcessList() ([]ProcessListItem, error) {
|
|
|
|
|
|
// Pause pauses the execution of the container. This feature is not enabled in TP5.
|
|
// Pause pauses the execution of the container. This feature is not enabled in TP5.
|
|
func (container *container) Pause() error {
|
|
func (container *container) Pause() error {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Pause"
|
|
operation := "Pause"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
var resultp *uint16
|
|
var resultp *uint16
|
|
- err := hcsPauseComputeSystemTP5(container.handle, nil, &resultp)
|
|
|
|
|
|
+ err := hcsPauseComputeSystem(container.handle, "", &resultp)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemPauseCompleted, &defaultTimeout)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemPauseCompleted, &defaultTimeout)
|
|
if err != nil {
|
|
if err != nil {
|
|
return makeContainerError(container, operation, "", err)
|
|
return makeContainerError(container, operation, "", err)
|
|
@@ -373,14 +417,18 @@ func (container *container) Pause() error {
|
|
|
|
|
|
// Resume resumes the execution of the container. This feature is not enabled in TP5.
|
|
// Resume resumes the execution of the container. This feature is not enabled in TP5.
|
|
func (container *container) Resume() error {
|
|
func (container *container) Resume() error {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "Resume"
|
|
operation := "Resume"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
- var (
|
|
|
|
- resultp *uint16
|
|
|
|
- )
|
|
|
|
|
|
|
|
- err := hcsResumeComputeSystemTP5(container.handle, nil, &resultp)
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var resultp *uint16
|
|
|
|
+ err := hcsResumeComputeSystem(container.handle, "", &resultp)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemResumeCompleted, &defaultTimeout)
|
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemResumeCompleted, &defaultTimeout)
|
|
if err != nil {
|
|
if err != nil {
|
|
return makeContainerError(container, operation, "", err)
|
|
return makeContainerError(container, operation, "", err)
|
|
@@ -392,6 +440,8 @@ func (container *container) Resume() error {
|
|
|
|
|
|
// CreateProcess launches a new process within the container.
|
|
// CreateProcess launches a new process within the container.
|
|
func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
|
func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "CreateProcess"
|
|
operation := "CreateProcess"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
var (
|
|
var (
|
|
@@ -400,6 +450,10 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
|
resultp *uint16
|
|
resultp *uint16
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
// If we are not emulating a console, ignore any console size passed to us
|
|
// If we are not emulating a console, ignore any console size passed to us
|
|
if !c.EmulateConsole {
|
|
if !c.EmulateConsole {
|
|
c.ConsoleSize[0] = 0
|
|
c.ConsoleSize[0] = 0
|
|
@@ -431,10 +485,8 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
- if hcsCallbacksSupported {
|
|
|
|
- if err := process.registerCallback(); err != nil {
|
|
|
|
- return nil, makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ if err := process.registerCallback(); err != nil {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
|
|
|
|
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
|
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
|
@@ -444,6 +496,8 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
|
|
|
|
|
// OpenProcess gets an interface to an existing process within the container.
|
|
// OpenProcess gets an interface to an existing process within the container.
|
|
func (container *container) OpenProcess(pid int) (Process, error) {
|
|
func (container *container) OpenProcess(pid int) (Process, error) {
|
|
|
|
+ container.handleLock.RLock()
|
|
|
|
+ defer container.handleLock.RUnlock()
|
|
operation := "OpenProcess"
|
|
operation := "OpenProcess"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s, processid=%d", container.id, pid)
|
|
logrus.Debugf(title+" id=%s, processid=%d", container.id, pid)
|
|
@@ -452,6 +506,10 @@ func (container *container) OpenProcess(pid int) (Process, error) {
|
|
resultp *uint16
|
|
resultp *uint16
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if container.handle == 0 {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
|
|
|
|
+ }
|
|
|
|
+
|
|
err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
|
|
err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
|
|
err = processHcsResult(err, resultp)
|
|
err = processHcsResult(err, resultp)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -464,10 +522,8 @@ func (container *container) OpenProcess(pid int) (Process, error) {
|
|
container: container,
|
|
container: container,
|
|
}
|
|
}
|
|
|
|
|
|
- if hcsCallbacksSupported {
|
|
|
|
- if err := process.registerCallback(); err != nil {
|
|
|
|
- return nil, makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ if err := process.registerCallback(); err != nil {
|
|
|
|
+ return nil, makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
|
|
|
|
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
|
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
|
@@ -477,6 +533,8 @@ func (container *container) OpenProcess(pid int) (Process, error) {
|
|
|
|
|
|
// Close cleans up any state associated with the container but does not terminate or wait for it.
|
|
// Close cleans up any state associated with the container but does not terminate or wait for it.
|
|
func (container *container) Close() error {
|
|
func (container *container) Close() error {
|
|
|
|
+ container.handleLock.Lock()
|
|
|
|
+ defer container.handleLock.Unlock()
|
|
operation := "Close"
|
|
operation := "Close"
|
|
title := "HCSShim::Container::" + operation
|
|
title := "HCSShim::Container::" + operation
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
logrus.Debugf(title+" id=%s", container.id)
|
|
@@ -486,10 +544,8 @@ func (container *container) Close() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- if hcsCallbacksSupported {
|
|
|
|
- if err := container.unregisterCallback(); err != nil {
|
|
|
|
- return makeContainerError(container, operation, "", err)
|
|
|
|
- }
|
|
|
|
|
|
+ if err := container.unregisterCallback(); err != nil {
|
|
|
|
+ return makeContainerError(container, operation, "", err)
|
|
}
|
|
}
|
|
|
|
|
|
if err := hcsCloseComputeSystem(container.handle); err != nil {
|
|
if err := hcsCloseComputeSystem(container.handle); err != nil {
|
|
@@ -497,6 +553,7 @@ func (container *container) Close() error {
|
|
}
|
|
}
|
|
|
|
|
|
container.handle = 0
|
|
container.handle = 0
|
|
|
|
+ runtime.SetFinalizer(container, nil)
|
|
|
|
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
|
return nil
|
|
return nil
|