1118 Commits

Author SHA1 Message Date
ligd
d9e178aad0 nshlib/console: fix compile error when open CONFIG_NSH_ALTCONDEV
CC:  mm_heap/mm_memalign.c misc/rwbuffer.c: In function 'rwb_readbytes':
misc/rwbuffer.c:1172:2: warning: #warning Not Implemented [-Wcpp]
 1172 | #warning Not Implemented
      |  ^~~~~~~
CC:  binfmt_unloadmodule.c In file included from nsh_console.c:40:
nsh_console.c: In function 'nsh_consoleredirect':
nsh_console.h:85:30: error: 'struct serialsave_s' has no member named 'cn_confd'; did you mean 'cn_infd'?
   85 | #  define INFD(p)      ((p)->cn_confd)
      |                              ^~~~~~~~
nsh_console.c:344:7: note: in expansion of macro 'INFD'
  344 |       INFD(ssave) = INFD(pstate);
      |       ^~~~
nsh_console.c: In function 'nsh_consoleundirect':
nsh_console.h:85:30: error: 'struct serialsave_s' has no member named 'cn_confd'; did you mean 'cn_infd'?
   85 | #  define INFD(p)      ((p)->cn_confd)
      |                              ^~~~~~~~
nsh_console.c:370:18: note: in expansion of macro 'INFD'
  370 |   INFD(pstate) = INFD(ssave);
      |                  ^~~~

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-29 23:43:04 +08:00
zhanghongyu
4cec3dad0d nsh_netcmds.c: handle the ENETUNREACH error number
before:
server> arp -a 10.0.1.4
nsh: arp: ioctl failed: 101

after:
server> arp -a 10.0.1.4
nsh: arp: no such ARP entry: 10.0.1.4

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-10-29 12:27:16 +08:00
buxiasen
790be6d639 nshlib/nsh_parse: use sh -c replace pthread detach when nsh background.
pthread & detach will still quit when parent task exit,
cause nsh_parse clone args leak. nsh should use task instead of thread

this case can reproduce the memory leak.
int main(int argc, FAR char *argv[])
{
  printf("Hello, World!!\n");
  system("sleep 1 &");
  return 0;
}

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-22 00:04:09 +08:00
wangjianyu3
e5a1bb1796 nshlib/dd: Add support for reading from/writing to standard input/output
Test
  1. Input from stdin and output to stdout
       Keyboard input: 12345AAAAABBBBB
    nsh> dd bs=5
    1234512345AAAAAAAAAABBBBBBBBBB

  2. Input from file and output to stdout
    nsh> dd if=/etc/init.d/rc.sysinit
    mkrd -m 2 -s 512 1024
    mkfatfs /dev/ram2
    mount -t vfat /dev/ram2 "/tmp"

  3. Input from stdin and output to file
       Keyboard input: QWERT
    dd of=/data/dd_stdout bs=5

    Then, cat the output file in host (based on HostFS):
    $ cat ./dd_stdout
    QWERT

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-10-19 14:07:32 +08:00
zhengyu9
697e3bed0a apps/nshlib/cmd_cd: Modify the logic of cd
Modify the implementation logic of changing directory.
There's an error handling the path incluing "../" or "./"

bug examples:

nsh> cd proc/self/group
nsh> cd ../..
nsh: cd: chdir failed: 2

nsh> pwd
/proc/self
nsh> ls
/proc/self:
 status
 cmdline
 stack
 group/
nsh> cd ./group
nsh: cd: chdir failed: 2

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
2024-10-17 18:06:48 +08:00
yinshengkai
59c21c7aee nsh: support watch command
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-17 18:06:32 +08:00
wangjianyu3
c5c18a2997 nshlib/cmd_cat: Avoid casting -1 to size_t as count of nsh_write()
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-10-17 08:55:51 +08:00
yinshengkai
15b081f02d nshlib: fix top command sorting result error
qsort expects the return value to be -1,0,1

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-17 00:00:51 +08:00
buxiasen
4285c4df73 nsh/ps: fix -heap cut more than 10MB
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-16 18:23:54 +08:00
anjiahao
6979fca4dc nshlib: Support top command
show thread sort by cpuloading:
use `top [-n <num> ][ -d <delay>] [ -p <pidlist>] [ -h ]`

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-16 18:23:54 +08:00
anjiahao
6951b64038 nshlib: Reconstruct ps command for top command
divide data collection and data output into two parts

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-16 18:23:54 +08:00
yinshengkai
b90899b1d5 nshlib: ps supports noheap parameter
Obtaining the heap usage size requires traversing all memory.
When the number of threads is large, it will become very slow.

ps -heap
PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK              HEAP  STACK   USED  FILLED COMMAND
  0     0   0 FIFO     Kthread   - Ready              0000000000000000  4338432 2162672 0005196   0.2%  Idle_Task

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-16 18:23:54 +08:00
zhushiqshi
a655e067ef apps: added pid list for ps command.
Signed-off-by: zhushiqshi <zhushiqshi@xiaomi.com>
2024-10-16 18:23:54 +08:00
chao an
43d634ce00 nsh/fsutils: fix build break if CONFIG_NSH_DISABLE_PKILL not disabled
arm-none-eabi/bin/ld: apps/libapps.a(nsh_proccmds.c.obj): in function `cmd_pkill':
apps/nshlib/nsh_proccmds.c:861:(.text.cmd_pkill+0x38): undefined reference to `nsh_getpid'

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-16 14:32:13 +08:00
yangguangcai
49941f1d57 cmd_date:Set optind to zero in the error case.
Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2024-10-16 12:40:04 +08:00
Bowen Wang
4af9653b1e nshlib/nsh_parse: support use \\ to pass '\' to argument
Now the nsh can use \\ to pass '\' to the command

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-16 10:21:30 +08:00
ouyangxiangzhen
44d2250b6e apps: Fix compilation error after nuttx/arch.h excluded.
This patch fix compilation error after excluding nuttx/arch.h.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-10-16 07:12:40 +08:00
anjiahao
345e303133 nshlib:Add macro restrictions to code that uses floating point numbers
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-16 07:11:02 +08:00
yinshengkai
2ea062642f nshlib: Add startup process buried points
Used for system startup time profiling

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-15 12:34:09 +08:00
wangjianyu3
2bfe2c2ed0 nshlib: Fix a typo error of redirect
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-10-13 15:48:57 +08:00
wangjianyu3
0f5a786347 nshlib: Fix stack-buffer-overflow of nsh_redirect()
Board/Config/Command
  sim:nsh
  cat < /etc/init.d/rc.sysinit

Problem
  The NSH hangs after exec the test command.
  `nsh_redirect()` needs to save three fd but array length is only two, stack buffer overflowed!

Related: https://github.com/apache/nuttx-apps/pull/2469

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-10-13 15:48:57 +08:00
Bowen Wang
6f85062019 nshlib/nsh_parse: support use \" and \' to pass " and ' to arguments
Now we can pass symbol " and ' to the nsh command arguments

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 19:22:57 +08:00
Bowen Wang
0b8a52379c nsh_syscmds/rpmsg: include <nuttx/rpmsg/rpmsg.h> to fix compile error
nsh_syscmds.c: In function ‘cmd_rpmsg_once’:
nsh_syscmds.c:567:13: error: ‘RPMSGIOC_PANIC’ undeclared (first use in this function)
  567 |       cmd = RPMSGIOC_PANIC;
      |             ^~~~~~~~~~~~~~
nsh_syscmds.c:567:13: note: each undeclared identifier is reported only once for each function it appears in
nsh_syscmds.c:571:13: error: ‘RPMSGIOC_DUMP’ undeclared (first use in this function); did you mean ‘FIOC_DUMP’?
  571 |       cmd = RPMSGIOC_DUMP;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 14:59:22 +08:00
Yongrong Wang
568310858b nsh_syscmds.c: upadate rpmsg ping help
1. struct rpmsg_ping_s ack change to cmd;
2. Update the help descrption based on the new cmd
   meaning;

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 14:59:22 +08:00
wangmingrong
c2597504e0 nsh: Fix PS printing misalignment
When the stack is allocated in megabytes, printing seven bits of ps will not align

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-10-08 07:58:51 +02:00
wanggang26
d407670115 resetcause:restore to factory, factory to factory_inquiry
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-07 05:10:19 +08:00
anjiahao
c916f163f2 nsh:support wait command to wait task exit.
usage like:
  nsh> sleep 10 &
  [5:100]
  nsh>set pid1=$!
  nsh>sleep 15 &
  [6:100]
  nsh>set pid2=$!
  nsh>wait $pid1 $pid2

'wait' command will block nsh from running until pid1 and pid2 finish.
This is useful for parallel requirements to perform certain tasks

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-02 21:13:54 +08:00
dulibo1
b20f023ab7 pmconfig:fix coverity scan issue which is unsigned_compare
Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
2024-09-30 18:31:03 +08:00
dongjiuzhu1
97a33e7491 nshlib: support dd with conv=notrunc,nocreat
refs to: https://man7.org/linux/man-pages/man1/dd.1.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-30 14:16:40 +08:00
anjiahao
5dcfe93a95 nsh:support $! get last pid use nsh run
test:
    nsh> hello &
    hello [4:100]
    nsh> Hello, World!!

    nsh> echo $!
    4
    nsh> echo $!
    3
    nsh> ps
      PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK COMMAND
        0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069616 Idle_Task
        1     1 224 FIFO     Kthread   - Waiting  Signal    0000000000000000 0067536 loop_task
        2     2 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067504 hpwork 0x45ae80 0x45aea8
        3     3 100 FIFO     Task      - Running            0000000000000000 0067536 nsh_main
    nsh>

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-28 11:28:15 +08:00
yanghuatao
909e479d7f toolchain/ghs: Fix green hills toolchain build Vela warnings
Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-09-28 10:47:32 +08:00
Huang Qi
dca6c0cd91 nshlib: Add missing newline in cmd_pidof output
Add newline at the end of cmd_pidof to show nsh
prompt correctly.

Before this patch:
```
nsh> pidof wifi
3 nsh>
```

After:
```
nsh> pidof wifi
3
nsh>
```
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-27 23:24:22 +08:00
Michal Lenc
f81a094283 nshlib: add support for pkill command
This command looks through the currently running processes and kills
the those that match the selection criteria. This way system can send
signal to processes by name and without knowing the IDs.

Example (kill application hello):
	pkill -15 hello

The command can be turned off by NSH_DISABLE_PKILL option and depends
on FS_PROCFS.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2024-09-23 08:40:54 +08:00
wanggang26
bae15dfd58 nshlib: enable O_CLOEXEC explicit to avoid potential fd leak
leaking here means fork/vfork will duplicate fd without O_CLOEXEC flag
to the child process.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-23 08:34:16 +08:00
wanggang26
864371cc10 nshlib:enable O_CLOEXEC expliciti to avoid potential fd leak
leaking here means fork/vfork will duplicate fd without O_CLOEXEC flag
to the child process.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-22 01:44:06 +08:00
wangjianyu3
aaf4e9d480 nshlib: Support "-f" option for command "rm"
In below two cases "rm" command with "-f" option will return 0:
  a. Bad arguments
  b. File not exists

Following "rm" of GNU coreutils 8.32

GNU coreutils
  $ rm --version
  rm (GNU coreutils) 8.32
  Copyright (C) 2020 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

  Written by Paul Rubin, David MacKenzie, Richard M. Stallman,
  and Jim Meyering.

  $ rm /FILE_NOT_EXISTS
  rm: cannot remove '/FILE_NOT_EXISTS': No such file or directory
  $ echo $?
  1

  $ rm -f
  $ echo $?
  0

  $ rm -f /FILE_NOT_EXISTS
  $ echo $?
  0

Without this patch
  nsh> rm
  nsh: rm: missing required argument(s)

  nsh> rm /FILE_NOT_EXISTS
  nsh: rm: unlink failed: 2
  nsh> echo $?
  1

With this patch
  nsh> rm -f
  nsh> echo $?
  0

  nsh> rm -f /FILE_NOT_EXISTS
  nsh> echo $?
  0

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-19 03:45:37 +08:00
chao an
8ad39537dd nshlib: move g_builtin_prompt from data to rodata
1. move g_builtin_prompt from data to rodata
2. add g_ prefix to some global variables

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-05 09:49:44 +08:00
meijian
c91a1817aa netlib/setroute: fix dhcpd stack-overflow when calls netlib_set_dripv4addr with debug info-level
Signed-off-by: meijian <meijian@xiaomi.com>
2024-08-26 01:54:46 +08:00
zhangshuai39
6d52a0fbc1 netutils/netlib: Encapsulate the dhcp configuration network code and modify at all calling locations
The DHCP configuration network code is called multiple times, so it is encapsulated

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2024-08-23 22:10:04 +08:00
guoshichao
573008244c greenhills: fix the variable unused warning
"nsh_parse.c", line 1565: warning #550-D: variable "quoted" was set but never
          used
    bool quoted;
         ^

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-20 02:50:13 +08:00
Shoukui Zhang
7df20ea1bb nshlib: Optimize the size of the recursive stack
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
2024-08-16 19:48:18 +08:00
Marco Casaroli
0797ee2312 fix(nsh_parse): handle env variables correctly
The PR #2469 broke handling of environment variables because an
error in the if/else if control flow.

This fixes it.
2024-08-10 11:08:18 -03:00
Marco Casaroli
e46347ec1b nsh_fileapp: handle input redirection 2024-08-08 19:19:18 -03:00
Marco Casaroli
8fba726a7d feat(nsh_cat): allow cat to read from stdin
Now, if we run cat without arguments, it will just read from stdin.

It can be used with redirect like `cat < infile > outfile`.
2024-08-08 19:19:18 -03:00
Marco Casaroli
4104019e1c feat(nsh): add console read
This allows programs such as `cat` to read from the console (that could be redirected).
2024-08-08 19:19:18 -03:00
Marco Casaroli
96100b30f2 feat(nsh): input (stdin) redirection
This adds support for `<` to redirect input on nsh commands.
2024-08-08 19:19:18 -03:00
chenrun1
ffcee721ce nshlib/ddcmd:Fixed NSH_CMDOPT_DD_STATS output format warning in 64-bit environment
In file included from nsh_ddcmd.c:44:
nsh_ddcmd.c: In function 'cmd_dd':
nsh_ddcmd.c:456:20: error: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
  456 |   nsh_output(vtbl, "%llu bytes copied, %u usec, ",
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457 |              total, (unsigned int)elapsed);
      |              ~~~~~
      |              |
      |              uint64_t {aka long unsigned int}
nsh_console.h:55:49: note: in definition of macro 'nsh_output'
   55 | #  define nsh_output(v, ...)   (v)->output(v, ##__VA_ARGS__)
      |                                                 ^~~~~~~~~~~
nsh_ddcmd.c:456:24: note: format string is defined here
  456 |   nsh_output(vtbl, "%llu bytes copied, %u usec, ",
      |                     ~~~^
      |                        |
      |                        long long unsigned int
      |                     %lu
cc1: all warnings being treated as errors

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-07 15:04:39 +08:00
chenrun1
f126adb5fc nshlib/fscmds:Fix write overflow during cp -r process
Summary:
      do
        {
          nbyteswritten = write(wrfd, iobuffer, nbytesread);
          if (nbyteswritten >= 0)

The write return type is ssize_t, which is different in size from the originally declared type, so the unified type is ssize_t

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-06 19:30:12 -03:00
Denis Ryndine
a15403958d nsh_dd: fix lseek return check.
- As was merged in commit 1852731df87e5895e299b74aabdb1984b7e3f795 on
   dd_main.c: lseek returns -1 on error.

   Should be consistent in nsh_ddcmd.c and nsh_main.c.
2024-08-01 09:52:03 +08:00
buxiasen
b9a7353a43 add include to handle when PM_NDOMAINS from pm.h
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-05-18 22:08:14 +08:00