mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
libcontainerd: SignalProcess(): accept syscall.Signal
This helps reducing some type-juggling / conversions further up the stack. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c9b37e5cb4
commit
2ec2b65e45
6 changed files with 17 additions and 16 deletions
|
@ -279,7 +279,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
logrus.Debugf("Sending TERM signal to process %v in container %v", name, c.ID)
|
||||
daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["TERM"]))
|
||||
daemon.containerd.SignalProcess(ctx, c.ID, name, signal.SignalMap["TERM"])
|
||||
|
||||
timeout := time.NewTimer(termProcessTimeout)
|
||||
defer timeout.Stop()
|
||||
|
@ -287,7 +287,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin
|
|||
select {
|
||||
case <-timeout.C:
|
||||
logrus.Infof("Container %v, process %v failed to exit within %v of signal TERM - using the force", c.ID, name, termProcessTimeout)
|
||||
daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["KILL"]))
|
||||
daemon.containerd.SignalProcess(ctx, c.ID, name, signal.SignalMap["KILL"])
|
||||
case <-attachErr:
|
||||
// TERM signal worked
|
||||
}
|
||||
|
|
|
@ -60,7 +60,8 @@ func (daemon *Daemon) ContainerKill(name string, sig uint64) error {
|
|||
// or not running, or if there is a problem returned from the
|
||||
// underlying kill command.
|
||||
func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int) error {
|
||||
logrus.Debugf("Sending kill signal %d to container %s", sig, container.ID)
|
||||
var stopSignal = syscall.Signal(sig)
|
||||
logrus.Debugf("Sending kill signal %d to container %s", stopSignal, container.ID)
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
|
@ -69,12 +70,12 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
|||
}
|
||||
|
||||
var unpause bool
|
||||
if container.Config.StopSignal != "" && syscall.Signal(sig) != syscall.SIGKILL {
|
||||
if container.Config.StopSignal != "" && stopSignal != syscall.SIGKILL {
|
||||
containerStopSignal, err := signal.ParseSignal(container.Config.StopSignal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if containerStopSignal == syscall.Signal(sig) {
|
||||
if containerStopSignal == stopSignal {
|
||||
container.ExitOnNext()
|
||||
unpause = container.Paused
|
||||
}
|
||||
|
@ -95,7 +96,8 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := daemon.kill(container, sig); err != nil {
|
||||
err := daemon.containerd.SignalProcess(context.Background(), container.ID, libcontainerdtypes.InitProcessName, stopSignal)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
unpause = false
|
||||
logrus.WithError(err).WithField("container", container.ID).WithField("action", "kill").Debug("container kill failed because of 'container not found' or 'no such process'")
|
||||
|
@ -125,7 +127,7 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
|||
}
|
||||
|
||||
attributes := map[string]string{
|
||||
"signal": fmt.Sprintf("%d", sig),
|
||||
"signal": fmt.Sprintf("%d", stopSignal),
|
||||
}
|
||||
daemon.LogContainerEventWithAttributes(container, "kill", attributes)
|
||||
return nil
|
||||
|
@ -182,7 +184,3 @@ func (daemon *Daemon) killPossiblyDeadProcess(container *containerpkg.Container,
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (daemon *Daemon) kill(c *containerpkg.Container, sig int) error {
|
||||
return daemon.containerd.SignalProcess(context.Background(), c.ID, libcontainerdtypes.InitProcessName, sig)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package daemon
|
|||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
|
@ -35,7 +36,7 @@ func (c *MockContainerdClient) Create(ctx context.Context, containerID string, s
|
|||
func (c *MockContainerdClient) Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (pid int, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (c *MockContainerdClient) SignalProcess(ctx context.Context, containerID, processID string, signal int) error {
|
||||
func (c *MockContainerdClient) SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error {
|
||||
return nil
|
||||
}
|
||||
func (c *MockContainerdClient) Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (int, error) {
|
||||
|
|
|
@ -333,12 +333,12 @@ func (c *client) Exec(ctx context.Context, containerID, processID string, spec *
|
|||
return int(p.Pid()), nil
|
||||
}
|
||||
|
||||
func (c *client) SignalProcess(ctx context.Context, containerID, processID string, signal int) error {
|
||||
func (c *client) SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error {
|
||||
p, err := c.getProcess(ctx, containerID, processID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return wrapError(p.Kill(ctx, syscall.Signal(signal)))
|
||||
return wrapError(p.Kill(ctx, signal))
|
||||
}
|
||||
|
||||
func (c *client) ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error {
|
||||
|
|
|
@ -2,6 +2,7 @@ package types // import "github.com/docker/docker/libcontainerd/types"
|
|||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
|
@ -54,7 +55,7 @@ type Client interface {
|
|||
|
||||
Create(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) error
|
||||
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
|
||||
SignalProcess(ctx context.Context, containerID, processID string, signal int) error
|
||||
SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error
|
||||
Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
|
||||
ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
|
||||
CloseStdin(ctx context.Context, containerID, processID string) error
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cio"
|
||||
|
@ -113,7 +114,7 @@ func (e *Executor) IsRunning(id string) (bool, error) {
|
|||
|
||||
// Signal sends the specified signal to the container
|
||||
func (e *Executor) Signal(id string, signal int) error {
|
||||
return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, signal)
|
||||
return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, syscall.Signal(signal))
|
||||
}
|
||||
|
||||
// ProcessEvent handles events from containerd
|
||||
|
|
Loading…
Reference in a new issue