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

[nuttx-apps] branch master updated (9246502ac -> 359f66ad3)

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

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


    from 9246502ac drivertest/drivertest_uart: uart driver testcase
     new 80feb2432 nshlib: Shouldn't set TIOCSCTTY with STDOUT_FILENO directly
     new 359f66ad3 nshlib: Remove the remaining CONFIG_FILE_STREAM dependence

The 2 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:
 nshlib/nsh.h             | 12 ++----------
 nshlib/nsh_altconsole.c  |  4 +---
 nshlib/nsh_builtin.c     |  5 +++--
 nshlib/nsh_codeccmd.c    |  1 -
 nshlib/nsh_command.c     |  8 ++------
 nshlib/nsh_console.c     | 34 +++++++++++++++++++++++++++-------
 nshlib/nsh_console.h     |  5 +++--
 nshlib/nsh_consolemain.c |  3 ---
 nshlib/nsh_dbgcmds.c     |  1 +
 nshlib/nsh_ddcmd.c       |  2 ++
 nshlib/nsh_envcmds.c     |  1 -
 nshlib/nsh_fileapps.c    |  4 ++--
 nshlib/nsh_fscmds.c      |  4 +---
 nshlib/nsh_fsutils.c     |  1 +
 nshlib/nsh_login.c       |  1 -
 nshlib/nsh_mmcmds.c      |  2 ++
 nshlib/nsh_modcmds.c     | 17 +++++++++--------
 nshlib/nsh_parse.c       |  5 ++++-
 nshlib/nsh_printf.c      |  1 -
 nshlib/nsh_script.c      |  6 +++---
 nshlib/nsh_system.c      |  1 -
 nshlib/nsh_telnetlogin.c |  1 -
 nshlib/nsh_usbconsole.c  |  6 ------
 nshlib/nsh_usbtrace.c    |  2 +-
 24 files changed, 64 insertions(+), 63 deletions(-)


[nuttx-apps] 02/02: nshlib: Remove the remaining CONFIG_FILE_STREAM dependence

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

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

commit 359f66ad3701c8a53b6344fe49a2d8d01e9c7f97
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Feb 22 06:08:13 2023 +0800

    nshlib: Remove the remaining CONFIG_FILE_STREAM dependence
    
    continue the change from https://github.com/apache/nuttx-apps/pull/1559
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh.h             | 12 ++----------
 nshlib/nsh_altconsole.c  |  4 +---
 nshlib/nsh_builtin.c     |  1 +
 nshlib/nsh_codeccmd.c    |  1 -
 nshlib/nsh_command.c     |  8 ++------
 nshlib/nsh_console.c     |  3 ++-
 nshlib/nsh_console.h     |  3 +--
 nshlib/nsh_consolemain.c |  3 ---
 nshlib/nsh_dbgcmds.c     |  1 +
 nshlib/nsh_ddcmd.c       |  2 ++
 nshlib/nsh_envcmds.c     |  1 -
 nshlib/nsh_fscmds.c      |  4 +---
 nshlib/nsh_fsutils.c     |  1 +
 nshlib/nsh_login.c       |  1 -
 nshlib/nsh_mmcmds.c      |  2 ++
 nshlib/nsh_modcmds.c     | 17 +++++++++--------
 nshlib/nsh_parse.c       |  5 ++++-
 nshlib/nsh_printf.c      |  1 -
 nshlib/nsh_script.c      |  6 +++---
 nshlib/nsh_system.c      |  1 -
 nshlib/nsh_telnetlogin.c |  1 -
 nshlib/nsh_usbconsole.c  |  6 ------
 nshlib/nsh_usbtrace.c    |  2 +-
 23 files changed, 33 insertions(+), 53 deletions(-)

diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 0ccd5992b..50205c8cc 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 
-#include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <unistd.h>
@@ -55,11 +54,6 @@
 #  endif
 #endif
 
-#ifndef CONFIG_FILE_STREAM
-#  undef CONFIG_NSH_FILE_APPS
-#  undef CONFIG_NSH_CMDPARMS
-#endif
-
 /* rmdir, mkdir, rm, and mv are only available if mountpoints are enabled
  * AND there is a writeable file system OR if these operations on the
  * pseudo-filesystem are not disabled.
@@ -988,11 +982,9 @@ int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
 #if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
   int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
 #endif
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-#  ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
-#  endif
-#endif /* CONFIG_FILE_STREAM && !CONFIG_NSH_DISABLESCRIPT */
+#endif
 
 #ifdef NSH_HAVE_DIROPTS
 #  ifndef CONFIG_NSH_DISABLE_MKDIR
diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index 82f284fda..831725f4f 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -150,8 +149,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
                * to open the keyboard device.
                */
 
-              puts(msg);
-              fflush(stdout);
+              write(STDOUT_FILENO, msg, strlen(msg));
               msg = NULL;
             }
 
diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c
index 2e2c6d10f..583df84e3 100644
--- a/nshlib/nsh_builtin.c
+++ b/nshlib/nsh_builtin.c
@@ -31,6 +31,7 @@
 
 #include <stdbool.h>
 #include <errno.h>
+#include <sched.h>
 #include <string.h>
 
 #include <nuttx/lib/builtin.h>
diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index 6eb4d026d..9b3efdcce 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -28,7 +28,6 @@
 #include <sys/stat.h>
 #include <stdint.h>
 #include <stdbool.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index efd3a366b..f3a7af0f5 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -87,10 +87,8 @@ static int  cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc,
 
 static const struct cmdmap_s g_cmdmap[] =
 {
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-# ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   { ".",        cmd_source,   2, 2, "<script-path>" },
-# endif
 #endif
 
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
@@ -515,10 +513,8 @@ static const struct cmdmap_s g_cmdmap[] =
   { "sleep",    cmd_sleep,    2, 2, "<sec>" },
 #endif
 
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-# ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   { "source",   cmd_source,   2, 2, "<script-path>" },
-# endif
 #endif
 
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c
index 6494992b8..7d29749b1 100644
--- a/nshlib/nsh_console.c
+++ b/nshlib/nsh_console.c
@@ -24,6 +24,7 @@
 
 #include <nuttx/config.h>
 
+#include <sys/ioctl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -70,7 +71,7 @@ static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
 static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl,
                                 FAR uint8_t *save);
 static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl,
-                            int exitstatus) anoreturn_function;
+                            int exitstatus) noreturn_function;
 
 /****************************************************************************
  * Private Functions
diff --git a/nshlib/nsh_console.h b/nshlib/nsh_console.h
index 4b0037b2c..cf5e75a89 100644
--- a/nshlib/nsh_console.h
+++ b/nshlib/nsh_console.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 
-#include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <errno.h>
@@ -61,7 +60,7 @@
  * See struct serialsave_s in nsh_console.c
  */
 
-#define SAVE_SIZE (2 * sizeof(int) + 2 * sizeof(FILE*))
+#define SAVE_SIZE (2 * sizeof(int))
 
 /* Are we using the NuttX console for I/O?  Or some other character device? */
 
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 29e138bf6..8590d0284 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -24,11 +24,8 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <assert.h>
 
-#include <sys/boardctl.h>
-
 #include "nsh.h"
 #include "nsh_console.h"
 
diff --git a/nshlib/nsh_dbgcmds.c b/nshlib/nsh_dbgcmds.c
index 85a6718ee..fc2b587a7 100644
--- a/nshlib/nsh_dbgcmds.c
+++ b/nshlib/nsh_dbgcmds.c
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
diff --git a/nshlib/nsh_ddcmd.c b/nshlib/nsh_ddcmd.c
index f9ac66901..dea661408 100644
--- a/nshlib/nsh_ddcmd.c
+++ b/nshlib/nsh_ddcmd.c
@@ -24,6 +24,8 @@
 
 #include <nuttx/config.h>
 
+#include <nuttx/clock.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
diff --git a/nshlib/nsh_envcmds.c b/nshlib/nsh_envcmds.c
index 5c0f347af..37b64f165 100644
--- a/nshlib/nsh_envcmds.c
+++ b/nshlib/nsh_envcmds.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index c13d829bd..d8c4fbe4d 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -1976,8 +1976,7 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
  * Name: cmd_source
  ****************************************************************************/
 
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-#ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
 int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
   UNUSED(argc);
@@ -1985,7 +1984,6 @@ int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
   return nsh_script(vtbl, argv[0], argv[1], true);
 }
 #endif
-#endif
 
 /****************************************************************************
  * Name: cmd_cmp
diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c
index 9d48c79bd..7a279b561 100644
--- a/nshlib/nsh_fsutils.c
+++ b/nshlib/nsh_fsutils.c
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c
index 19be58ae5..82857c406 100644
--- a/nshlib/nsh_login.c
+++ b/nshlib/nsh_login.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
diff --git a/nshlib/nsh_mmcmds.c b/nshlib/nsh_mmcmds.c
index 746054236..8f5953a99 100644
--- a/nshlib/nsh_mmcmds.c
+++ b/nshlib/nsh_mmcmds.c
@@ -24,6 +24,8 @@
 
 #include <nuttx/config.h>
 
+#include <string.h>
+
 #include "nsh.h"
 #include "nsh_console.h"
 
diff --git a/nshlib/nsh_modcmds.c b/nshlib/nsh_modcmds.c
index 549c384c8..6b935e877 100644
--- a/nshlib/nsh_modcmds.c
+++ b/nshlib/nsh_modcmds.c
@@ -24,10 +24,11 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
+#include <fcntl.h>
 #include <string.h>
 
 #include <nuttx/module.h>
+#include <system/readline.h>
 
 #include "nsh.h"
 #include "nsh_console.h"
@@ -103,18 +104,18 @@ int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
 int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
-  UNUSED(argc);
+  int fd;
 
-  FILE *stream;
+  UNUSED(argc);
 
   /* Usage: lsmod */
 
   /* Open /proc/modules */
 
-  stream = fopen("/proc/modules", "r");
-  if (stream == NULL)
+  fd = open("/proc/modules", O_RDONLY);
+  if (fd < 0)
     {
-      nsh_error(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
+      nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
       return ERROR;
     }
 
@@ -126,7 +127,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 
   /* Read each line from the procfs "file" */
 
-  while (fgets(vtbl->iobuffer, IOBUFFERSIZE, stream) != NULL)
+  while (readline_fd(vtbl->iobuffer, IOBUFFERSIZE, fd, -1) >= 0)
     {
       FAR char *modulename;
       FAR char *initializer;
@@ -175,7 +176,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
                  datasize      ? datasize      : "");
     }
 
-  fclose(stream);
+  close(fd);
   return OK;
 }
 #endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_MODULE */
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index 169561e4c..0aabe5dbf 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -24,11 +24,14 @@
 
 #include <nuttx/config.h>
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
 #include <debug.h>
+#include <pthread.h>
+#include <sched.h>
 #include <unistd.h>
 
 #ifdef CONFIG_NSH_CMDPARMS
@@ -1958,7 +1961,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
                           SEEK_SET);
               if (ret < 0)
                 {
-                  nsh_error(vtbl, g_fmtcmdfailed, "done", "fseek",
+                  nsh_error(vtbl, g_fmtcmdfailed, "done", "lseek",
                             NSH_ERRNO);
                 }
 
diff --git a/nshlib/nsh_printf.c b/nshlib/nsh_printf.c
index c57893c8c..bb088e764 100644
--- a/nshlib/nsh_printf.c
+++ b/nshlib/nsh_printf.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index 99e61a60b..9acf681f3 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -115,7 +115,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
         {
           if (log)
             {
-              nsh_error(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
+              nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
             }
 
           /* Free the allocated path */
@@ -138,7 +138,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
           /* Get the current file position.  This is used to control
            * looping.  If a loop begins in the next line, then this file
            * offset will be needed to locate the top of the loop in the
-           * script file.  Note that ftell will return -1 on failure.
+           * script file.  Note that lseek will return -1 on failure.
            */
 
           vtbl->np.np_foffs = lseek(vtbl->np.np_fd, 0, SEEK_CUR);
@@ -146,7 +146,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
 
           if (vtbl->np.np_foffs < 0 && log)
             {
-              nsh_error(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
+              nsh_error(vtbl, g_fmtcmdfailed, "loop", "lseek", NSH_ERRNO);
             }
 #endif
 
diff --git a/nshlib/nsh_system.c b/nshlib/nsh_system.c
index 7603dfc94..26aaecbd2 100644
--- a/nshlib/nsh_system.c
+++ b/nshlib/nsh_system.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
diff --git a/nshlib/nsh_telnetlogin.c b/nshlib/nsh_telnetlogin.c
index 6592403b6..c2ec13a53 100644
--- a/nshlib/nsh_telnetlogin.c
+++ b/nshlib/nsh_telnetlogin.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 04233a990..bc95c7d9a 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -26,7 +26,6 @@
 
 #include <sys/boardctl.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -62,11 +61,6 @@
 
 static void nsh_configstdio(int fd)
 {
-  /* Make sure the stdout, and stderr are flushed */
-
-  fflush(stdout);
-  fflush(stderr);
-
   /* Dup the fd to create standard fd 0-2 */
 
   dup2(fd, 0);
diff --git a/nshlib/nsh_usbtrace.c b/nshlib/nsh_usbtrace.c
index c00d2c90a..3faaae348 100644
--- a/nshlib/nsh_usbtrace.c
+++ b/nshlib/nsh_usbtrace.c
@@ -24,7 +24,7 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
+#include <stdarg.h>
 #include <debug.h>
 
 #include <nuttx/usb/usbdev_trace.h>


[nuttx-apps] 01/02: nshlib: Shouldn't set TIOCSCTTY with STDOUT_FILENO directly

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

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

commit 80feb2432d9dfea262ea8a4fb3b9942bb384d44b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Feb 22 13:13:45 2023 +0800

    nshlib: Shouldn't set TIOCSCTTY with STDOUT_FILENO directly
    
    to handle the shell redirection correctly
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_builtin.c  |  4 ++--
 nshlib/nsh_console.c  | 33 ++++++++++++++++++++++++++-------
 nshlib/nsh_console.h  |  2 ++
 nshlib/nsh_fileapps.c |  4 ++--
 4 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c
index 877af0fc1..2e2c6d10f 100644
--- a/nshlib/nsh_builtin.c
+++ b/nshlib/nsh_builtin.c
@@ -136,7 +136,7 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
             {
               /* Setup up to receive SIGINT if control-C entered. */
 
-              tc = ioctl(STDOUT_FILENO, TIOCSCTTY, ret);
+              tc = nsh_ioctl(vtbl, TIOCSCTTY, ret);
             }
 
           /* Wait for the application to exit.  We did lock the scheduler
@@ -201,7 +201,7 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 
           if (vtbl->isctty && tc == 0)
             {
-              ioctl(STDOUT_FILENO, TIOCNOTTY);
+              nsh_ioctl(vtbl, TIOCNOTTY, 0);
             }
         }
 #  ifndef CONFIG_NSH_DISABLEBG
diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c
index e12a88c80..6494992b8 100644
--- a/nshlib/nsh_console.c
+++ b/nshlib/nsh_console.c
@@ -57,18 +57,20 @@ static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl);
 #endif
 static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
 static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
-  FAR const void *buffer, size_t nbytes);
+                                FAR const void *buffer, size_t nbytes);
+static int nsh_consoleioctl(FAR struct nsh_vtbl_s *vtbl,
+                            int cmd, unsigned long arg);
 static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
-  FAR const char *fmt, ...) printf_like(2, 3);
+                             FAR const char *fmt, ...) printf_like(2, 3);
 static int nsh_erroroutput(FAR struct nsh_vtbl_s *vtbl,
-  FAR const char *fmt, ...) printf_like(2, 3);
+                           FAR const char *fmt, ...) printf_like(2, 3);
 static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
 static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
-  FAR uint8_t *save);
+                                FAR uint8_t *save);
 static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl,
-  FAR uint8_t *save);
-static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus)
-  noreturn_function;
+                                FAR uint8_t *save);
+static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl,
+                            int exitstatus) anoreturn_function;
 
 /****************************************************************************
  * Private Functions
@@ -127,6 +129,22 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
   return ret;
 }
 
+/****************************************************************************
+ * Name: nsh_consolewrite
+ *
+ * Description:
+ *   Issue ioctl to the currently selected stream.
+ *
+ ****************************************************************************/
+
+static int nsh_consoleioctl(FAR struct nsh_vtbl_s *vtbl,
+                            int cmd, unsigned long arg)
+{
+  FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
+
+  return ioctl(OUTFD(pstate), cmd, arg);
+}
+
 /****************************************************************************
  * Name: nsh_consoleoutput
  *
@@ -347,6 +365,7 @@ FAR struct console_stdio_s *nsh_newconsole(bool isctty)
 #endif
       pstate->cn_vtbl.release     = nsh_consolerelease;
       pstate->cn_vtbl.write       = nsh_consolewrite;
+      pstate->cn_vtbl.ioctl       = nsh_consoleioctl;
       pstate->cn_vtbl.output      = nsh_consoleoutput;
       pstate->cn_vtbl.error       = nsh_erroroutput;
       pstate->cn_vtbl.linebuffer  = nsh_consolelinebuffer;
diff --git a/nshlib/nsh_console.h b/nshlib/nsh_console.h
index 249480bae..4b0037b2c 100644
--- a/nshlib/nsh_console.h
+++ b/nshlib/nsh_console.h
@@ -43,6 +43,7 @@
 #define nsh_clone(v)           (v)->clone(v)
 #define nsh_release(v)         (v)->release(v)
 #define nsh_write(v,b,n)       (v)->write(v,b,n)
+#define nsh_ioctl(v,c,a)       (v)->ioctl(v,c,a)
 #define nsh_linebuffer(v)      (v)->linebuffer(v)
 #define nsh_redirect(v,f,s)    (v)->redirect(v,f,s)
 #define nsh_undirect(v,s)      (v)->undirect(v,s)
@@ -103,6 +104,7 @@ struct nsh_vtbl_s
   void (*release)(FAR struct nsh_vtbl_s *vtbl);
   ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer,
                    size_t nbytes);
+  int (*ioctl)(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg);
   int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
       printf_like(2, 3);
   int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
diff --git a/nshlib/nsh_fileapps.c b/nshlib/nsh_fileapps.c
index e017f6c6c..804c0062d 100644
--- a/nshlib/nsh_fileapps.c
+++ b/nshlib/nsh_fileapps.c
@@ -204,7 +204,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
             {
               /* Setup up to receive SIGINT if control-C entered. */
 
-              tc = ioctl(stdout->fs_fd, TIOCSCTTY, pid);
+              tc = nsh_ioctl(vtbl, TIOCSCTTY, pid);
             }
 
           /* Wait for the application to exit.  We did lock the scheduler
@@ -260,7 +260,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
 
           if (vtbl->isctty && tc == 0)
             {
-              ioctl(stdout->fs_fd, TIOCNOTTY);
+              nsh_ioctl(vtbl, TIOCNOTTY, 0);
             }
         }
 #  ifndef CONFIG_NSH_DISABLEBG