Add the API "nsh_getpid" in "nsh_fsutils. c" and the nsh command pidof. Temporarily support two parameters, - s, and process name
Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
Add nsh_none to consume all empty traces from nsh.
For the variadic argument case need to add a (inline) function to eat
away the __VA_ARGS__ list, there is no good / portable way to do this by
pre-processor macros, but a function will eat the variadic list whatever
its size is.
Fixes following warning:
CC: grp/lib_getgrbufr.c nsh_timcmds.c: In function 'cmd_date':
nsh_timcmds.c:370:19: warning: variable 'errfmt' set but not used [-Wunused-but-set-variable]
370 | FAR const char *errfmt;
|
Got use-after-free warning under GCC 12 with `-O3` option, and I found
that `nsh_strcat` may realloc `ptr`, then `cmdline` may point to invalid
memory.
Let `cmdline` point to the reallocated `ptr` may solve the problem.
Tested by `alias ll='ls -l'` and `ll /` on sim.
GCC output:
CC: binfmt_unloadmodule.c In function 'nsh_aliasexpand',
inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1196:23: error: pointer 'ptr' used after 'realloc' [-Werror=use-after-free]
1196 | ptr = cmdline + len;
| ~~~~~~~~^~~~~~~~~~~~~~~
In function 'nsh_strcat',
inlined from 'nsh_aliasexpand' at nsh_parse.c:1190:21,
inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1100:27: note: call to 'realloc' here
1100 | argument = (FAR char *)realloc(s1, allocsize);
| ^~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Fix error: implicit declaration of function 'nsh_foreach_direntry' [-Werror=implicit-function-declaration] on file nsh_fscmds on some compiler versions.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
text data bss dec hex filename
398953 27088 4128 430169 69059 nuttx /* before */
389241 27072 4128 420441 66a59 nuttx /* after */
-9712 -16
Signed-off-by: chao an <anchao@xiaomi.com>
Add missing FAR and CODE to pointers
Remove FAR for non-pointer variables
Remove extra spaces and align the parameters
Add do {} while(0) wrapper in macro
Use nitems to calculate number of elements in arrays
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
Test on sim/nsh (CONFIG_NSH_DISABLE_HELP=y):
text data bss dec hex filename
393746 26824 4000 424570 67a7a nuttx /* before */
391858 26440 4000 422298 6719a nuttx /* after */
-1888 -384
Signed-off-by: chao an <anchao@xiaomi.com>
When rm -r is passed with no address specified, it will automatically recursively unlink all files under the root path ('/') until unlinking to the mounted folder causes the unlink to fail. In this change, rm -r without a specified path will prompt for missing arguments
Current implementation is broken, in this patch ECHO is
disabled by termios.
This patch works with https://github.com/apache/nuttx/pull/8950
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
The logic that handles back-quotes was faulty, i.e. example command
set FOO `ls -l` would be split into two tokens as follows:
- set FOO `ls
- -l`
This results in nsh: `: no matching ` error, this fixes that issue.
This adds support for more complex alias handling, such as:
$ alias ls='ls -l'
Previously such an alias was not split into the command verb and the
argument correctly, instead the full alias string was handled as the
verb, which obviously fails.
This commit fixes this by expanding the alias, checking whether it has
arguments and if so, it merges the expanded alias + the old command line
together, resulting in a completely new command line.
Example (assuming the alias above has been created):
$ ls /bin
Results in a new command line: "ls -l /bin" which is then parsed and
executed.
switchboot <image path>
Switch to the updated or specified boot system. This command depends on
hardware support CONFIG_BOARDCTL_SWITCH_BOOT. `<image path>` point to a
partion or file which contain the firmware to boot.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
boot [<image path> [<header size>]]
Boot a new firmware image. This command depends on hardware support
CONFIG_BOARDCTL_BOOT_IMAGE. <image path> may point to a partion or file
which contain the firmware to boot. The optional, numeric argument
<header size> may be useful for skipping metadata information preprended
to the firmware image.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Summary:
- I noticed that the ps command shows the wrong format due to
recent changes on sigmask length from 32bits to 64bits
- This commit fixes this issue
Impact:
- None
Testing:
- Tested with sabre-6quad:smp on qemu-7.1
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
A resulting word that is identified to be the command name word of a
simple command shall be examined to determine whether it is an unquoted,
valid alias name.
The keyword here being "a simple command", arguments are not subject to
expansion.