diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 58b7e65a4..5dbe6c307 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -261,7 +261,7 @@ static const struct cmdmap_s g_cmdmap[] = #endif #ifndef CONFIG_NSH_DISABLE_KILL - { "kill", cmd_kill, 3, 3, "- " }, + { "kill", cmd_kill, 2, 3, "[-] " }, #endif #ifndef CONFIG_DISABLE_MOUNTPOINT diff --git a/nshlib/nsh_proccmds.c b/nshlib/nsh_proccmds.c index d5797a8df..01a615f7b 100644 --- a/nshlib/nsh_proccmds.c +++ b/nshlib/nsh_proccmds.c @@ -48,6 +48,7 @@ #include #include #include +#include #include "nsh.h" #include "nsh_console.h" @@ -618,23 +619,54 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) long signal; long pid; - /* Check incoming parameters. The first parameter should be "-" */ + /* kill will send SIGTERM to the task in case no signal is selected by + * - option + */ - ptr = argv[1]; - if (*ptr != '-' || ptr[1] < '0' || ptr[1] > '9') + if (argc == 3) /* kill - */ { - goto invalid_arg; + /* Check incoming parameters. + * The first parameter should be "-" + */ + + ptr = argv[1]; + if (*ptr != '-' || ptr[1] < '0' || ptr[1] > '9') + { + goto invalid_arg; + } + + /* Extract the signal number */ + + signal = strtol(&ptr[1], &endptr, 0); + + /* The second parameter should be */ + + ptr = argv[2]; + + if (*ptr < '0' || *ptr > '9') + { + goto invalid_arg; + } } - - /* Extract the signal number */ - - signal = strtol(&ptr[1], &endptr, 0); - - /* The second parameter should be */ - - ptr = argv[2]; - if (*ptr < '0' || *ptr > '9') + else if (argc == 2) /* kill */ { + /* uses default signal number as SIGTERM */ + + signal = (long) SIGTERM; /* SIGTERM is always defined in signal.h */ + + /* The first parameter should be */ + + ptr = argv[1]; + + if (*ptr < '0' || *ptr > '9') + { + goto invalid_arg; + } + } + else + { + /* invalid number of arguments */ + goto invalid_arg; }