github.com/wulonghui/docker@v1.8.0-rc2/daemon/execdriver/windows/terminatekill.go (about)

     1  // +build windows
     2  
     3  package windows
     4  
     5  import (
     6  	"github.com/Sirupsen/logrus"
     7  	"github.com/docker/docker/daemon/execdriver"
     8  	"github.com/microsoft/hcsshim"
     9  )
    10  
    11  func (d *driver) Terminate(p *execdriver.Command) error {
    12  	logrus.Debugf("WindowsExec: Terminate() id=%s", p.ID)
    13  	return kill(p.ID, p.ContainerPid)
    14  }
    15  
    16  func (d *driver) Kill(p *execdriver.Command, sig int) error {
    17  	logrus.Debugf("WindowsExec: Kill() id=%s sig=%d", p.ID, sig)
    18  	return kill(p.ID, p.ContainerPid)
    19  }
    20  
    21  func kill(id string, pid int) error {
    22  	logrus.Debugln("kill() ", id, pid)
    23  	var err error
    24  
    25  	// Terminate Process
    26  	if err = hcsshim.TerminateProcessInComputeSystem(id, uint32(pid)); err != nil {
    27  		logrus.Warnf("Failed to terminate pid %d in %s", id, pid, err)
    28  		// Ignore errors
    29  		err = nil
    30  	}
    31  
    32  	if terminateMode {
    33  		// Terminate the compute system
    34  		if err = hcsshim.TerminateComputeSystem(id); err != nil {
    35  			logrus.Errorf("Failed to terminate %s - %s", id, err)
    36  		}
    37  
    38  	} else {
    39  		// Shutdown the compute system
    40  		if err = hcsshim.ShutdownComputeSystem(id); err != nil {
    41  			logrus.Errorf("Failed to shutdown %s - %s", id, err)
    42  		}
    43  	}
    44  	return err
    45  }