nsh kill cmd can be executed with no signal option.

SIGTERM is the default signal, as in unix kill command.
nsh> kill [-<signal>] <pid>
This commit is contained in:
RoCorbera 2021-06-01 00:12:41 -03:00 committed by Alan Carvalho de Assis
parent 61ddfeba17
commit 42f4565129
2 changed files with 46 additions and 14 deletions

View File

@ -261,7 +261,7 @@ static const struct cmdmap_s g_cmdmap[] =
#endif
#ifndef CONFIG_NSH_DISABLE_KILL
{ "kill", cmd_kill, 3, 3, "-<signal> <pid>" },
{ "kill", cmd_kill, 2, 3, "[-<signal>] <pid>" },
#endif
#ifndef CONFIG_DISABLE_MOUNTPOINT

View File

@ -48,6 +48,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <signal.h>
#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 "-<signal>" */
/* kill will send SIGTERM to the task in case no signal is selected by
* -<signal> option
*/
ptr = argv[1];
if (*ptr != '-' || ptr[1] < '0' || ptr[1] > '9')
if (argc == 3) /* kill -<signal> <pid> */
{
goto invalid_arg;
/* Check incoming parameters.
* The first parameter should be "-<signal>"
*/
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 <pid> */
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 <pid> */
ptr = argv[2];
if (*ptr < '0' || *ptr > '9')
else if (argc == 2) /* kill <pid> */
{
/* uses default signal number as SIGTERM */
signal = (long) SIGTERM; /* SIGTERM is always defined in signal.h */
/* The first parameter should be <pid> */
ptr = argv[1];
if (*ptr < '0' || *ptr > '9')
{
goto invalid_arg;
}
}
else
{
/* invalid number of arguments */
goto invalid_arg;
}