diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 74170efee38..045117b08ef 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -8,7 +8,7 @@

NuttShell (NSH)

-

Last Updated: July 06, 2010

+

Last Updated: February 27, 2011

@@ -149,139 +149,145 @@
- 2.12 Setup/teardown the Loop Device (losetup) + 2.12 Send a signal to a task (kill)
- 2.13 List Directory Contents (ls) + 2.13 Setup/teardown the Loop Device (losetup)
- 2.14 Access Memory (mb, mh, and mw) + 2.14 List Directory Contents (ls)
- 2.15 Show Memory Manager Status (mem) + 2.15 Access Memory (mb, mh, and mw)
- 2.16 Show Current Tasks and Threads (ps) + 2.16 Show Memory Manager Status (mem)
- 2.17 Create a Directory (mkdir) + 2.17 Show Current Tasks and Threads (ps)
- 2.18 Create a FAT Filesystem (mkfatfs) + 2.18 Create a Directory (mkdir)
- 2.19 Create a FIFO (mkfifo) + 2.19 Create a FAT Filesystem (mkfatfs)
- 2.20 Create a RAMDISK (mkrd) + 2.20 Create a FIFO (mkfifo)
- 2.21 Mount a File System (mount) + 2.21 Create a RAMDISK (mkrd)
- 2.22 Check Network Peer (ping) + 2.22 Mount a File System (mount)
- 2.23 Send File Via TFTP (put) + 2.23 Check Network Peer (ping)
- 2.24 Show Current Working Directory (pwd) + 2.24 Send File Via TFTP (put)
- 2.25 Remove a File (rm) + 2.25 Show Current Working Directory (pwd)
- 2.26 Remove a Directory (rmdir) + 2.26 Remove a File (rm)
- 2.27 Set an Environment Variable (set) + 2.27 Remove a Directory (rmdir)
- 2.28 Execute an NSH Script (sh) + 2.28 Set an Environment Variable (set)
- 2.29 Wait for Seconds (sleep) + 2.29 Execute an NSH Script (sh)
- 2.30 Unmount a File System (umount) + 2.30 Wait for Seconds (sleep)
- 2.31 Unset an Environment Variable (unset) + 2.31 Unmount a File System (umount)
- 2.32 Wait for Microseconds (usleep) + 2.32 Unset an Environment Variable (unset)
- 2.33 Get File Via HTTP (wget) + 2.33 Wait for Microseconds (usleep)
- 2.34 Hexadecimal Dump (xd) + 2.34 Get File Via HTTP (wget) + + + +
+ + 2.35 Hexadecimal Dump (xd) @@ -682,7 +688,7 @@ test <expression> -Command Syntax:

+

Command Syntax:

@@ -700,7 +706,7 @@ cat <path> [<path> [<path> -
Command Syntax:

+

Command Syntax:

@@ -742,7 +748,7 @@ cd [<dir-path>|-|~|..] -
Command Syntax:

+

Command Syntax:

@@ -760,7 +766,7 @@ cp <source-path> <dest-path> -
Command Syntax:

+

Command Syntax:

@@ -819,7 +825,7 @@ nsh> dd if=/dev/ram0 of=/dev/null -
Command Syntax:

+

Command Syntax:

@@ -856,7 +862,7 @@ exec <hex-address> -
Command Syntax:

+

Command Syntax:

@@ -891,7 +897,7 @@ get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path> -
Command Syntax:

+

Command Syntax:

@@ -910,7 +916,7 @@ exit -
Command Syntax:

+

Command Syntax:

@@ -927,7 +933,7 @@ help -
Command Syntax:

+

Command Syntax:

@@ -948,12 +954,28 @@ eth0 HWaddr 00:18:11:80:10:06
-

2.12 Setup/teardown the Loop Device (losetup)

+

2.12 Send a signal to a task (kill)

-
Command Syntax 1:

+ +

+ Synopsis. + Send the to the task identified by . +

+ + + + + +
+

2.13 Setup/teardown the Loop Device (losetup)

+
+ +

Command Syntax 1:

@@ -989,7 +1011,7 @@ nsh>

-
Command Syntax 2:

+

Command Syntax 2:

@@ -1001,12 +1023,12 @@ losetup d <dev-path>
-

2.13 List Directory Contents (ls)

+

2.14 List Directory Contents (ls)

-
Command Syntax:

+

Command Syntax:

@@ -1038,7 +1060,7 @@ ls [-lRs] <dir-path>
-

2.14 Access Memory (mb, mh, and mw)

+

2.15 Access Memory (mb, mh, and mw)

@@ -1092,12 +1114,12 @@ nsh>
-

2.15 Show Memory Manager Status (mem)

+

2.16 Show Memory Manager Status (mem)

-
Command Syntax:

+

Command Syntax:

@@ -1141,12 +1163,12 @@ nsh>
-

2.16 Show Current Tasks and Threads (ps)

+

2.17 Show Current Tasks and Threads (ps)

-
Command Syntax:

+

Command Syntax:

@@ -1167,7 +1189,7 @@ nsh>
-

2.17 Create a Directory (mkdir)

+

2.18 Create a Directory (mkdir)

@@ -1202,7 +1224,7 @@ nsh>
-

2.18 Create a FAT Filesystem (mkfatfs)

+

2.19 Create a FAT Filesystem (mkfatfs)

@@ -1222,7 +1244,7 @@ mkfatfs <path>
-

2.19 Create a FIFO (mkfifo)

+

2.20 Create a FIFO (mkfifo)

@@ -1260,7 +1282,7 @@ nsh>
-

2.20 Create a RAMDISK (mkrd)

+

2.21 Create a RAMDISK (mkrd)

@@ -1311,7 +1333,7 @@ nsh>
-

2.21 Mount a File System (mount)

+

2.22 Mount a File System (mount)

@@ -1378,12 +1400,12 @@ nsh>
-

2.22 Check Network Peer (ping)

+

2.23 Check Network Peer (ping)

-
Command Syntax:

+

Command Syntax:

@@ -1411,12 +1433,12 @@ nsh>
-

2.23 Send File Via TFTP (put)

+

2.24 Send File Via TFTP (put)

-
Command Syntax:

+

Command Syntax:

@@ -1446,12 +1468,12 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
-

2.24 Show Current Working Directory (pwd)

+

2.25 Show Current Working Directory (pwd)

-
Command Syntax:

+

Command Syntax:

@@ -1476,12 +1498,12 @@ nsh>
-

2.25 Remove a File (rm)

+

2.26 Remove a File (rm)

-
Command Syntax:

+

Command Syntax:

@@ -1510,12 +1532,12 @@ nsh>
-

2.26 Remove a Directory (rmdir)

+

2.27 Remove a Directory (rmdir)

-
Command Syntax:

+

Command Syntax:

@@ -1545,12 +1567,12 @@ nsh>
-

2.27 Set an Environment Variable (set)

+

2.28 Set an Environment Variable (set)

-
Command Syntax:

+

Command Syntax:

@@ -1571,12 +1593,12 @@ nsh>
-

2.28 Execute an NSH Script (sh)

+

2.29 Execute an NSH Script (sh)

-
Command Syntax:

+

Command Syntax:

@@ -1589,12 +1611,12 @@ sh <script-path>
-

2.29 Wait for Seconds (sleep)

+

2.30 Wait for Seconds (sleep)

-
Command Syntax:

+

Command Syntax:

@@ -1606,12 +1628,12 @@ sleep <sec>
-

2.30 Unmount a File System (umount)

+

2.31 Unmount a File System (umount)

-
Command Syntax:

+

Command Syntax:

@@ -1636,12 +1658,12 @@ nsh>
-

2.31 Unset an Environment Variable (unset)

+

2.32 Unset an Environment Variable (unset)

-
Command Syntax:

+

Command Syntax:

@@ -1662,12 +1684,12 @@ nsh>
-

2.32 Wait for Microseconds (usleep)

+

2.33 Wait for Microseconds (usleep)

-
Command Syntax:

+

Command Syntax:

@@ -1679,12 +1701,12 @@ usleep <usec>
- 2.33 Get File Via HTTP (wget) + 2.34 Get File Via HTTP (wget)
-
Command Syntax:

+

Command Syntax:

@@ -1706,12 +1728,12 @@ wget [-o <local-path>] <url>
-

2.34 Hexadecimal dump (xd)

+

2.35 Hexadecimal dump (xd)

-
Command Syntax:

+

Command Syntax:

@@ -1825,6 +1847,11 @@ nsh> CONFIG_NET CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG + + kill + !CONFIG_DISABLE_SIGNALS + CONFIG_EXAMPLES_NSH_DISABLE_KILL + losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 @@ -2331,6 +2358,7 @@ nsh>
  • help
  • if-then[-else]-fi
  • ifconfig
  • +
  • kill
  • losetup
  • ls
  • mb
  • diff --git a/examples/nsh/README.txt b/examples/nsh/README.txt index 73c281558df..bbe1429d8fd 100644 --- a/examples/nsh/README.txt +++ b/examples/nsh/README.txt @@ -329,6 +329,10 @@ o ifconfig if uIP statistics are enabled (CONFIG_NET_STATISTICS), then this command will also show the detailed state of uIP. +o kill - + + Send the to the task identified by . + o losetup [-d ] | [[-o ] [-r] ] Setup or teardown the loop device: @@ -769,6 +773,7 @@ Command Dependencies on Configuration Settings get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1) help -- ifconfig CONFIG_NET + kill !CONFIG_DISABLE_SIGNALS losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 ls CONFIG_NFILE_DESCRIPTORS > 0 mb,mh,mw --- @@ -812,15 +817,16 @@ also allow it to squeeze into very small memory footprints. CONFIG_EXAMPLES_NSH_DISABLE_CAT, CONFIG_EXAMPLES_NSH_DISABLE_CD, CONFIG_EXAMPLES_NSH_DISABLE_CP, CONFIG_EXAMPLES_NSH_DISABLE_DD, CONFIG_EXAMPLES_NSH_DISABLE_ECHO, CONFIG_EXAMPLES_NSH_DISABLE_EXEC, CONFIG_EXAMPLES_NSH_DISABLE_EXIT, CONFIG_EXAMPLES_NSH_DISABLE_GET, CONFIG_EXAMPLES_NSH_DISABLE_HELP, - CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG, CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP, CONFIG_EXAMPLES_NSH_DISABLE_LS, - CONFIG_EXAMPLES_NSH_DISABLE_MB, CONFIG_EXAMPLES_NSH_DISABLE_MEM, CONFIG_EXAMPLES_NSH_DISABLE_MKDIR, - CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS, CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO, CONFIG_EXAMPLES_NSH_DISABLE_MKRD, - CONFIG_EXAMPLES_NSH_DISABLE_MH, CONFIG_EXAMPLES_NSH_DISABLE_MOUNT, CONFIG_EXAMPLES_NSH_DISABLE_MW, - CONFIG_EXAMPLES_NSH_DISABLE_PS, CONFIG_EXAMPLES_NSH_DISABLE_PING, CONFIG_EXAMPLES_NSH_DISABLE_PUT, - CONFIG_EXAMPLES_NSH_DISABLE_PWD, CONFIG_EXAMPLES_NSH_DISABLE_RM, CONFIG_EXAMPLES_NSH_DISABLE_RMDIR, - CONFIG_EXAMPLES_NSH_DISABLE_SET, CONFIG_EXAMPLES_NSH_DISABLE_SH, CONFIG_EXAMPLES_NSH_DISABLE_SLEEP, - CONFIG_EXAMPLES_NSH_DISABLE_TEST, CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT, CONFIG_EXAMPLES_NSH_DISABLE_UNSET, - CONFIG_EXAMPLES_NSH_DISABLE_USLEEP, CONFIG_EXAMPLES_NSH_DISABLE_WGET, CONFIG_EXAMPLES_NSH_DISABLE_XD + CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG, CONFIG_EXAMPLES_NSH_DISABLE_KILL, CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP, + CONFIG_EXAMPLES_NSH_DISABLE_LS, CONFIG_EXAMPLES_NSH_DISABLE_MB, CONFIG_EXAMPLES_NSH_DISABLE_MEM, + CONFIG_EXAMPLES_NSH_DISABLE_MKDIR, CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS, CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO, + CONFIG_EXAMPLES_NSH_DISABLE_MKRD, CONFIG_EXAMPLES_NSH_DISABLE_MH, CONFIG_EXAMPLES_NSH_DISABLE_MOUNT, + CONFIG_EXAMPLES_NSH_DISABLE_MW, CONFIG_EXAMPLES_NSH_DISABLE_PS, CONFIG_EXAMPLES_NSH_DISABLE_PING, + CONFIG_EXAMPLES_NSH_DISABLE_PUT, CONFIG_EXAMPLES_NSH_DISABLE_PWD, CONFIG_EXAMPLES_NSH_DISABLE_RM, + CONFIG_EXAMPLES_NSH_DISABLE_RMDIR, CONFIG_EXAMPLES_NSH_DISABLE_SET, CONFIG_EXAMPLES_NSH_DISABLE_SH, + CONFIG_EXAMPLES_NSH_DISABLE_SLEEP, CONFIG_EXAMPLES_NSH_DISABLE_TEST, CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT, + CONFIG_EXAMPLES_NSH_DISABLE_UNSET, CONFIG_EXAMPLES_NSH_DISABLE_USLEEP, CONFIG_EXAMPLES_NSH_DISABLE_WGET, + CONFIG_EXAMPLES_NSH_DISABLE_XD NSH-Specific Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/examples/nsh/nsh.h b/examples/nsh/nsh.h index c1c1a9ed871..29bd19b98a9 100644 --- a/examples/nsh/nsh.h +++ b/examples/nsh/nsh.h @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nsh/nsh.h * - * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -474,6 +474,9 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif /* CONFIG_DISABLE_ENVIRON */ #ifndef CONFIG_DISABLE_SIGNALS +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_KILL + extern int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif # ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP extern int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index 223a3537c25..80a9eb8e1a8 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nsh/nsh_main.c * - * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -189,6 +189,12 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif +#ifndef CONFIG_DISABLE_SIGNALS +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP + { "kill", cmd_kill, 3, 3, "kill - " }, +# endif +#endif + #if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) # ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP { "losetup", cmd_losetup, 3, 6, "[-d ] | [[-o ] [-r] ]" }, diff --git a/examples/nsh/nsh_proccmds.c b/examples/nsh/nsh_proccmds.c index 6c0c14e37e1..5c3f6db6004 100644 --- a/examples/nsh/nsh_proccmds.c +++ b/examples/nsh/nsh_proccmds.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nsh/nsh_proccmds.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include #include +#include #include "nsh.h" @@ -175,6 +176,80 @@ int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_kill + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_SIGNALS +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_KILL +int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + char *ptr; + char *endptr; + long signal; + long pid; + + /* 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 athe pid */ + + pid = strtol(ptr, &endptr, 0); + + /* 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. + */ + + if (kill((pid_t)pid, (int)signal) == 0) + { + return OK; + } + + switch (errno) + { + case EINVAL: + goto invalid_arg; + + case ESRCH: + nsh_output(vtbl, g_fmtnosuch, argv[0], "task", argv[2]); + return ERROR; + + case EPERM: + case ENOSYS: + default: + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "kill", NSH_ERRNO); + return ERROR; + } + +invalid_arg: + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + return ERROR; +} +#endif +#endif + /**************************************************************************** * Name: cmd_sleep ****************************************************************************/ diff --git a/sched/sig_kill.c b/sched/sig_kill.c index 7d36ac4b137..5e91250883f 100644 --- a/sched/sig_kill.c +++ b/sched/sig_kill.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sig_kill.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -96,7 +96,7 @@ int kill(pid_t pid, int signo) if (pid <= 0) { - *get_errno_ptr() = ENOSYS; + errno = ENOSYS; return ERROR; } @@ -104,7 +104,7 @@ int kill(pid_t pid, int signo) if (!GOOD_SIGNO(signo)) { - *get_errno_ptr() = EINVAL; + errno = EINVAL; return ERROR; } @@ -118,7 +118,7 @@ int kill(pid_t pid, int signo) sdbg("TCB=0x%08x signo=%d\n", stcb, signo); if (!stcb) { - *get_errno_ptr() = ESRCH; + errno = ESRCH; sched_unlock(); return ERROR; }