Commit Graph

126 Commits

Author SHA1 Message Date
Junbo Zheng
79e770b0c6 apps/nshlib: add the missing FAR macro for all source files
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-22 14:22:13 +08:00
Fotis Panagiotopoulos
0cdb2cfa48 Fixed compiler warnings. 2022-08-23 01:39:59 +08:00
Norman Rasmussen
6285990a5c Remove trailing whitespace from commands as parameters 2022-01-01 22:18:07 +08:00
Norman Rasmussen
92287e2b14 Fix some edge case bugs in nsh_parse
- Handle nsh_filecat returning NULL on failure
- Background and redirect must be restored after an empty line
- Output redirection should be removed from argv like background
2022-01-01 22:18:07 +08:00
Xiang Xiao
ecae66fe59 Replace all CONFIG_NFILE_STREAMS with CONFIG_FILE_STREAM
follow up the kernel side change

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ic27ad65d7cc2ea570921e0c17098dcb6bfe1893a
2020-09-11 17:57:58 +08:00
Masayuki Ishikawa
7f48576218 nshlib: Fix memory corruption in nsh_parse.c
Summary:
- Fix memory corruption when pthread_create() failed in nsh_execute()

Impact:

- nsh builtin command execution in background with errors

Testing:

- Tested with hifive1-revb:nsh
- Set CONFIG_MAX_TASKS=4
- Run 'sleep 1000 &' in 3 times will cause pthread_create error
- Run free, ps command

Reported-by: Yoshinori Sugino <ysgn0101@gmail.com>
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-08-11 13:57:02 +02:00
chao.an
898c1ce4d2 Revert "This critical behavior was broken by this commit:"
This reverts commit 9b06b508f9.

Signed-off-by: chao.an <anchao@xiaomi.com>
2020-05-18 06:53:57 -06:00
Gregory Nutt
4f54a75c48 apps/nshlib/nsh_parse.c: Add some comments.
Add some comments to nsh_parse.c emphasizing the reason that things are done in the order that they are.  Perhaps such comments will avoid similar breakage in the future.
2020-05-18 10:03:17 +08:00
Gregory Nutt
60428baed6 apps/nshlib/nsh_parse.c: Run through nxstyle. 2020-05-17 23:38:05 +01:00
Gregory Nutt
9b06b508f9 This critical behavior was broken by this commit:
commit 9a28ccf836
    Author: chao.an <anchao@xiaomi.com>
    Date:   Fri Feb 21 09:54:47 2020 +0800

        nsh/parse: try the builtin configuration first

        In the case of enable the BUILTIN_APPS/FILE_APPS at the same time,
        try the builtin list first to ensure that the relevant configuration
        (stacksize, priority) can be set normally.

This commit breaks the feature because it changes the order to that the built-in application is tried first.  Hence, the version on the file system will never replace the built-in version.

That commit must be reverted in order to restore the correct functionality.

    Revert "nsh/parse: try the builtin configuration first"

    This reverts commit 9a28ccf836.
2020-05-17 23:38:05 +01:00
Xiang Xiao
41d88f06e7 Run codespell -w with the latest dictonary again 2020-02-23 07:10:14 -06:00
chao.an
9a28ccf836 nsh/parse: try the builtin configuration first
In the case of enable the BUILTIN_APPS/FILE_APPS at the same time, try the builtin list first to ensure that the relevant configuration(stacksize, priority) can be set normally.
2020-02-21 07:40:47 -06:00
Xiang Xiao
857158451b Unify the void cast usage
1.Remove void cast for function because many place ignore the returned value witout cast
2.Replace void cast for variable with UNUSED macro

Change-Id: Ie644129a563244a6397036789c4c3ea83c4e9b09
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-01-02 23:21:01 +08:00
Gregory Nutt
0536c5b523 apps/nshlib/nsh_parse.c: Correct an error found in build testing. Commit 2a462c78aa was insufficient. It was a mistake to revert Xiang's change of commit 9defae8af6. But we are on a different vector now. 2019-12-24 12:18:30 -06:00
Gregory Nutt
2a462c78aa nshlib/nsh_parse.c: Replacement implementation for 9defae8af6. This addes conditional compilation on the definition of g_nullstring[] to avoid the warning. Suggested by SUZUKI Y <NBG03015@nifty.ne.jp> 2019-12-19 07:59:30 -06:00
Gregory Nutt
6bfd6166dd Revert "apps/nshlib/nsh_parse.c: Fix warning: 'g_nullstring defined but not used'. Use directly since the usage is triggered by a complex Kconfig combination."
Per SUZUKI Y <NBG03015@nifty.ne.jp>, changing:

-      return (FAR char *)g_nullstring;
+      return "";

causes a bad return value because "" lies on the stack.

This reverts commit 9defae8af6.
2019-12-19 07:52:00 -06:00
Xiang Xiao
9defae8af6 apps/nshlib/nsh_parse.c: Fix warning: 'g_nullstring defined but not used'. Use directly since the usage is triggered by a complex Kconfig combination. 2019-12-18 09:43:31 -06:00
Gregory Nutt
77a3b08302 apps/nshlib/nsh_parse.c: Ensure /bin/ping and ping work at the same time. Don't skip nsh_builtin even CONFIG_NSH_FILE_APPS or CONFIG_FS_BINFS equal y. 2019-12-10 08:40:29 -06:00
Gregory Nutt
8c36ec3f33 nshlib/nsh_parse.c: Fix a warning about an uninitialized variable from the ZDS-II compiler. 2019-06-03 09:29:44 -06:00
Gregory Nutt
8f5944c4a8 Squashed commit of the following:
include/ and netutils/:  Remove references to CONFIG_DISABLE_SIGNALS.  Signals can no longer be disabled.
    nshlib/:  Remove references to CONFIG_DISABLE_SIGNALS.  Signals can no longer be disabled.
    system/:  Remove references to CONFIG_DISABLE_SIGNALS.  Signals can no longer be disabled.
    testing/:  Remove references to CONFIG_DISABLE_SIGNALS.  Signals can no longer be disabled.
    examples/:  Remove references to CONFIG_DISABLE_SIGNALS.  Signals can no longer be disabled.
2019-04-29 14:53:38 -06:00
Ken Pettit
e08d100919 apps/nshlib/nsh_parse.c: Fixes an error in the NSH parser. There was a bug when executing an nsh shell script which contains a redirection. When the command in the script is executed, it sets the vtbl->np.np_redirect flag (as it should), but then doesn't restore it, leaving it set at the end of the script execution. Then the vtbl->np.np_redirect flag is set when the 'sh' command completes, causing a restore from un-initialized variables, thus leading to a crash. See the code snippet below for an example test case.
Test case:

NuttShell (NSH)
nsh> mkrd -s 1024 40
nsh> mkfatfs /dev/ram0
nsh> mount -t vfat /dev/ram0 /tmp
nsh> echo "echo 1 > /dev/null" > /tmp/test.sh
nsh> cat /tmp/test.sh
echo 1 > /dev/null
nsh> sh /tmp/test.sh
...

The nsh prompt doesn't get printed.  You can type a couple of commands, but then the system will crash because of bad pointers.
2019-01-12 10:56:48 -06:00
Gregory Nutt
3257ea42d5 apps/nshlib/nsh_parrse.c: Correct some coding standard problems in last PR. 2019-01-06 10:00:19 -06:00
Daniel Agar
c700bf9739 Merged in dagar/nuttx-apps/pr-nshlib (pull request #163)
[WIP] nshlib add var expansion in nsh parse

Approved-by: GregoryN <gnutt@nuttx.org>
2019-01-06 15:52:18 +00:00
GregoryN
3bf4b6d245 Merged altconsole into master 2018-12-08 18:53:54 -06:00
Gregory Nutt
cb982ea8df apps/nshlib: Eliminate more new warnings found in build testing. 2018-10-02 11:16:15 -06:00
Gregory Nutt
2bc4d1e8e2 apps/nshlib/nsh_parse.c: Fix a warning (really a bug) detected in build testing. 2018-10-02 11:08:17 -06:00
Gregory Nutt
7f7b728231 apps/nshlib/nsh_parse.c: Correct an error in conditional compilation found in build testing. 2018-10-02 10:21:33 -06:00
Gregory Nutt
e9edfd064f apps/nshlib: Add support for NSH local variables if CONFIG_NSH_VARS are set. These are like environment variables but are local to NSH. The importance of this is that these variables are *not* inherited when NSH creates a new task. The new command 'export' was added. In this case, the NSH variable will be promoted to an environment variable and will then be inherited by any tasks executed by NSH. 2018-10-01 13:30:25 -06:00
Xiang Xiao
dbf152cbeb apps/nshlib: (1) NSH prompt string is now configurable. nsh> is still the default. (2) Increase the default configuration for the maximum number of command line arguments to 7 (CONFIG_NSH_MAXARGUMENTS). This is needed for 'mount' with the -o option. 2018-08-23 07:34:30 -06:00
Gregory Nutt
f2ef84f048 apps/nshlib: Back out 516a743344. While the change is fuly functional and adds a pleasing symmetry to the control commands, it is also redundant and serves no real purpose other than requiring more FLASH. 2018-08-12 06:15:29 -06:00
Gregory Nutt
ff192a4a58 apps/nshlib: I was able to cause an assertion with some typos in an testing the 'fi' command. Not an important thing, but this will protect against the assertion. 2018-08-11 09:30:53 -06:00
Gregory Nutt
516a743344 apps/nshlib: Extend Beat Küng's commit 888ad352eb so that inverted logic may also be used in repeat and while loops. 2018-08-11 07:53:22 -06:00
Beat Küng
888ad352eb Merged in bkueng/nuttx-apps (pull request #150)
nsh: add inverted logic support in the form of 'if ! <cmd>'

Approved-by: GregoryN <gnutt@nuttx.org>
2018-08-11 13:14:41 +00:00
Gregory Nutt
303629dbe4 apps/nshlib: Small parsing improvement plus some added comments. 2018-08-06 15:52:02 -06:00
Gregory Nutt
cb556d6236 apps/nshlib: Add parsing support for back-slash quoted characters. Currenlty only implemented properly if CONFIG_NSH_ARGCAT is also selected. This commit is in response to Bitbucket Issue 11 opened by Maciej Wójcik 2018-08-06 13:28:31 -06:00
Beat Küng
c6697c150d Merged in bkueng/nuttx-apps (pull request #138)
nsh_parse.c: fix 'while' and 'until' loop condition

The loop condition logic was inverted:
  while true; do echo "test"; done
would exit immediately, while using 'until' would stay in the loop.
This is the opposite of how it is supposed to work.
The reason is that 'state' was set wrong because 'whilematch' is a bool.

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2018-06-06 12:50:41 +00:00
Gregory Nutt
bb6877ed78 apps/nshlib: Fix compile error when CONFIG_NSH_DISABLESCRIPT is not defined. The field np_flags does not exist if scripting is disabled. 2018-01-22 08:32:40 -06:00
Gregory Nutt
ef353ed632 Fix parsing of empty strings when CONFIG_NSH_CMDPARMS is not defined. Problem noted by Juha Niskanen. 2017-10-27 06:41:26 -06:00
Bruno Herrera
3fe720d1e2 Fixes for problems found by Coverity in the apps/ repository:
nshlib/nsh_parse.c: Avoid truncating the strcmp result into a unsigned char variable.

    nshlib/nsh_netcmds.c: Check for valid hostip before using it.

    nshlib/nsh_ddcmd.c: Fix resouce leak when 'if=' or 'of=' params are repeated in the command line.  For example:

       dd if=/dev/null if=/dev/zero of=/dev/null or
       dd if=/dev/zero of=/dev/zero of=/dev/null
2017-09-25 07:34:34 -06:00
Gregory Nutt
1cdf4ad8d1 Fix a warning found in build testing 2017-08-12 11:14:30 -06:00
David Sidrane
35cf98d4df Print expanded variables if -x 2017-04-05 18:31:47 -06:00
Gregory Nutt
2ef46ce4ba NSH library: In nsh_argexand(), if CONFIG_NSH_ARGCAT is defined but CONFIG_NSH_CMDPARMS defined and/or CONFIG_DISABLE_ENVIRON not defined, then there is a situation that causes an infinite loop in the parser. Noted by Freddie Chopin. 2017-03-09 08:07:22 -06:00
Gregory Nutt
bab5df0966 Eliminate a warning about an unused variable. 2017-02-27 07:30:52 -06:00
Sebastien Lorquet
2cbad44f1d This is the Pokemon patch to change all includes fronm <apps/bla/bla.h> to "bla/bla.h" 2016-07-11 10:11:18 -06:00
Gregory Nutt
0e76ca7474 Move apps/include/nsh.h to apps/include/nshlib/nshlib.h 2016-07-01 06:59:23 -06:00
Gregory Nutt
5098539063 Add _ to front of remaining debug macros 2016-06-16 12:12:34 -06:00
Gregory Nutt
586b0aa7e0 Change names of *dbg() * *err() 2016-06-11 15:51:27 -06:00
Gregory Nutt
93d9d5e4ca apps/nshlib: All NSH sessions may now be protected with passwords stored in the encrypted /etc/passwd file 2016-01-20 14:42:39 -06:00
Gregory Nutt
3dad8a29a2 NSH now supports an MOTD string that will be presented after the greeting 2016-01-20 11:18:08 -06:00
Gregory Nutt
7f5a7a07a5 Costmetic alignment 2016-01-17 08:12:51 -06:00