github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/daemon/execdriver/windows/terminatekill.go (about)

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