2015-05-27 13:15:14 -07:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package windows
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
|
|
|
"github.com/microsoft/hcsshim"
|
|
|
|
)
|
|
|
|
|
2015-08-03 09:54:02 +08:00
|
|
|
// Terminate implements the exec driver Driver interface.
|
|
|
|
func (d *Driver) Terminate(p *execdriver.Command) error {
|
2015-05-27 13:15:14 -07:00
|
|
|
logrus.Debugf("WindowsExec: Terminate() id=%s", p.ID)
|
|
|
|
return kill(p.ID, p.ContainerPid)
|
|
|
|
}
|
|
|
|
|
2015-08-03 09:54:02 +08:00
|
|
|
// Kill implements the exec driver Driver interface.
|
|
|
|
func (d *Driver) Kill(p *execdriver.Command, sig int) error {
|
2015-05-27 13:15:14 -07:00
|
|
|
logrus.Debugf("WindowsExec: Kill() id=%s sig=%d", p.ID, sig)
|
|
|
|
return kill(p.ID, p.ContainerPid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func kill(id string, pid int) error {
|
|
|
|
logrus.Debugln("kill() ", id, pid)
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Terminate Process
|
|
|
|
if err = hcsshim.TerminateProcessInComputeSystem(id, uint32(pid)); err != nil {
|
2015-09-08 10:53:17 -07:00
|
|
|
logrus.Warnf("Failed to terminate pid %d in %s: %q", pid, id, err)
|
2015-05-27 13:15:14 -07:00
|
|
|
// Ignore errors
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if terminateMode {
|
|
|
|
// Terminate the compute system
|
|
|
|
if err = hcsshim.TerminateComputeSystem(id); err != nil {
|
2015-09-08 10:53:17 -07:00
|
|
|
logrus.Errorf("Failed to terminate %s - %q", id, err)
|
2015-05-27 13:15:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Shutdown the compute system
|
2015-07-22 19:30:47 -07:00
|
|
|
if err = hcsshim.ShutdownComputeSystem(id); err != nil {
|
2015-09-08 10:53:17 -07:00
|
|
|
logrus.Errorf("Failed to shutdown %s - %q", id, err)
|
2015-05-27 13:15:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|