You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/19 14:07:14 UTC

[incubator-nuttx-apps] branch master updated (b813944 -> 650b58d)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.


    from b813944  example/nettest: tcpclient and tcpserver to .gitignore
     new 6c4dc44  nshlib: Ensure nsh_initscript always follow usbtrace_enable immediately
     new ac5632f  nshlib: Move BOARDIOC_FINALINIT into nsh_initscript
     new 9dbdc73  nshlib: Reset NSH_NP_SET_OPTIONS_INIT in nsh_initscript
     new 7b4d34e  system/taskset: Call system to launch application instead of nsh_system
     new 9ab5e2f  nshlib: Add login argument to nsh_session for controling the login process
     new d307758  nshlib: Rename 'sh' command to 'source' command
     new 3f93025  nshlib: Enhance nsh to execute the shell script
     new de8a56d  nshlib: Split shell functionality from nsh to sh
     new 650b58d  nshlib: Fix nxstyle warning

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/nshlib/nshlib.h  | 11 ++++---
 nshlib/Kconfig           |  4 +--
 nshlib/README.txt        | 16 +++++-----
 nshlib/nsh.h             |  6 ++--
 nshlib/nsh_altconsole.c  | 22 ++++++--------
 nshlib/nsh_command.c     | 18 +++++++----
 nshlib/nsh_consolemain.c | 28 +++++------------
 nshlib/nsh_fscmds.c      | 34 ++++++++++++++-------
 nshlib/nsh_script.c      | 18 +++++++++--
 nshlib/nsh_session.c     | 41 ++++++++++++++-----------
 nshlib/nsh_stdsession.c  | 35 ++++++++++++---------
 nshlib/nsh_system.c      | 47 ++++++++++++++++++----------
 nshlib/nsh_telnetd.c     | 34 +++++++++++----------
 nshlib/nsh_usbconsole.c  | 31 ++++++++-----------
 system/nsh/Makefile      |  4 +--
 system/nsh/nsh_main.c    | 79 ++++++++++--------------------------------------
 system/nsh/sh_main.c     | 53 ++++++++++++++++++++++++++++++++
 system/popen/Kconfig     |  2 +-
 system/popen/popen.c     | 56 +++++++++++++++++-----------------
 system/system/Kconfig    |  2 +-
 system/system/system.c   | 18 ++++++-----
 system/taskset/Kconfig   |  2 +-
 system/taskset/taskset.c | 33 +++++++-------------
 23 files changed, 316 insertions(+), 278 deletions(-)
 create mode 100644 system/nsh/sh_main.c


[incubator-nuttx-apps] 02/09: nshlib: Move BOARDIOC_FINALINIT into nsh_initscript

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit ac5632fc504f4e66b61131047326e78c16210d5c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 02:24:04 2020 +0800

    nshlib: Move BOARDIOC_FINALINIT into nsh_initscript
    
    1.Avoid the code duplication
    2.Call BOARDIOC_FINALINIT onnce and only once
    3.Ensure BOARDIOC_FINALINIT get called in all case
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_altconsole.c  | 6 ------
 nshlib/nsh_consolemain.c | 6 ------
 nshlib/nsh_script.c      | 6 ++++++
 nshlib/nsh_usbconsole.c  | 6 ------
 4 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index dd574be..ed2fe82 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -292,12 +292,6 @@ int nsh_consolemain(int argc, char *argv[])
   netinit_bringup();
 #endif
 
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
   /* First map stderr and stdout to alternative devices */
 
   ret = nsh_clone_console(pstate);
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 61aabf3..5ff9f0e 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -110,12 +110,6 @@ int nsh_consolemain(int argc, char *argv[])
   netinit_bringup();
 #endif
 
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
   /* Execute the session */
 
   ret = nsh_session(pstate);
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index a29994e..cf77ef9 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -190,6 +190,12 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
   if (!already)
     {
       ret = nsh_script(vtbl, "init", NSH_INITPATH);
+
+#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
+      /* Perform architecture-specific final-initialization (if configured) */
+
+      boardctl(BOARDIOC_FINALINIT, 0);
+#endif
     }
 
   return ret;
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 11c1602..60a8815 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -325,12 +325,6 @@ int nsh_consolemain(int argc, char *argv[])
   netinit_bringup();
 #endif
 
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
   /* Now loop, executing creating a session for each USB connection */
 
   for (;;)


[incubator-nuttx-apps] 09/09: nshlib: Fix nxstyle warning

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 650b58d6b2a82753aaa19b693c2c8080dda8830a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 11:45:51 2020 +0800

    nshlib: Fix nxstyle warning
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/nshlib/nshlib.h  |  9 +++++----
 nshlib/nsh_altconsole.c  | 14 ++++++++------
 nshlib/nsh_consolemain.c |  2 +-
 nshlib/nsh_fscmds.c      | 28 +++++++++++++++++++--------
 nshlib/nsh_script.c      |  4 ++--
 nshlib/nsh_session.c     |  4 +++-
 nshlib/nsh_stdsession.c  |  4 +++-
 nshlib/nsh_system.c      |  2 +-
 nshlib/nsh_telnetd.c     | 24 +++++++++++++-----------
 nshlib/nsh_usbconsole.c  | 23 ++++++++++++-----------
 system/nsh/nsh_main.c    |  2 +-
 system/popen/popen.c     | 49 ++++++++++++++++++++++++------------------------
 system/system/system.c   |  9 +++++----
 13 files changed, 99 insertions(+), 75 deletions(-)

diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h
index 1e0db81..b22dfb5 100644
--- a/include/nshlib/nshlib.h
+++ b/include/nshlib/nshlib.h
@@ -47,8 +47,9 @@
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
-/* If a USB device is selected for the NSH console then we need to handle some
- * special start-up conditions.
+
+/* If a USB device is selected for the NSH console then we need to handle
+ * some special start-up conditions.
  */
 
 #undef HAVE_USB_CONSOLE
@@ -138,7 +139,7 @@ void nsh_initialize(void);
  *
  ****************************************************************************/
 
-int nsh_consolemain(int argc, char *argv[]);
+int nsh_consolemain(int argc, FAR char *argv[]);
 
 /****************************************************************************
  * Name: nsh_telnetstart
@@ -226,7 +227,7 @@ int platform_user_verify(FAR const char *username, FAR const char *password);
  *
  ****************************************************************************/
 
-int nsh_system(int argc, char *argv[]);
+int nsh_system(int argc, FAR char *argv[]);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index b699634..c0570c7 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -78,7 +78,7 @@ static int nsh_clone_console(FAR struct console_stdio_s *pstate)
       return -ENODEV;
     }
 
-  /* Close stderr: note we only close stderr if we opened the alternative one */
+  /* Close stderr: we only close stderr if we opened the alternative one */
 
   fclose(stderr);
 
@@ -101,7 +101,7 @@ static int nsh_clone_console(FAR struct console_stdio_s *pstate)
       return -ENODEV;
     }
 
-  /* Close stdout: note we only close stdout if we opened the alternative one */
+  /* Close stdout: we only close stdout if we opened the alternative one */
 
   fclose(stdout);
 
@@ -202,7 +202,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
     }
   while (fd < 0);
 
-  /* Close stdin: note we only closed stdin if we opened the alternative one */
+  /* Close stdin: we only closed stdin if we opened the alternative one */
 
   fclose(stdin);
 
@@ -212,7 +212,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
 
   if (fd != 0)
     {
-       /* No..  Dup the fd to create standard fd 0.  stdin should not know. */
+      /* No..  Dup the fd to create standard fd 0. stdin should not know. */
 
       dup2(fd, 0);
 
@@ -266,7 +266,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
  *
  ****************************************************************************/
 
-int nsh_consolemain(int argc, char *argv[])
+int nsh_consolemain(int argc, FAR char *argv[])
 {
   FAR struct console_stdio_s *pstate = nsh_newconsole();
   FAR const char *msg;
@@ -280,7 +280,9 @@ int nsh_consolemain(int argc, char *argv[])
   usbtrace_enable(TRACE_BITSET);
 #endif
 
-  /* Execute the one-time start-up script.  Any output will go to /dev/console. */
+  /* Execute the one-time start-up script.
+   * Any output will go to /dev/console.
+   */
 
 #ifdef CONFIG_NSH_ROMFSETC
   nsh_initscript(&pstate->cn_vtbl);
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 84f8275..59b5d7e 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -79,7 +79,7 @@
  *
  ****************************************************************************/
 
-int nsh_consolemain(int argc, char *argv[])
+int nsh_consolemain(int argc, FAR char *argv[])
 {
   FAR struct console_stdio_s *pstate = nsh_newconsole();
   int ret;
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index bd8a55f..3008c04 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -149,7 +149,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
         }
       else
         {
-          /* A NULL entryp signifies that we are running ls on a single file */
+          /* NULL entry signifies that we are running ls on a single file */
 
           ret = stat(dirpath, &buf);
         }
@@ -339,7 +339,7 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
 {
   int ret = OK;
 
-  /* Is this entry a directory (and not one of the special directories, . and ..)? */
+  /* Is this entry a directory (not a special directories, e.g. . and ..)? */
 
   if (DIRENT_ISDIRECTORY(entryp->d_type) && !ls_specialdir(entryp->d_name))
     {
@@ -536,7 +536,9 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
 
       if (S_ISDIR(buf.st_mode))
         {
-          /* Yes, it is a directory. Remove any trailing '/' characters from the path */
+          /* Yes, it is a directory.
+           * Remove any trailing '/' characters from the path
+           */
 
           nsh_trimdir(destpath);
 
@@ -728,7 +730,9 @@ int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
-  /* If a bad argument was encountered, then return without processing the command */
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
 
   if (badarg)
     {
@@ -898,7 +902,9 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
-  /* If a bad argument was encountered, then return without processing the command */
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
 
   if (badarg)
     {
@@ -1105,7 +1111,9 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
-  /* If a bad argument was encountered, then return without processing the command */
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
 
   if (badarg)
     {
@@ -1269,7 +1277,9 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
-  /* If a bad argument was encountered, then return without processing the command */
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
 
   if (badarg)
     {
@@ -1392,7 +1402,9 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
-  /* If a bad argument was encountered, then return without processing the command */
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
 
   if (badarg)
     {
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index 4a12b44..35231a3 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -65,7 +65,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
   FAR char *pret;
   int ret = ERROR;
 
-  /* The path to the script may be relative to the current working directory */
+  /* The path to the script may relative to the current working directory */
 
   fullpath = nsh_getfullpath(vtbl, path);
   if (!fullpath)
@@ -137,7 +137,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 
               if ((vtbl->np.np_flags & NSH_PFLAG_SILENT) == 0)
                 {
-                  nsh_output(vtbl,"%s", buffer);
+                  nsh_output(vtbl, "%s", buffer);
                 }
 
               ret = nsh_parse(vtbl, buffer);
diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c
index 00aadcd..329e3a7 100644
--- a/nshlib/nsh_session.c
+++ b/nshlib/nsh_session.c
@@ -130,7 +130,9 @@ int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 
   for (; ; )
     {
-      /* For the case of debugging the USB console... dump collected USB trace data */
+      /* For the case of debugging the USB console...
+       * dump collected USB trace data
+       */
 
 #ifdef CONFIG_NSH_USBDEV_TRACE
       nsh_usbtrace();
diff --git a/nshlib/nsh_stdsession.c b/nshlib/nsh_stdsession.c
index e5f1e03..1a2c6c3 100644
--- a/nshlib/nsh_stdsession.c
+++ b/nshlib/nsh_stdsession.c
@@ -120,7 +120,9 @@ int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 
   for (; ; )
     {
-      /* For the case of debugging the USB console... dump collected USB trace data */
+      /* For the case of debugging the USB console...
+       * dump collected USB trace data
+       */
 
 #ifdef CONFIG_NSH_USBDEV_TRACE
       nsh_usbtrace();
diff --git a/nshlib/nsh_system.c b/nshlib/nsh_system.c
index e866660..83fa347 100644
--- a/nshlib/nsh_system.c
+++ b/nshlib/nsh_system.c
@@ -70,7 +70,7 @@
  *
  ****************************************************************************/
 
-int nsh_system(int argc, char *argv[])
+int nsh_system(int argc, FAR char *argv[])
 {
   FAR struct console_stdio_s *pstate = nsh_newconsole();
   FAR struct nsh_vtbl_s *vtbl;
diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c
index a168549..b2a75dc 100644
--- a/nshlib/nsh_telnetd.c
+++ b/nshlib/nsh_telnetd.c
@@ -257,10 +257,10 @@ int nsh_telnetstart(sa_family_t family)
       usbtrace_enable(TRACE_BITSET);
 #endif
 
-      /* Execute the startup script.  If standard console is also defined, then
-      * we will not bother with the initscript here (although it is safe to
-      * call nshinitscript multiple times).
-      */
+      /* Execute the startup script.  If standard console is also defined,
+       * then we will not bother with the initscript here (although it is
+       * safe to call nshinitscript multiple times).
+       */
 
 #if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
       nsh_initscript(vtbl);
@@ -286,7 +286,8 @@ int nsh_telnetstart(sa_family_t family)
           ret = telnetd_start(&config);
           if (ret < 0)
             {
-              _err("ERROR: Failed to start the Telnet IPv4 daemon: %d\n", ret);
+              _err("ERROR: Failed to start the Telnet IPv4 daemon: %d\n",
+                   ret);
             }
           else
             {
@@ -302,7 +303,8 @@ int nsh_telnetstart(sa_family_t family)
           ret = telnetd_start(&config);
           if (ret < 0)
             {
-              _err("ERROR: Failed to start the Telnet IPv6 daemon: %d\n", ret);
+              _err("ERROR: Failed to start the Telnet IPv6 daemon: %d\n",
+                   ret);
             }
           else
             {
@@ -328,11 +330,11 @@ int nsh_telnetstart(sa_family_t family)
  *   nsh_telnetstart() or it may be started from the NSH command line using
  *   this telnetd command.
  *
- *   Normally this command would be suppressed with CONFIG_NSH_DISABLE_TELNETD
- *   because the Telnet daemon is automatically started in nsh_main.c.  The
- *   exception is when CONFIG_NETINIT_NETLOCAL is selected.  IN that case, the
- *   network is not enabled at initialization but rather must be enabled from
- *   the NSH command line or via other applications.
+ *   This command would be suppressed with CONFIG_NSH_DISABLE_TELNETD
+ *   normally because the Telnet daemon is automatically started in
+ *   nsh_main.c. The exception is when CONFIG_NETINIT_NETLOCAL is selected.
+ *   IN that case, the network is not enabled at initialization but rather
+ *   must be enabled from the NSH command line or via other applications.
  *
  *   In that case, calling nsh_telnetstart() before the the network is
  *   initialized will fail.
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index c60d965..b018773 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -89,9 +89,10 @@ static void nsh_configstdio(int fd)
   dup2(fd, 1);
   dup2(fd, 2);
 
-  /* fdopen to get the stdin, stdout and stderr streams. The following logic depends
-   * on the fact that the library layer will allocate FILEs in order.  And since
-   * we closed stdin, stdout, and stderr above, that is what we should get.
+  /* fdopen to get the stdin, stdout and stderr streams. The following logic
+   * depends on the fact that the library layer will allocate FILEs in order.
+   * And since we closed stdin, stdout, and stderr above, that is what we
+   * should get.
    *
    * fd = 0 is stdin  (read-only)
    * fd = 1 is stdout (write-only, append)
@@ -129,9 +130,9 @@ static int nsh_nullstdio(void)
        */
 
       if (fd > 2)
-       {
+        {
           close(fd);
-       }
+        }
 
       return OK;
     }
@@ -171,8 +172,8 @@ restart:
       fd = open(CONFIG_NSH_USBCONDEV, O_RDWR);
       if (fd < 0)
         {
-          /* ENOTCONN means that the USB device is not yet connected. Anything
-           * else is bad.
+          /* ENOTCONN means that the USB device is not yet connected.
+           * Anything else is bad.
            */
 
           DEBUGASSERT(errno == ENOTCONN);
@@ -230,7 +231,7 @@ restart:
 
   nsh_configstdio(fd);
 
-  /* We can close the original file descriptor now (unless it was one of 0-2) */
+  /* We can close the original file descriptor (unless it was one of 0-2) */
 
   if (fd > 2)
     {
@@ -257,7 +258,7 @@ restart:
  *   operations to handle the cases where the session is lost when the
  *   USB device is unplugged and restarted when the USB device is plugged
  *   in again.
-  *
+ *
  * Input Parameters:
  *   Standard task start-up arguments.  These are not used.  argc may be
  *   zero and argv may be NULL.
@@ -268,7 +269,7 @@ restart:
  *
  ****************************************************************************/
 
-int nsh_consolemain(int argc, char *argv[])
+int nsh_consolemain(int argc, FAR char *argv[])
 {
   FAR struct console_stdio_s *pstate = nsh_newconsole();
   struct boardioc_usbdev_ctrl_s ctrl;
@@ -327,7 +328,7 @@ int nsh_consolemain(int argc, char *argv[])
 
   /* Now loop, executing creating a session for each USB connection */
 
-  for (;;)
+  for (; ; )
     {
       /* Wait for the USB to be connected to the host and switch
        * standard I/O to the USB serial device.
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index 5c20be0..9571bbd 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -177,7 +177,7 @@ int main(int argc, FAR char *argv[])
 #endif
 
 #ifdef CONFIG_NSH_CONSOLE
-  /* If the serial console front end is selected, then run it on this thread */
+  /* If the serial console front end is selected, run it on this thread */
 
   ret = nsh_consolemain(0, NULL);
 
diff --git a/system/popen/popen.c b/system/popen/popen.c
index 99c0ed3..81fe8fc 100644
--- a/system/popen/popen.c
+++ b/system/popen/popen.c
@@ -212,15 +212,16 @@ FILE *popen(FAR const char *command, FAR const char *mode)
       goto errout_with_actions;
     }
 
-  errcode = task_spawnattr_setstacksize(&attr, CONFIG_SYSTEM_POPEN_STACKSIZE);
+  errcode = task_spawnattr_setstacksize(&attr,
+                                        CONFIG_SYSTEM_POPEN_STACKSIZE);
   if (errcode != 0)
     {
       goto errout_with_actions;
     }
 
-   /* If robin robin scheduling is enabled, then set the scheduling policy
-    * of the new task to SCHED_RR before it has a chance to run.
-    */
+  /* If robin robin scheduling is enabled, then set the scheduling policy
+   * of the new task to SCHED_RR before it has a chance to run.
+   */
 
 #if CONFIG_RR_INTERVAL > 0
   errcode = posix_spawnattr_setschedpolicy(&attr, SCHED_RR);
@@ -332,22 +333,22 @@ errout:
  *     waitpid() with a pid argument less than or equal to 0 or equal to the
  *               process ID of the command line interpreter
  *
- *   Any other function not defined in this volume of IEEE Std 1003.1-2001 that
- *   could do one of the above
+ *   Any other function not defined in this volume of IEEE Std 1003.1-2001
+ *   that could do one of the above
  *
- *   In any case, pclose() will not return before the child process created by
- *   popen() has terminated.
+ *   In any case, pclose() will not return before the child process created
+ *   by popen() has terminated.
  *
- *   If the command language interpreter cannot be executed, the child termination
- *   status returned by pclose() will be as if the command language interpreter
- *   terminated using exit(127) or _exit(127).
+ *   If the command language interpreter cannot be executed, the child
+ *   termination status returned by pclose() will be as if the command
+ *   language interpreter terminated using exit(127) or _exit(127).
  *
- *   The pclose() function will not affect the termination status of any child of
- *   the calling process other than the one created by popen() for the associated
- *   stream.
+ *   The pclose() function will not affect the termination status of any
+ *   child of the calling process other than the one created by popen() for
+ *   the associated stream.
  *
- *   If the argument stream to pclose() is not a pointer to a stream created by
- *   popen(), the result of pclose() is undefined.
+ *   If the argument stream to pclose() is not a pointer to a stream created
+ *   by popen(), the result of pclose() is undefined.
  *
  * Description:
  *   stream - The stream reference returned by a previous call to popen()
@@ -377,8 +378,8 @@ int pclose(FILE *stream)
 
   memcpy(original, &container->copy, sizeof(FILE));
 
-  /* Then close the original and free the container (saving the PID of the shell
-   * process)
+  /* Then close the original and free the container (saving the PID of the
+   * shell process)
    */
 
   fclose(original);
@@ -389,13 +390,13 @@ int pclose(FILE *stream)
 #ifdef CONFIG_SCHED_WAITPID
   /* Wait for the shell to exit, retrieving the return value if available. */
 
- result = waitpid(shell, &status, 0);
- if (result < 0)
-   {
-     /* The errno has already been set */
+  result = waitpid(shell, &status, 0);
+  if (result < 0)
+    {
+      /* The errno has already been set */
 
-     return ERROR;
-   }
+      return ERROR;
+    }
 
   return status;
 #else
diff --git a/system/system/system.c b/system/system/system.c
index 5f3f182..3f24359 100644
--- a/system/system/system.c
+++ b/system/system/system.c
@@ -105,15 +105,16 @@ int system(FAR const char *cmd)
       goto errout_with_attrs;
     }
 
-  errcode = task_spawnattr_setstacksize(&attr, CONFIG_SYSTEM_SYSTEM_STACKSIZE);
+  errcode = task_spawnattr_setstacksize(&attr,
+                                        CONFIG_SYSTEM_SYSTEM_STACKSIZE);
   if (errcode != 0)
     {
       goto errout_with_attrs;
     }
 
-   /* If robin robin scheduling is enabled, then set the scheduling policy
-    * of the new task to SCHED_RR before it has a chance to run.
-    */
+  /* If robin robin scheduling is enabled, then set the scheduling policy
+   * of the new task to SCHED_RR before it has a chance to run.
+   */
 
 #if CONFIG_RR_INTERVAL > 0
   errcode = posix_spawnattr_setschedpolicy(&attr, SCHED_RR);


[incubator-nuttx-apps] 07/09: nshlib: Enhance nsh to execute the shell script

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 3f9302561c960f69e453a5b42e8043130a1fc351
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Apr 18 22:27:10 2020 +0800

    nshlib: Enhance nsh to execute the shell script
    
    and support the interactive shell too
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_system.c    | 45 ++++++++++++++++++++++++++++++---------------
 system/popen/popen.c   |  7 ++++---
 system/system/system.c |  7 ++++---
 3 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/nshlib/nsh_system.c b/nshlib/nsh_system.c
index 1549bdc..e866660 100644
--- a/nshlib/nsh_system.c
+++ b/nshlib/nsh_system.c
@@ -41,6 +41,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <assert.h>
 
 #include "nsh.h"
@@ -71,30 +72,44 @@
 
 int nsh_system(int argc, char *argv[])
 {
-  /* Expect argc == 2 with argv[1] being the command to execute */
+  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct nsh_vtbl_s *vtbl;
+  int ret = EXIT_FAILURE;
 
-  if (argc >= 2)
+  DEBUGASSERT(pstate != NULL);
+  vtbl = &pstate->cn_vtbl;
+
+  if (argc < 2)
     {
-      FAR struct console_stdio_s *pstate = nsh_newconsole();
-      FAR struct nsh_vtbl_s *vtbl;
+      /* Execute the interactive shell */
 
-      DEBUGASSERT(pstate != NULL);
-      vtbl = &pstate->cn_vtbl;
+      ret = nsh_session(pstate, false);
+    }
+  else if (strcmp(argv[1], "-h") == 0)
+    {
+      ret = nsh_output(vtbl, "Usage: %s [<script-path>|-c <command>]\n",
+                       argv[0]);
+    }
+  else if (strcmp(argv[1], "-c") != 0)
+    {
+#if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
+      /* Execute the shell script */
 
+      ret = nsh_script(vtbl, argv[0], argv[1]);
+#endif
+    }
+  else if (argc >= 3)
+    {
       /* Parse process the command */
 
-      nsh_parse(vtbl, argv[1]);
+      ret = nsh_parse(vtbl, argv[2]);
 #if CONFIG_NFILE_STREAMS > 0
       fflush(pstate->cn_outstream);
 #endif
+    }
 
-      /* Exit upon return */
+  /* Exit upon return */
 
-      nsh_exit(&pstate->cn_vtbl, OK);
-      return EXIT_SUCCESS;
-    }
-  else
-    {
-      return EXIT_FAILURE;
-    }
+  nsh_exit(&pstate->cn_vtbl, ret);
+  return ret;
 }
diff --git a/system/popen/popen.c b/system/popen/popen.c
index dfc201d..99c0ed3 100644
--- a/system/popen/popen.c
+++ b/system/popen/popen.c
@@ -128,7 +128,7 @@ FILE *popen(FAR const char *command, FAR const char *mode)
   struct sched_param param;
   posix_spawnattr_t attr;
   posix_spawn_file_actions_t file_actions;
-  FAR char *argv[2];
+  FAR char *argv[3];
   int fd[2];
   int oldfd;
   int newfd;
@@ -258,8 +258,9 @@ FILE *popen(FAR const char *command, FAR const char *mode)
    * appropriately.
    */
 
-  argv[0] = (FAR char *)command;
-  argv[1] = NULL;
+  argv[0] = "-c";
+  argv[1] = (FAR char *)command;
+  argv[2] = NULL;
 
 #ifdef CONFIG_SYSTEM_POPEN_SHPATH
   errcode = posix_spawn(&container->shell, CONFIG_SYSTEM_POPEN_SHPATH,
diff --git a/system/system/system.c b/system/system/system.c
index 76749c2..5f3f182 100644
--- a/system/system/system.c
+++ b/system/system/system.c
@@ -74,7 +74,7 @@
 
 int system(FAR const char *cmd)
 {
-  FAR char *argv[2];
+  FAR char *argv[3];
   struct sched_param param;
   posix_spawnattr_t attr;
   pid_t pid;
@@ -141,8 +141,9 @@ int system(FAR const char *cmd)
 
   /* Spawn nsh_system() which will execute the command under the shell. */
 
-  argv[0] = (FAR char *)cmd;
-  argv[1] = NULL;
+  argv[0] = "-c";
+  argv[1] = (FAR char *)cmd;
+  argv[2] = NULL;
 
 #ifdef CONFIG_SYSTEM_SYSTEM_SHPATH
   errcode = posix_spawn(&pid, CONFIG_SYSTEM_SYSTEM_SHPATH,  NULL, &attr,


[incubator-nuttx-apps] 04/09: system/taskset: Call system to launch application instead of nsh_system

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 7b4d34e3526fc1232ffbf5c1b48392c5ffcbd9be
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 02:35:20 2020 +0800

    system/taskset: Call system to launch application instead of nsh_system
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 system/system/system.c   |  2 +-
 system/taskset/Kconfig   |  2 +-
 system/taskset/taskset.c | 33 +++++++++++----------------------
 3 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/system/system/system.c b/system/system/system.c
index 2573269..76749c2 100644
--- a/system/system/system.c
+++ b/system/system/system.c
@@ -148,7 +148,7 @@ int system(FAR const char *cmd)
   errcode = posix_spawn(&pid, CONFIG_SYSTEM_SYSTEM_SHPATH,  NULL, &attr,
                         argv, (FAR char * const *)NULL);
 #else
-  errcode = task_spawn(&pid, "popen", nsh_system, NULL, &attr,
+  errcode = task_spawn(&pid, "system", nsh_system, NULL, &attr,
                        argv, (FAR char * const *)NULL);
 #endif
 
diff --git a/system/taskset/Kconfig b/system/taskset/Kconfig
index a9e5d21..0be8361 100644
--- a/system/taskset/Kconfig
+++ b/system/taskset/Kconfig
@@ -6,7 +6,7 @@
 config SYSTEM_TASKSET
 	tristate "Taskset Command"
 	default n
-	depends on SMP && NSH_LIBRARY && SCHED_WAITPID
+	depends on SMP && SYSTEM_SYSTEM
 	---help---
 		Enable support for the taskset command.
 
diff --git a/system/taskset/taskset.c b/system/taskset/taskset.c
index 4decd97..b2efb2b 100644
--- a/system/taskset/taskset.c
+++ b/system/taskset/taskset.c
@@ -49,8 +49,6 @@
 #include <errno.h>
 #include <string.h>
 
-#include "nshlib/nshlib.h"
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -59,11 +57,10 @@
  * Name: show_usage
  ****************************************************************************/
 
-static void show_usage(FAR const char *progname, int exitcode) noreturn_function;
 static void show_usage(FAR const char *progname, int exitcode)
 {
-  printf("%s mask command ... \n", progname);
-  printf("%s -p [mask] pid \n", progname);
+  printf("%s mask command ...\n", progname);
+  printf("%s -p [mask] pid\n", progname);
   exit(exitcode);
 }
 
@@ -85,7 +82,7 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set)
     }
   else
     {
-      fprintf(stderr, "invalid cpuset %s \n", arg);
+      fprintf(stderr, "invalid cpuset %s\n", arg);
     }
 
   return ret;
@@ -97,7 +94,6 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set)
 
 int main(int argc, FAR char *argv[])
 {
-  FAR char *nshargv[2];
   char command[CONFIG_NSH_LINELEN];
   int exitcode;
   int option;
@@ -143,7 +139,8 @@ int main(int argc, FAR char *argv[])
 
           if (-1 == rc)
             {
-              fprintf(stderr, "Err in sched_setaffinity() errno=%d \n", errno);
+              fprintf(stderr,
+                      "Err in sched_setaffinity() errno=%d\n", errno);
               goto errout;
             }
         }
@@ -152,11 +149,11 @@ int main(int argc, FAR char *argv[])
 
       if (-1 == rc)
         {
-          fprintf(stderr, "Err in sched_getaffinity() errno=%d \n", errno);
+          fprintf(stderr, "Err in sched_getaffinity() errno=%d\n", errno);
           goto errout;
         }
 
-      printf("pid %d's current affinity mask: %x \n", pid, cpuset);
+      printf("pid %d's current affinity mask: %x\n", pid, cpuset);
     }
   else
     {
@@ -167,8 +164,9 @@ int main(int argc, FAR char *argv[])
               goto errout;
             }
 
-          /* Construct actual command with args */
-          /* NOTE: total length does not exceed CONFIG_NSH_LINELEN */
+          /* Construct actual command with args
+           * NOTE: total length does not exceed CONFIG_NSH_LINELEN
+           */
 
           for (i = 0; i < argc - 2; i++)
             {
@@ -176,17 +174,8 @@ int main(int argc, FAR char *argv[])
               strcat(command, " ");
             }
 
-          nshargv[0] = command;
-          nshargv[1] = NULL;
-
           sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
-          usleep(10 * 1000);
-
-          pid = task_create("system", CONFIG_SYSTEM_TASKSET_PRIORITY,
-                            CONFIG_SYSTEM_TASKSET_STACKSIZE, nsh_system,
-                            (FAR char * const *)nshargv);
-
-          waitpid(pid, &rc, 0);
+          system(command);
         }
     }
 


[incubator-nuttx-apps] 06/09: nshlib: Rename 'sh' command to 'source' command

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit d307758c3cd40c1a537094ad23c256d523f95e43
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Apr 18 21:57:26 2020 +0800

    nshlib: Rename 'sh' command to 'source' command
    
    since this command change the parent environment variable and
    add new '.' command which has the same functionality as 'source'
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/Kconfig       |  4 ++--
 nshlib/README.txt    | 16 ++++++++--------
 nshlib/nsh.h         |  4 ++--
 nshlib/nsh_command.c | 18 ++++++++++++------
 nshlib/nsh_fscmds.c  |  6 +++---
 nshlib/nsh_script.c  |  2 +-
 6 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index a6aa790..6d8b130 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -507,8 +507,8 @@ config NSH_DISABLE_SET
 	bool "Disable set"
 	default n
 
-config NSH_DISABLE_SH
-	bool "Disable sh"
+config NSH_DISABLE_SOURCE
+	bool "Disable source"
 	default n
 
 config NSH_DISABLE_SHUTDOWN
diff --git a/nshlib/README.txt b/nshlib/README.txt
index 49ca81f..8c67779 100644
--- a/nshlib/README.txt
+++ b/nshlib/README.txt
@@ -1199,11 +1199,6 @@ o set [{+|-}{e|x|xe|ex}] [<name> <value>]
     nsh> echo $foobar
     foovalue
 
-o sh <script-path>
-
-  Execute the sequence of NSH commands in the file referred
-  to by <script-path>.
-
 o shutdown [--reboot]
 
   Shutdown and power off the system or, optionally, reset and reboot the
@@ -1218,6 +1213,11 @@ o sleep <sec>
 
   Pause execution (sleep) of <sec> seconds.
 
+o source <script-path>
+
+  Execute the sequence of NSH commands in the file referred
+  to by <script-path>.
+
 o telnetd
 
   The Telnet daemon may be started either programmatically by calling
@@ -1496,9 +1496,9 @@ Command Dependencies on Configuration Settings
              !CONFIG_NSH_DISABLE_ROUTE && (CONFIG_NET_IPv4 || CONFIG_NET_IPv6)
   rptun      CONFIG_RPTUN
   set        CONFIG_NSH_VARS || !CONFIG_DISABLE_ENVIRON
-  sh         CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT
   shutdown   CONFIG_BOARDCTL_POWEROFF || CONFIG_BOARDCTL_RESET
   sleep      --
+  source     CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT
   test       !CONFIG_NSH_DISABLESCRIPT
   telnetd    CONFIG_NSH_TELNET && !CONFIG_NSH_DISABLE_TELNETD
   time       ---
@@ -1541,8 +1541,8 @@ also allow it to squeeze into very small memory footprints.
   CONFIG_NSH_DISABLE_POWEROFF,  CONFIG_NSH_DISABLE_PS,        CONFIG_NSH_DISABLE_PUT,
   CONFIG_NSH_DISABLE_PWD,       CONFIG_NSH_DISABLE_READLINK,  CONFIG_NSH_DISABLE_REBOOT,
   CONFIG_NSH_DISABLE_RM,        CONFIG_NSH_DISABLE_RPTUN,     CONFIG_NSH_DISABLE_RMDIR,
-  CONFIG_NSH_DISABLE_ROUTE,     CONFIG_NSH_DISABLE_SET,       CONFIG_NSH_DISABLE_SH,
-  CONFIG_NSH_DISABLE_SHUTDOWN,  CONFIG_NSH_DISABLE_SLEEP,     CONFIG_NSH_DISABLE_TEST,
+  CONFIG_NSH_DISABLE_ROUTE,     CONFIG_NSH_DISABLE_SET,       CONFIG_NSH_DISABLE_SHUTDOWN,
+  CONFIG_NSH_DISABLE_SLEEP,     CONFIG_NSH_DISABLE_SOURCE,    CONFIG_NSH_DISABLE_TEST,
   CONFIG_NSH_DIABLE_TIME,       CONFIG_NSH_DISABLE_TRUNCATE,  CONFIG_NSH_DISABLE_UMOUNT,
   CONFIG_NSH_DISABLE_UNSET,     CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE,
   CONFIG_NSH_DISABLE_USERADD,   CONFIG_NSH_DISABLE_USERDEL,   CONFIG_NSH_DISABLE_USLEEP,
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 96623f3..06e80cc 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -1008,8 +1008,8 @@ int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
   int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
 #endif
 #if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
-#  ifndef CONFIG_NSH_DISABLE_SH
-  int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+#  ifndef CONFIG_NSH_DISABLE_SOURCE
+  int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
 #  endif
 #endif /* CONFIG_NFILE_STREAMS && !CONFIG_NSH_DISABLESCRIPT */
 
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index da749a8..895ed6b 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -85,6 +85,12 @@ static int  cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc,
 
 static const struct cmdmap_s g_cmdmap[] =
 {
+#if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
+# ifndef CONFIG_NSH_DISABLE_SOURCE
+  { ".",        cmd_source,   2, 2, "<script-path>" },
+# endif
+#endif
+
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
   { "[",        cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]" },
 #endif
@@ -478,12 +484,6 @@ static const struct cmdmap_s g_cmdmap[] =
 #endif
 #endif /* CONFIG_NSH_DISABLE_SET */
 
-#if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
-# ifndef CONFIG_NSH_DISABLE_SH
-  { "sh",       cmd_sh,       2, 2, "<script-path>" },
-# endif
-#endif
-
 #ifndef CONFIG_NSH_DISABLE_SHUTDOWN
 #if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET)
   { "shutdown", cmd_shutdown, 1, 2, "[--reboot]" },
@@ -498,6 +498,12 @@ static const struct cmdmap_s g_cmdmap[] =
   { "sleep",    cmd_sleep,    2, 2, "<sec>" },
 #endif
 
+#if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
+# ifndef CONFIG_NSH_DISABLE_SOURCE
+  { "source",   cmd_source,   2, 2, "<script-path>" },
+# endif
+#endif
+
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
   { "test",     cmd_test,     3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
 #endif
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index 296e917..bd8a55f 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -1671,12 +1671,12 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
 #endif
 
 /****************************************************************************
- * Name: cmd_sh
+ * Name: cmd_source
  ****************************************************************************/
 
 #if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
-#ifndef CONFIG_NSH_DISABLE_SH
-int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+#ifndef CONFIG_NSH_DISABLE_SOURCE
+int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
 {
   return nsh_script(vtbl, argv[0], argv[1]);
 }
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index cf0d536..4a12b44 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -131,7 +131,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
           if (pret)
             {
               /* Parse process the command.  NOTE:  this is recursive...
-               * we got to cmd_sh via a call to nsh_parse.  So some
+               * we got to cmd_source via a call to nsh_parse.  So some
                * considerable amount of stack may be used.
                */
 


[incubator-nuttx-apps] 01/09: nshlib: Ensure nsh_initscript always follow usbtrace_enable immediately

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 6c4dc44e048b7fed047c1501f89d41789ed2e3a5
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 02:14:05 2020 +0800

    nshlib: Ensure nsh_initscript always follow usbtrace_enable immediately
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_consolemain.c | 12 ++++++------
 nshlib/nsh_telnetd.c     | 18 +++++++++---------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 60e1f6e..61aabf3 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -86,6 +86,12 @@ int nsh_consolemain(int argc, char *argv[])
 
   DEBUGASSERT(pstate != NULL);
 
+#ifdef CONFIG_NSH_USBDEV_TRACE
+  /* Initialize any USB tracing options that were requested */
+
+  usbtrace_enable(TRACE_BITSET);
+#endif
+
 #ifdef CONFIG_NSH_ROMFSETC
   /* Execute the start-up script */
 
@@ -104,12 +110,6 @@ int nsh_consolemain(int argc, char *argv[])
   netinit_bringup();
 #endif
 
-#ifdef CONFIG_NSH_USBDEV_TRACE
-  /* Initialize any USB tracing options that were requested */
-
-  usbtrace_enable(TRACE_BITSET);
-#endif
-
 #if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
   /* Perform architecture-specific final-initialization (if configured) */
 
diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c
index bfea5b6..a168549 100644
--- a/nshlib/nsh_telnetd.c
+++ b/nshlib/nsh_telnetd.c
@@ -127,15 +127,6 @@ static int nsh_telnetmain(int argc, char *argv[])
 
   fflush(pstate->cn_outstream);
 
-  /* Execute the startup script.  If standard console is also defined, then
-   * we will not bother with the initscript here (although it is safe to
-   * call nshinitscript multiple times).
-   */
-
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
-  nsh_initscript(vtbl);
-#endif
-
   /* Execute the login script */
 
 #ifdef CONFIG_NSH_ROMFSRC
@@ -266,6 +257,15 @@ int nsh_telnetstart(sa_family_t family)
       usbtrace_enable(TRACE_BITSET);
 #endif
 
+      /* Execute the startup script.  If standard console is also defined, then
+      * we will not bother with the initscript here (although it is safe to
+      * call nshinitscript multiple times).
+      */
+
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
+      nsh_initscript(vtbl);
+#endif
+
       /* Configure the telnet daemon */
 
       config.d_port      = HTONS(CONFIG_NSH_TELNETD_PORT);


[incubator-nuttx-apps] 03/09: nshlib: Reset NSH_NP_SET_OPTIONS_INIT in nsh_initscript

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 9dbdc73df6a199fe7d0fee365d5ad0ad953e5138
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 13:55:15 2020 +0800

    nshlib: Reset NSH_NP_SET_OPTIONS_INIT in nsh_initscript
    
    to ensure the reset get executed in all console implementation
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_consolemain.c | 6 ------
 nshlib/nsh_script.c      | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 5ff9f0e..e213c4c 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -96,12 +96,6 @@ int nsh_consolemain(int argc, char *argv[])
   /* Execute the start-up script */
 
   nsh_initscript(&pstate->cn_vtbl);
-
-#ifndef CONFIG_NSH_DISABLESCRIPT
-  /* Reset the option flags */
-
-  pstate->cn_vtbl.np.np_flags = NSH_NP_SET_OPTIONS_INIT;
-#endif
 #endif
 
 #ifdef CONFIG_NSH_NETINIT
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index cf77ef9..cf0d536 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -191,6 +191,12 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
     {
       ret = nsh_script(vtbl, "init", NSH_INITPATH);
 
+#ifndef CONFIG_NSH_DISABLESCRIPT
+      /* Reset the option flags */
+
+      vtbl->np.np_flags = NSH_NP_SET_OPTIONS_INIT;
+#endif
+
 #if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
       /* Perform architecture-specific final-initialization (if configured) */
 


[incubator-nuttx-apps] 08/09: nshlib: Split shell functionality from nsh to sh

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit de8a56d149343f66736454dedb4b44a352f52c01
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Apr 19 02:02:09 2020 +0800

    nshlib: Split shell functionality from nsh to sh
    
    1.Improve the compatiblity as other OS
    2.Avoid call nsh_initialize more than once
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/nshlib/nshlib.h |  2 ++
 system/nsh/Makefile     |  4 +--
 system/nsh/nsh_main.c   | 77 ++++++++++---------------------------------------
 system/nsh/sh_main.c    | 53 ++++++++++++++++++++++++++++++++++
 system/popen/Kconfig    |  2 +-
 system/system/Kconfig   |  2 +-
 6 files changed, 74 insertions(+), 66 deletions(-)

diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h
index 1e7084d..1e0db81 100644
--- a/include/nshlib/nshlib.h
+++ b/include/nshlib/nshlib.h
@@ -42,6 +42,8 @@
 
 #include <nuttx/config.h>
 
+#include <arpa/inet.h>
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
diff --git a/system/nsh/Makefile b/system/nsh/Makefile
index 232404b..166ca6a 100644
--- a/system/nsh/Makefile
+++ b/system/nsh/Makefile
@@ -37,9 +37,9 @@
 
 # NuttShell (NSH) Example
 
-MAINSRC = nsh_main.c
+MAINSRC = nsh_main.c sh_main.c
 
-PROGNAME = $(CONFIG_SYSTEM_NSH_PROGNAME)
+PROGNAME = $(CONFIG_SYSTEM_NSH_PROGNAME) sh
 PRIORITY = $(CONFIG_SYSTEM_NSH_PRIORITY)
 STACKSIZE = $(CONFIG_SYSTEM_NSH_STACKSIZE)
 MODULE = $(CONFIG_SYSTEM_NSH)
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index 7ebcf80..5c20be0 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -80,17 +80,6 @@
 #  undef CONFIG_SYSTEM_NSH_SYMTAB
 #endif
 
-/* Check if we need to build in support for the system() and/or popen()
- * functions.  In the KERNEL build mode (only), NSH is build as a ELF
- * program and must be capable of executing a single command provided
- * on the command line.
- */
-
-#undef HAVE_NSH_COMMAND
-#if defined(CONFIG_SYSTEM_SYSTEM) || defined(CONFIG_SYSTEM_POPEN)
-#  define HAVE_NSH_COMMAND 1
-#endif
-
 /* C++ initialization requires CXX initializer support */
 
 #if !defined(CONFIG_HAVE_CXX) || !defined(CONFIG_HAVE_CXXINITIALIZE)
@@ -115,11 +104,11 @@ extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
 #endif
 
 /****************************************************************************
- * Private Functions
+ * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: nsh_task
+ * Name: nsh_main
  *
  * Description:
  *   This is the main logic for the case of the NSH task.  It will perform
@@ -128,14 +117,26 @@ extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
  *
  ****************************************************************************/
 
-static int nsh_task(void)
+int main(int argc, FAR char *argv[])
 {
 #if defined (CONFIG_SYSTEM_NSH_SYMTAB)
   struct boardioc_symtab_s symdesc;
 #endif
+  struct sched_param param;
   int exitval = 0;
   int ret;
 
+  /* Check the task priority that we were started with */
+
+  sched_getparam(0, &param);
+  if (param.sched_priority != CONFIG_SYSTEM_NSH_PRIORITY)
+    {
+      /* If not then set the priority to the configured priority */
+
+      param.sched_priority = CONFIG_SYSTEM_NSH_PRIORITY;
+      sched_setparam(0, &param);
+    }
+
 #if defined(CONFIG_SYSTEM_NSH_CXXINITIALIZE)
   /* Call all C++ static constructors */
 
@@ -190,51 +191,3 @@ static int nsh_task(void)
 
   return exitval;
 }
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nsh_main
- ****************************************************************************/
-
-int main(int argc, FAR char *argv[])
-{
-  struct sched_param param;
-
-  /* Check the task priority that we were started with */
-
-  sched_getparam(0, &param);
-  if (param.sched_priority != CONFIG_SYSTEM_NSH_PRIORITY)
-    {
-      /* If not then set the priority to the configured priority */
-
-      param.sched_priority = CONFIG_SYSTEM_NSH_PRIORITY;
-      sched_setparam(0, &param);
-    }
-
-  /* There are two modes that NSH can be executed in:
-   *
-   * 1) As a normal, interactive shell.  In this case, no arguments are
-   *    expected on the command line.  OR
-   * 2) As a single command processor.  In this case, the single command is
-   *    is provided in argv[1].
-   *
-   * NOTE:  The latter mode is only available if CONFIG_SYSTEM_NSH=m.
-   * In that case, this main() function will be built as a process.  The
-   * process will be started with a command by the implementations of the
-   * system() and popen() interfaces.
-   */
-
-#ifdef HAVE_NSH_COMMAND
-  if (argc > 1)
-    {
-      return nsh_system(argc, argv);
-    }
-  else
-#endif
-    {
-      return nsh_task();
-    }
-}
diff --git a/system/nsh/sh_main.c b/system/nsh/sh_main.c
new file mode 100644
index 0000000..345097d
--- /dev/null
+++ b/system/nsh/sh_main.c
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * system/nsh/sh_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include "nshlib/nshlib.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sh_main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  /* There are two modes that NSH can be executed in:
+   *
+   * 1) As a normal, interactive shell.  In this case, no arguments are
+   *    expected on the command line.  OR
+   * 2) As a single command processor.  In this case, the single command is
+   *    is provided in argv[1].
+   *
+   * NOTE:  The latter mode is only available if CONFIG_SYSTEM_NSH=m.
+   * In that case, this main() function will be built as a process.  The
+   * process will be started with a command by the implementations of the
+   * system() and popen() interfaces.
+   */
+
+  return nsh_system(argc, argv);
+}
diff --git a/system/popen/Kconfig b/system/popen/Kconfig
index 9c7527b..14a245f 100644
--- a/system/popen/Kconfig
+++ b/system/popen/Kconfig
@@ -17,7 +17,7 @@ if SYSTEM_POPEN
 
 config SYSTEM_POPEN_SHPATH
 	string "Path to shell command"
-	default "/bin/nsh"
+	default "/bin/sh"
 	depends on SYSTEM_NSH=m
 	---help---
 		This is the full path to the program in a mounted file system that
diff --git a/system/system/Kconfig b/system/system/Kconfig
index 36be798..60af654 100644
--- a/system/system/Kconfig
+++ b/system/system/Kconfig
@@ -16,7 +16,7 @@ if SYSTEM_SYSTEM
 
 config SYSTEM_SYSTEM_SHPATH
 	string "Path to shell command"
-	default "/bin/nsh"
+	default "/bin/sh"
 	depends on SYSTEM_NSH=m
 	---help---
 		This is the full path to the program in a mounted file system that


[incubator-nuttx-apps] 05/09: nshlib: Add login argument to nsh_session for controling the login process

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 9ab5e2ff450314c743e416f914d084d52bb9fd8a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Apr 18 23:53:32 2020 +0800

    nshlib: Add login argument to nsh_session for controling the login process
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh.h             |  2 +-
 nshlib/nsh_altconsole.c  |  2 +-
 nshlib/nsh_consolemain.c |  2 +-
 nshlib/nsh_session.c     | 37 ++++++++++++++++++++-----------------
 nshlib/nsh_stdsession.c  | 31 +++++++++++++++++--------------
 nshlib/nsh_usbconsole.c  |  2 +-
 6 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index feed7bd..96623f3 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -860,7 +860,7 @@ int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl);
 /* Basic session and message handling */
 
 struct console_stdio_s;
-int nsh_session(FAR struct console_stdio_s *pstate);
+int nsh_session(FAR struct console_stdio_s *pstate, bool login);
 int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline);
 
 /****************************************************************************
diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index ed2fe82..b699634 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -317,7 +317,7 @@ int nsh_consolemain(int argc, char *argv[])
 
       /* Execute the session */
 
-      nsh_session(pstate);
+      nsh_session(pstate, true);
 
       /* We lost the connection.  Wait for the keyboard to
        * be re-connected.
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index e213c4c..84f8275 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -106,7 +106,7 @@ int nsh_consolemain(int argc, char *argv[])
 
   /* Execute the session */
 
-  ret = nsh_session(pstate);
+  ret = nsh_session(pstate, true);
 
   /* Exit upon return */
 
diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c
index 6b5ac55..00aadcd 100644
--- a/nshlib/nsh_session.c
+++ b/nshlib/nsh_session.c
@@ -79,7 +79,7 @@
  *
  ****************************************************************************/
 
-int nsh_session(FAR struct console_stdio_s *pstate)
+int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 {
   FAR struct nsh_vtbl_s *vtbl;
   int ret;
@@ -87,41 +87,44 @@ int nsh_session(FAR struct console_stdio_s *pstate)
   DEBUGASSERT(pstate);
   vtbl = &pstate->cn_vtbl;
 
+  if (login)
+    {
 #ifdef CONFIG_NSH_CONSOLE_LOGIN
-  /* Login User and Password Check */
+      /* Login User and Password Check */
 
-  if (nsh_login(pstate) != OK)
-    {
-      nsh_exit(vtbl, 1);
-      return -1; /* nsh_exit does not return */
-    }
+      if (nsh_login(pstate) != OK)
+        {
+          nsh_exit(vtbl, 1);
+          return -1; /* nsh_exit does not return */
+        }
 #endif /* CONFIG_NSH_CONSOLE_LOGIN */
 
-  /* Present a greeting and possibly a Message of the Day (MOTD) */
+      /* Present a greeting and possibly a Message of the Day (MOTD) */
 
-  fputs(g_nshgreeting, pstate->cn_outstream);
+      fputs(g_nshgreeting, pstate->cn_outstream);
 
 #ifdef CONFIG_NSH_MOTD
 #ifdef CONFIG_NSH_PLATFORM_MOTD
-  /* Output the platform message of the day */
+      /* Output the platform message of the day */
 
-  platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
-  fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
+      platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
+      fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
 
 #else
-  /* Output the fixed message of the day */
+      /* Output the fixed message of the day */
 
-  fprintf(pstate->cn_outstream, "%s\n", g_nshmotd);
+      fprintf(pstate->cn_outstream, "%s\n", g_nshmotd);
 #endif
 #endif
 
-  fflush(pstate->cn_outstream);
+      fflush(pstate->cn_outstream);
 
-  /* Execute the login script */
+      /* Execute the login script */
 
 #ifdef CONFIG_NSH_ROMFSRC
-  nsh_loginscript(vtbl);
+      nsh_loginscript(vtbl);
 #endif
+    }
 
   /* Then enter the command line parsing loop */
 
diff --git a/nshlib/nsh_stdsession.c b/nshlib/nsh_stdsession.c
index 64353d1..e5f1e03 100644
--- a/nshlib/nsh_stdsession.c
+++ b/nshlib/nsh_stdsession.c
@@ -76,7 +76,7 @@
  *
  ****************************************************************************/
 
-int nsh_session(FAR struct console_stdio_s *pstate)
+int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 {
   FAR struct nsh_vtbl_s *vtbl;
   int ret;
@@ -84,34 +84,37 @@ int nsh_session(FAR struct console_stdio_s *pstate)
   DEBUGASSERT(pstate);
   vtbl = &pstate->cn_vtbl;
 
+  if (login)
+    {
 #ifdef CONFIG_NSH_CONSOLE_LOGIN
-  /* Login User and Password Check */
+      /* Login User and Password Check */
 
-  if (nsh_stdlogin(pstate) != OK)
-    {
-      nsh_exit(vtbl, 1);
-      return -1; /* nsh_exit does not return */
-    }
+      if (nsh_stdlogin(pstate) != OK)
+        {
+          nsh_exit(vtbl, 1);
+          return -1; /* nsh_exit does not return */
+        }
 #endif /* CONFIG_NSH_CONSOLE_LOGIN */
 
-  /* Present a greeting and possibly a Message of the Day (MOTD) */
+      /* Present a greeting and possibly a Message of the Day (MOTD) */
 
-  printf("%s", g_nshgreeting);
+      printf("%s", g_nshgreeting);
 
 #ifdef CONFIG_NSH_MOTD
 # ifdef CONFIG_NSH_PLATFORM_MOTD
-  /* Output the platform message of the day */
+      /* Output the platform message of the day */
 
-  platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
-  printf("%s\n", vtbl->iobuffer);
+      platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
+      printf("%s\n", vtbl->iobuffer);
 
 # else
-  /* Output the fixed message of the day */
+      /* Output the fixed message of the day */
 
-  printf("%s\n", g_nshmotd);
+      printf("%s\n", g_nshmotd);
 
 # endif
 #endif
+    }
 
   /* Then enter the command line parsing loop */
 
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 60a8815..c60d965 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -339,7 +339,7 @@ int nsh_consolemain(int argc, char *argv[])
 
       /* Execute the session */
 
-      nsh_session(pstate);
+      nsh_session(pstate, true);
 
       /* Switch to /dev/null because we probably no longer have a
        * valid console device.