This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 42f4565 nsh kill cmd can be executed with no signal option. SIGTERM
is the default signal, as in unix kill command. nsh> kill [-<signal>] <pid>
42f4565 is described below
commit 42f4565129d0d84264e54a2cdf66c43f917501cb
Author: RoCorbera <[email protected]>
AuthorDate: Tue Jun 1 00:12:41 2021 -0300
nsh kill cmd can be executed with no signal option.
SIGTERM is the default signal, as in unix kill command.
nsh> kill [-<signal>] <pid>
---
nshlib/nsh_command.c | 2 +-
nshlib/nsh_proccmds.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 58b7e65..5dbe6c3 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, "-<signal> <pid>" },
+ { "kill", cmd_kill, 2, 3, "[-<signal>] <pid>" },
#endif
#ifndef CONFIG_DISABLE_MOUNTPOINT
diff --git a/nshlib/nsh_proccmds.c b/nshlib/nsh_proccmds.c
index d5797a8..01a615f 100644
--- a/nshlib/nsh_proccmds.c
+++ b/nshlib/nsh_proccmds.c
@@ -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;
+ }
}
+ else if (argc == 2) /* kill <pid> */
+ {
+ /* uses default signal number as SIGTERM */
- /* Extract the signal number */
+ signal = (long) SIGTERM; /* SIGTERM is always defined in signal.h */
- signal = strtol(&ptr[1], &endptr, 0);
+ /* The first parameter should be <pid> */
- /* The second parameter should be <pid> */
+ ptr = argv[1];
- ptr = argv[2];
- if (*ptr < '0' || *ptr > '9')
+ if (*ptr < '0' || *ptr > '9')
+ {
+ goto invalid_arg;
+ }
+ }
+ else
{
+ /* invalid number of arguments */
+
goto invalid_arg;
}