This helps reducing some type-juggling / conversions further up
the stack.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -279,7 +279,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin |
| 279 | 279 |
select {
|
| 280 | 280 |
case <-ctx.Done(): |
| 281 | 281 |
logrus.Debugf("Sending TERM signal to process %v in container %v", name, c.ID)
|
| 282 |
- daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["TERM"])) |
|
| 282 |
+ daemon.containerd.SignalProcess(ctx, c.ID, name, signal.SignalMap["TERM"]) |
|
| 283 | 283 |
|
| 284 | 284 |
timeout := time.NewTimer(termProcessTimeout) |
| 285 | 285 |
defer timeout.Stop() |
| ... | ... |
@@ -287,7 +287,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin |
| 287 | 287 |
select {
|
| 288 | 288 |
case <-timeout.C: |
| 289 | 289 |
logrus.Infof("Container %v, process %v failed to exit within %v of signal TERM - using the force", c.ID, name, termProcessTimeout)
|
| 290 |
- daemon.containerd.SignalProcess(ctx, c.ID, name, int(signal.SignalMap["KILL"])) |
|
| 290 |
+ daemon.containerd.SignalProcess(ctx, c.ID, name, signal.SignalMap["KILL"]) |
|
| 291 | 291 |
case <-attachErr: |
| 292 | 292 |
// TERM signal worked |
| 293 | 293 |
} |
| ... | ... |
@@ -60,7 +60,8 @@ func (daemon *Daemon) ContainerKill(name string, sig uint64) error {
|
| 60 | 60 |
// or not running, or if there is a problem returned from the |
| 61 | 61 |
// underlying kill command. |
| 62 | 62 |
func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int) error {
|
| 63 |
- logrus.Debugf("Sending kill signal %d to container %s", sig, container.ID)
|
|
| 63 |
+ var stopSignal = syscall.Signal(sig) |
|
| 64 |
+ logrus.Debugf("Sending kill signal %d to container %s", stopSignal, container.ID)
|
|
| 64 | 65 |
container.Lock() |
| 65 | 66 |
defer container.Unlock() |
| 66 | 67 |
|
| ... | ... |
@@ -69,12 +70,12 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int) |
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 | 71 |
var unpause bool |
| 72 |
- if container.Config.StopSignal != "" && syscall.Signal(sig) != syscall.SIGKILL {
|
|
| 72 |
+ if container.Config.StopSignal != "" && stopSignal != syscall.SIGKILL {
|
|
| 73 | 73 |
containerStopSignal, err := signal.ParseSignal(container.Config.StopSignal) |
| 74 | 74 |
if err != nil {
|
| 75 | 75 |
return err |
| 76 | 76 |
} |
| 77 |
- if containerStopSignal == syscall.Signal(sig) {
|
|
| 77 |
+ if containerStopSignal == stopSignal {
|
|
| 78 | 78 |
container.ExitOnNext() |
| 79 | 79 |
unpause = container.Paused |
| 80 | 80 |
} |
| ... | ... |
@@ -95,7 +96,8 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int) |
| 95 | 95 |
return nil |
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 |
- if err := daemon.kill(container, sig); err != nil {
|
|
| 98 |
+ err := daemon.containerd.SignalProcess(context.Background(), container.ID, libcontainerdtypes.InitProcessName, stopSignal) |
|
| 99 |
+ if err != nil {
|
|
| 99 | 100 |
if errdefs.IsNotFound(err) {
|
| 100 | 101 |
unpause = false |
| 101 | 102 |
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) |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
attributes := map[string]string{
|
| 128 |
- "signal": fmt.Sprintf("%d", sig),
|
|
| 128 |
+ "signal": fmt.Sprintf("%d", stopSignal),
|
|
| 129 | 129 |
} |
| 130 | 130 |
daemon.LogContainerEventWithAttributes(container, "kill", attributes) |
| 131 | 131 |
return nil |
| ... | ... |
@@ -182,7 +184,3 @@ func (daemon *Daemon) killPossiblyDeadProcess(container *containerpkg.Container, |
| 182 | 182 |
} |
| 183 | 183 |
return err |
| 184 | 184 |
} |
| 185 |
- |
|
| 186 |
-func (daemon *Daemon) kill(c *containerpkg.Container, sig int) error {
|
|
| 187 |
- return daemon.containerd.SignalProcess(context.Background(), c.ID, libcontainerdtypes.InitProcessName, sig) |
|
| 188 |
-} |
| ... | ... |
@@ -5,6 +5,7 @@ package daemon |
| 5 | 5 |
|
| 6 | 6 |
import ( |
| 7 | 7 |
"context" |
| 8 |
+ "syscall" |
|
| 8 | 9 |
"time" |
| 9 | 10 |
|
| 10 | 11 |
"github.com/containerd/containerd" |
| ... | ... |
@@ -35,7 +36,7 @@ func (c *MockContainerdClient) Create(ctx context.Context, containerID string, s |
| 35 | 35 |
func (c *MockContainerdClient) Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (pid int, err error) {
|
| 36 | 36 |
return 0, nil |
| 37 | 37 |
} |
| 38 |
-func (c *MockContainerdClient) SignalProcess(ctx context.Context, containerID, processID string, signal int) error {
|
|
| 38 |
+func (c *MockContainerdClient) SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error {
|
|
| 39 | 39 |
return nil |
| 40 | 40 |
} |
| 41 | 41 |
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 * |
| 333 | 333 |
return int(p.Pid()), nil |
| 334 | 334 |
} |
| 335 | 335 |
|
| 336 |
-func (c *client) SignalProcess(ctx context.Context, containerID, processID string, signal int) error {
|
|
| 336 |
+func (c *client) SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error {
|
|
| 337 | 337 |
p, err := c.getProcess(ctx, containerID, processID) |
| 338 | 338 |
if err != nil {
|
| 339 | 339 |
return err |
| 340 | 340 |
} |
| 341 |
- return wrapError(p.Kill(ctx, syscall.Signal(signal))) |
|
| 341 |
+ return wrapError(p.Kill(ctx, signal)) |
|
| 342 | 342 |
} |
| 343 | 343 |
|
| 344 | 344 |
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" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "syscall" |
|
| 5 | 6 |
"time" |
| 6 | 7 |
|
| 7 | 8 |
"github.com/containerd/containerd" |
| ... | ... |
@@ -54,7 +55,7 @@ type Client interface {
|
| 54 | 54 |
|
| 55 | 55 |
Create(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) error
|
| 56 | 56 |
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error) |
| 57 |
- SignalProcess(ctx context.Context, containerID, processID string, signal int) error |
|
| 57 |
+ SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error |
|
| 58 | 58 |
Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error) |
| 59 | 59 |
ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error |
| 60 | 60 |
CloseStdin(ctx context.Context, containerID, processID string) error |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"io" |
| 6 | 6 |
"sync" |
| 7 |
+ "syscall" |
|
| 7 | 8 |
|
| 8 | 9 |
"github.com/containerd/containerd" |
| 9 | 10 |
"github.com/containerd/containerd/cio" |
| ... | ... |
@@ -113,7 +114,7 @@ func (e *Executor) IsRunning(id string) (bool, error) {
|
| 113 | 113 |
|
| 114 | 114 |
// Signal sends the specified signal to the container |
| 115 | 115 |
func (e *Executor) Signal(id string, signal int) error {
|
| 116 |
- return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, signal) |
|
| 116 |
+ return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, syscall.Signal(signal)) |
|
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
// ProcessEvent handles events from containerd |