summaryrefslogtreecommitdiffhomepage
path: root/runsc/cmd
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2018-10-17 10:50:24 -0700
committerShentubot <shentubot@google.com>2018-10-17 10:51:39 -0700
commit9b3550f70bf1612e2c474b3826b0347b21503401 (patch)
treee9c2e0b2b354f57f2a84b85733d35d99abc5a4da /runsc/cmd
parent9d17eba121dab054c21307b9696ba7471dff4a74 (diff)
runsc: Add --pid flag to runsc kill.
--pid allows specific processes to be signalled rather than the container root process or all processes in the container. containerd needs to SIGKILL exec'd processes that timeout and check whether processes are still alive. PiperOrigin-RevId: 217547636 Change-Id: I2058ebb548b51c8eb748f5884fb88bad0b532e45
Diffstat (limited to 'runsc/cmd')
-rw-r--r--runsc/cmd/kill.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/runsc/cmd/kill.go b/runsc/cmd/kill.go
index dcb2988e3..7a98d10a2 100644
--- a/runsc/cmd/kill.go
+++ b/runsc/cmd/kill.go
@@ -31,6 +31,7 @@ import (
// Kill implements subcommands.Command for the "kill" command.
type Kill struct {
all bool
+ pid int
}
// Name implements subcommands.Command.Name.
@@ -51,6 +52,7 @@ func (*Kill) Usage() string {
// SetFlags implements subcommands.Command.SetFlags.
func (k *Kill) SetFlags(f *flag.FlagSet) {
f.BoolVar(&k.all, "all", false, "send the specified signal to all processes inside the container")
+ f.IntVar(&k.pid, "pid", 0, "send the specified signal to a specific process")
}
// Execute implements subcommands.Command.Execute.
@@ -63,6 +65,10 @@ func (k *Kill) Execute(_ context.Context, f *flag.FlagSet, args ...interface{})
id := f.Arg(0)
conf := args[0].(*boot.Config)
+ if k.pid != 0 && k.all {
+ Fatalf("it is invalid to specify both --all and --pid")
+ }
+
c, err := container.Load(conf.RootDir, id)
if err != nil {
Fatalf("error loading container: %v", err)
@@ -80,8 +86,15 @@ func (k *Kill) Execute(_ context.Context, f *flag.FlagSet, args ...interface{})
if err != nil {
Fatalf("%v", err)
}
- if err := c.Signal(sig, k.all); err != nil {
- Fatalf("%v", err)
+
+ if k.pid != 0 {
+ if err := c.SignalProcess(sig, int32(k.pid)); err != nil {
+ Fatalf("failed to signal pid %d: %v", k.pid, err)
+ }
+ } else {
+ if err := c.SignalContainer(sig, k.all); err != nil {
+ Fatalf("%v", err)
+ }
}
return subcommands.ExitSuccess
}