11 "github.com/urfave/cli"
14 var signalMap = map[string]syscall.Signal{
15 "ABRT": syscall.SIGABRT,
16 "ALRM": syscall.SIGALRM,
17 "BUS": syscall.SIGBUS,
18 "CHLD": syscall.SIGCHLD,
19 "CLD": syscall.SIGCLD,
20 "CONT": syscall.SIGCONT,
21 "FPE": syscall.SIGFPE,
22 "HUP": syscall.SIGHUP,
23 "ILL": syscall.SIGILL,
24 "INT": syscall.SIGINT,
26 "IOT": syscall.SIGIOT,
27 "KILL": syscall.SIGKILL,
28 "PIPE": syscall.SIGPIPE,
29 "POLL": syscall.SIGPOLL,
30 "PROF": syscall.SIGPROF,
31 "PWR": syscall.SIGPWR,
32 "QUIT": syscall.SIGQUIT,
33 "SEGV": syscall.SIGSEGV,
34 "STKFLT": syscall.SIGSTKFLT,
35 "STOP": syscall.SIGSTOP,
36 "SYS": syscall.SIGSYS,
37 "TERM": syscall.SIGTERM,
38 "TRAP": syscall.SIGTRAP,
39 "TSTP": syscall.SIGTSTP,
40 "TTIN": syscall.SIGTTIN,
41 "TTOU": syscall.SIGTTOU,
42 "UNUSED": syscall.SIGUNUSED,
43 "URG": syscall.SIGURG,
44 "USR1": syscall.SIGUSR1,
45 "USR2": syscall.SIGUSR2,
46 "VTALRM": syscall.SIGVTALRM,
47 "WINCH": syscall.SIGWINCH,
48 "XCPU": syscall.SIGXCPU,
49 "XFSZ": syscall.SIGXFSZ,
52 var killCommand = cli.Command{
54 Usage: "kill sends the specified signal (default: SIGTERM) to the container's init process",
55 ArgsUsage: `<container-id> [signal]
57 Where "<container-id>" is the name for the instance of the container and
58 "[signal]" is the signal to be sent to the init process.
61 For example, if the container id is "ubuntu01" the following will send a "KILL"
62 signal to the init process of the "ubuntu01" container:
64 # runc kill ubuntu01 KILL`,
68 Usage: "send the specified signal to all processes inside the container",
71 Action: func(context *cli.Context) error {
72 if err := checkArgs(context, 1, minArgs); err != nil {
75 if err := checkArgs(context, 2, maxArgs); err != nil {
78 container, err := getContainer(context)
83 sigstr := context.Args().Get(1)
88 signal, err := parseSignal(sigstr)
92 if err := container.Signal(signal, context.Bool("all")); err != nil {
99 func parseSignal(rawSignal string) (syscall.Signal, error) {
100 s, err := strconv.Atoi(rawSignal)
102 sig := syscall.Signal(s)
103 for _, msig := range signalMap {
108 return -1, fmt.Errorf("unknown signal %q", rawSignal)
110 signal, ok := signalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
112 return -1, fmt.Errorf("unknown signal %q", rawSignal)