You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2021/07/02 16:09:38 UTC

[incubator-nuttx-apps] branch master updated: apps: add variable to identify main shell

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

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


The following commit(s) were added to refs/heads/master by this push:
     new faa2438  apps: add variable to identify main shell
faa2438 is described below

commit faa243844d938010f810d8c67002bd849e0dc26b
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Jun 17 22:59:42 2021 +0800

    apps: add variable to identify main shell
    
    Change-Id: Ifecfbb58b3c2cdbeae900eb2eeb2b641155a7580
    Signed-off-by: ligd <li...@xiaomi.com>
---
 nshlib/nsh_altconsole.c  |  2 +-
 nshlib/nsh_builtin.c     | 16 ++++++++++------
 nshlib/nsh_console.c     |  5 +++--
 nshlib/nsh_console.h     |  6 +++++-
 nshlib/nsh_consolemain.c |  2 +-
 nshlib/nsh_fileapps.c    | 17 +++++++++++------
 nshlib/nsh_system.c      |  2 +-
 nshlib/nsh_telnetd.c     |  2 +-
 nshlib/nsh_usbconsole.c  |  2 +-
 9 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index a841812..f003f42 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -245,7 +245,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
 
 int nsh_consolemain(int argc, FAR char *argv[])
 {
-  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct console_stdio_s *pstate = nsh_newconsole(true);
   FAR const char *msg;
   int ret;
 
diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c
index b3f4668..f5337f7 100644
--- a/nshlib/nsh_builtin.c
+++ b/nshlib/nsh_builtin.c
@@ -130,13 +130,14 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 #  endif /* CONFIG_NSH_DISABLEBG */
         {
           int rc = 0;
+          int tc = 0;
 
-          /* Setup up to receive SIGINT if control-C entered.  The return
-           * value is ignored because this console device may not support
-           * SIGINT.
-           */
+          if (vtbl->isctty)
+            {
+              /* Setup up to receive SIGINT if control-C entered. */
 
-          ioctl(stdout->fs_fd, TIOCSCTTY, ret);
+              tc = ioctl(stdout->fs_fd, TIOCSCTTY, ret);
+            }
 
           /* Wait for the application to exit.  We did lock the scheduler
            * above, but that does not guarantee that the application did not
@@ -198,7 +199,10 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
                */
             }
 
-          ioctl(stdout->fs_fd, TIOCSCTTY, -1);
+          if (vtbl->isctty && tc == 0)
+            {
+              ioctl(stdout->fs_fd, TIOCNOTTY);
+            }
         }
 #  ifndef CONFIG_NSH_DISABLEBG
       else
diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c
index bf613a1..3ee7241 100644
--- a/nshlib/nsh_console.c
+++ b/nshlib/nsh_console.c
@@ -274,7 +274,7 @@ static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl)
 #ifndef CONFIG_NSH_DISABLEBG
 static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl)
 {
-  FAR struct console_stdio_s *pclone = nsh_newconsole();
+  FAR struct console_stdio_s *pclone = nsh_newconsole(vtbl->isctty);
   return &pclone->cn_vtbl;
 }
 #endif
@@ -436,7 +436,7 @@ static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus)
  * Name: nsh_newconsole
  ****************************************************************************/
 
-FAR struct console_stdio_s *nsh_newconsole(void)
+FAR struct console_stdio_s *nsh_newconsole(bool isctty)
 {
   FAR struct console_stdio_s *pstate =
     (FAR struct console_stdio_s *)zalloc(sizeof(struct console_stdio_s));
@@ -454,6 +454,7 @@ FAR struct console_stdio_s *nsh_newconsole(void)
       pstate->cn_vtbl.error       = nsh_erroroutput;
       pstate->cn_vtbl.linebuffer  = nsh_consolelinebuffer;
       pstate->cn_vtbl.exit        = nsh_consoleexit;
+      pstate->cn_vtbl.isctty      = isctty;
 
 #ifndef CONFIG_NSH_DISABLESCRIPT
       /* Set the initial option flags */
diff --git a/nshlib/nsh_console.h b/nshlib/nsh_console.h
index 1febbc9..95fdbbf 100644
--- a/nshlib/nsh_console.h
+++ b/nshlib/nsh_console.h
@@ -128,6 +128,10 @@ struct nsh_vtbl_s
   /* Parser state data */
 
   struct nsh_parser_s np;
+
+  /* Ctrl tty or not */
+
+  bool isctty;
 };
 
 /* This structure describes a console front-end that is based on stdin and
@@ -177,6 +181,6 @@ struct console_stdio_s
 
 /* Defined in nsh_console.c *************************************************/
 
-FAR struct console_stdio_s *nsh_newconsole(void);
+FAR struct console_stdio_s *nsh_newconsole(bool isctty);
 
 #endif /* __APPS_NSHLIB_NSH_CONSOLE_H */
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index bfcdb5e..63e655b 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -66,7 +66,7 @@
 
 int nsh_consolemain(int argc, FAR char *argv[])
 {
-  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct console_stdio_s *pstate = nsh_newconsole(true);
   int ret;
 
   DEBUGASSERT(pstate != NULL);
diff --git a/nshlib/nsh_fileapps.c b/nshlib/nsh_fileapps.c
index 3fc48c1..7e3f94e 100644
--- a/nshlib/nsh_fileapps.c
+++ b/nshlib/nsh_fileapps.c
@@ -155,12 +155,14 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
       if (vtbl->np.np_bg == false)
 #  endif /* CONFIG_NSH_DISABLEBG */
         {
-          /* Setup up to receive SIGINT if control-C entered.  The return
-           * value is ignored because this console device may not support
-           * SIGINT.
-           */
+          int tc = 0;
+
+          if (vtbl->isctty)
+            {
+              /* Setup up to receive SIGINT if control-C entered. */
 
-          ioctl(stdout->fs_fd, TIOCSCTTY, pid);
+              tc = ioctl(stdout->fs_fd, TIOCSCTTY, pid);
+            }
 
           /* Wait for the application to exit.  We did lock the scheduler
            * above, but that does not guarantee that the application did not
@@ -213,7 +215,10 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
                */
             }
 
-          ioctl(stdout->fs_fd, TIOCSCTTY, -1);
+          if (vtbl->isctty && tc == 0)
+            {
+              ioctl(stdout->fs_fd, TIOCNOTTY);
+            }
         }
 #  ifndef CONFIG_NSH_DISABLEBG
       else
diff --git a/nshlib/nsh_system.c b/nshlib/nsh_system.c
index 31717b0..4804268 100644
--- a/nshlib/nsh_system.c
+++ b/nshlib/nsh_system.c
@@ -57,7 +57,7 @@
 
 int nsh_system(int argc, FAR char *argv[])
 {
-  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct console_stdio_s *pstate = nsh_newconsole(false);
   int ret;
 
   DEBUGASSERT(pstate != NULL);
diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c
index 4a03564..76ba97b 100644
--- a/nshlib/nsh_telnetd.c
+++ b/nshlib/nsh_telnetd.c
@@ -68,7 +68,7 @@ enum telnetd_state_e
 
 static int nsh_telnetmain(int argc, char *argv[])
 {
-  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct console_stdio_s *pstate = nsh_newconsole(true);
   FAR struct nsh_vtbl_s *vtbl;
   int ret;
 
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index c7fdb36..c538f0d 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -241,7 +241,7 @@ restart:
 
 int nsh_consolemain(int argc, FAR char *argv[])
 {
-  FAR struct console_stdio_s *pstate = nsh_newconsole();
+  FAR struct console_stdio_s *pstate = nsh_newconsole(true);
   struct boardioc_usbdev_ctrl_s ctrl;
   FAR void *handle;
   int ret;