Skip to content

Commit f8ad20f

Browse files
committed
runc kill: drop -a option
As of previous commit, this is implied in a particular scenario. In fact, this is the one and only scenario that justifies the use of -a. Drop the option from the documentation. For backward compatibility, do recognize it, and retain the feature of ignoring the "container is stopped" error when set. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9583b3d commit f8ad20f

File tree

6 files changed

+27
-38
lines changed

6 files changed

+27
-38
lines changed

delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
)
1515

1616
func killContainer(container *libcontainer.Container) error {
17-
_ = container.Signal(unix.SIGKILL, false)
17+
_ = container.Signal(unix.SIGKILL)
1818
for i := 0; i < 100; i++ {
1919
time.Sleep(100 * time.Millisecond)
20-
if err := container.Signal(unix.Signal(0), false); err != nil {
20+
if err := container.Signal(unix.Signal(0)); err != nil {
2121
destroy(container)
2222
return nil
2323
}

kill.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
67
"strings"
78

9+
"github.com/opencontainers/runc/libcontainer"
810
"github.com/urfave/cli"
911
"golang.org/x/sys/unix"
1012
)
@@ -24,8 +26,9 @@ signal to the init process of the "ubuntu01" container:
2426
# runc kill ubuntu01 KILL`,
2527
Flags: []cli.Flag{
2628
cli.BoolFlag{
27-
Name: "all, a",
28-
Usage: "send the specified signal to all processes inside the container",
29+
Name: "all, a",
30+
Usage: "(obsoleted, do not use)",
31+
Hidden: true,
2932
},
3033
},
3134
Action: func(context *cli.Context) error {
@@ -49,7 +52,11 @@ signal to the init process of the "ubuntu01" container:
4952
if err != nil {
5053
return err
5154
}
52-
return container.Signal(signal, context.Bool("all"))
55+
err = container.Signal(signal)
56+
if errors.Is(err, libcontainer.ErrNotRunning) && context.Bool("all") {
57+
err = nil
58+
}
59+
return err
5360
},
5461
}
5562

libcontainer/container_linux.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,32 +357,18 @@ func (c *Container) start(process *Process) (retErr error) {
357357
return nil
358358
}
359359

360-
// Signal sends a specified signal to container's init, or, if all is true,
361-
// to all container's processes (as determined by container's cgroup).
360+
// Signal sends a specified signal to container's init.
362361
//
363-
// Note all=true is implied when s is SIGKILL and the container does not have
364-
// its own PID namespace. In this scenario, the libcontainer user may be required
365-
// to implement a proper child reaper.
366-
func (c *Container) Signal(s os.Signal, all bool) error {
362+
// When s is SIGKILL and the container does not have its own PID namespace, all
363+
// the container's processes are killed. In this scenario, the libcontainer
364+
// user may be required to implement a proper child reaper.
365+
func (c *Container) Signal(s os.Signal) error {
367366
c.m.Lock()
368367
defer c.m.Unlock()
369368
status, err := c.currentStatus()
370369
if err != nil {
371370
return err
372371
}
373-
if all {
374-
sig, ok := s.(unix.Signal)
375-
if !ok {
376-
return errors.New("unsupported signal type")
377-
}
378-
if status == Stopped && !c.cgroupManager.Exists() {
379-
// Avoid calling signalAllProcesses which may print
380-
// a warning trying to freeze a non-existing cgroup.
381-
return nil
382-
}
383-
return c.ignoreCgroupError(signalAllProcesses(c.cgroupManager, sig))
384-
}
385-
386372
// To avoid a PID reuse attack, don't kill non-running container.
387373
switch status {
388374
case Running, Created, Paused:

libcontainer/integration/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ func testPidnsInitKill(t *testing.T, config *configs.Config) {
14001400
ok(t, err)
14011401

14021402
// Kill the container.
1403-
err = container.Signal(syscall.SIGKILL, false)
1403+
err = container.Signal(syscall.SIGKILL)
14041404
ok(t, err)
14051405
_, err = process1.Wait()
14061406
if err == nil {

man/runc-kill.8.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**runc-kill** - send a specified signal to container
55

66
# SYNOPSIS
7-
**runc kill** [**--all**|**-a**] _container-id_ [_signal_]
7+
**runc kill** _container-id_ [_signal_]
88

99
# DESCRIPTION
1010

@@ -15,15 +15,6 @@ A different signal can be specified either by its name (with or without the
1515
**SIG** prefix), or its numeric value. Use **kill**(1) with **-l** option
1616
to list available signals.
1717

18-
# OPTIONS
19-
**--all**|**-a**
20-
: Send the signal to all processes inside the container, rather than
21-
the container's init only. This option is implied when the _signal_ is **KILL**
22-
and the container does not have its own PID namespace.
23-
24-
: When this option is set, no error is returned if the container is stopped
25-
or does not exist.
26-
2718
# EXAMPLES
2819

2920
The following will send a **KILL** signal to the init process of the

tests/integration/kill.bats

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ function teardown() {
2222
[ "$status" -eq 0 ]
2323
wait_for_container 10 1 test_busybox stopped
2424

25-
# we should ensure kill work after the container stopped
25+
# Check that kill errors on a stopped container.
26+
runc kill test_busybox 0
27+
[ "$status" -ne 0 ]
28+
[[ "$output" == *"container not running"* ]]
29+
30+
# Check that -a (now obsoleted) makes kill return no error for a stopped container.
2631
runc kill -a test_busybox 0
2732
[ "$status" -eq 0 ]
2833

@@ -31,7 +36,7 @@ function teardown() {
3136
}
3237

3338
# This is roughly the same as TestPIDHostInitProcessWait in libcontainer/integration.
34-
@test "kill --all KILL [host pidns]" {
39+
@test "kill KILL [host pidns]" {
3540
# kill -a currently requires cgroup freezer.
3641
requires cgroups_freezer
3742

@@ -65,7 +70,7 @@ function teardown() {
6570
kill -0 "$p"
6671
done
6772

68-
runc kill -a test_busybox KILL
73+
runc kill test_busybox KILL
6974
[ "$status" -eq 0 ]
7075
wait_for_container 10 1 test_busybox stopped
7176

0 commit comments

Comments
 (0)