xiaoxiang781216 commented on code in PR #2585:
URL: https://github.com/apache/nuttx-apps/pull/2585#discussion_r1767685744
##########
nshlib/nsh_command.c:
##########
@@ -310,6 +310,10 @@ static const struct cmdmap_s g_cmdmap[] =
CMD_MAP("kill", cmd_kill, 2, 3, "[-<signal>] <pid>"),
#endif
+#ifndef CONFIG_NSH_DISABLE_PKILL
Review Comment:
```suggestion
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
```
```
##########
nshlib/nsh_proccmds.c:
##########
@@ -801,6 +801,107 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
#endif
+/****************************************************************************
+ * Name: cmd_pkill
+ ****************************************************************************/
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
+int cmd_pkill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR const char *name;
+ FAR char *ptr;
+ pid_t pids[8];
+ long signal;
Review Comment:
```suggestion
int signal;
```
##########
nshlib/nsh_proccmds.c:
##########
@@ -801,6 +801,107 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
#endif
+/****************************************************************************
+ * Name: cmd_pkill
+ ****************************************************************************/
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
+int cmd_pkill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR const char *name;
+ FAR char *ptr;
+ pid_t pids[8];
+ long signal;
+ ssize_t ret;
+ int i;
+
+ /* pkill will send SIGTERM to the task in case no signal is selected by
+ * -<signal> option
+ */
+
+ if (argc == 3) /* pkill -<signal> <name> */
+ {
+ /* 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], NULL, 0);
+
+ /* The second parameter should be <pid> */
+
+ name = argv[2];
+ }
+ else if (argc == 2) /* kill <pid> */
+ {
+ /* uses default signal number as SIGTERM */
+
+ signal = (long) SIGTERM; /* SIGTERM is always defined in signal.h */
Review Comment:
```suggestion
signal = SIGTERM; /* SIGTERM is always defined in signal.h */
```
##########
nshlib/nsh_proccmds.c:
##########
@@ -801,6 +801,107 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
#endif
+/****************************************************************************
+ * Name: cmd_pkill
+ ****************************************************************************/
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
+int cmd_pkill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR const char *name;
+ FAR char *ptr;
+ pid_t pids[8];
+ long signal;
+ ssize_t ret;
+ int i;
+
+ /* pkill will send SIGTERM to the task in case no signal is selected by
+ * -<signal> option
+ */
+
+ if (argc == 3) /* pkill -<signal> <name> */
+ {
+ /* 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], NULL, 0);
Review Comment:
```suggestion
signal = atoi(&ptr[1]);
```
##########
nshlib/nsh_proccmds.c:
##########
@@ -801,6 +801,107 @@ int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
#endif
+/****************************************************************************
+ * Name: cmd_pkill
+ ****************************************************************************/
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
+int cmd_pkill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR const char *name;
+ FAR char *ptr;
+ pid_t pids[8];
+ long signal;
+ ssize_t ret;
+ int i;
+
+ /* pkill will send SIGTERM to the task in case no signal is selected by
+ * -<signal> option
+ */
+
+ if (argc == 3) /* pkill -<signal> <name> */
+ {
+ /* 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], NULL, 0);
+
+ /* The second parameter should be <pid> */
+
+ name = argv[2];
+ }
+ 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 name */
+
+ name = argv[1];
+ }
+ else
+ {
+ /* invalid number of arguments */
+
+ goto invalid_arg;
+ }
+
+ ret = nsh_getpid(vtbl, name, pids, nitems(pids));
+ if (ret <= 0)
+ {
+ nsh_error(vtbl, g_fmtnosuch, argv[0], "task", name);
+ return ERROR;
+ }
+
+ /* Send the signal. Kill return values:
+ *
+ * EINVAL An invalid signal was specified.
+ * EPERM The process does not have permission to send the signal to any
+ * of the target processes.
+ * ESRCH The pid or process group does not exist.
+ * ENOSYS Do not support sending signals to process groups.
+ */
+
+ for (i = 0; i < ret; i++)
+ {
+ if (kill(pids[i], (int)signal) != 0)
Review Comment:
```suggestion
if (kill(pids[i], signal) != 0)
```
##########
nshlib/nsh.h:
##########
@@ -1181,6 +1181,9 @@ int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv);
#ifndef CONFIG_NSH_DISABLE_KILL
int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif
+#ifndef CONFIG_NSH_DISABLE_PKILL
Review Comment:
```suggestion
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_PKILL)
```
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]