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

xiaoxiang 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 0c3ee06  nshlib: Fix nsh_usbconsole.c
0c3ee06 is described below

commit 0c3ee06fb3dbfd659dae96cb6578f351d6fb025e
Author: Masayuki Ishikawa <masayuki.ishik...@gmail.com>
AuthorDate: Mon Dec 14 14:39:23 2020 +0900

    nshlib: Fix nsh_usbconsole.c
    
    Summary:
    - stdin/stdout/stderr are now preallocated in libc and fs_fd
      in file_struct are also initialized to -1
    - So we need to call fdopen() for stdin again as we did before.
    - Also, cn_outstream and cn_errstream are not needed to be set.
    - See apps/nshlib/nsh_console.h as well
    
    Impact:
    - nsh_usbconsole.c only
    
    Testing:
    - Tested with stm32f4discovery:usbnsh
    
    Signed-off-by: SUZUKI Keiji <zuki.ebe...@gmail.com>
    Signed-off-by: Masayuki Ishikawa <masayuki.ishik...@jp.sony.com>
---
 nshlib/nsh_usbconsole.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 28f63bc..ee38e6d 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -75,7 +75,7 @@
  *
  ****************************************************************************/
 
-static void nsh_configstdio(int fd, FAR struct console_stdio_s *pstate)
+static void nsh_configstdio(int fd)
 {
   /* Make sure the stdout, and stderr are flushed */
 
@@ -88,15 +88,16 @@ static void nsh_configstdio(int fd, FAR struct 
console_stdio_s *pstate)
   dup2(fd, 1);
   dup2(fd, 2);
 
-  /* Setup the stdout */
-
-  pstate->cn_outfd     = 1;
-  pstate->cn_outstream = fdopen(1, "a");
-
-  /* Setup the stderr */
+  /* fdopen to get the stdin, stdout and stderr streams.
+   *
+   * fd = 0 is stdin  (read-only)
+   * fd = 1 is stdout (write-only, append)
+   * fd = 2 is stderr (write-only, append)
+   */
 
-  pstate->cn_errfd     = 2;
-  pstate->cn_errstream = fdopen(2, "a");
+  fdopen(0, "r");
+  fdopen(1, "a");
+  fdopen(2, "a");
 }
 
 /****************************************************************************
@@ -107,7 +108,7 @@ static void nsh_configstdio(int fd, FAR struct 
console_stdio_s *pstate)
  *
  ****************************************************************************/
 
-static int nsh_nullstdio(FAR struct console_stdio_s *pstate)
+static int nsh_nullstdio(void)
 {
   int fd;
 
@@ -118,7 +119,7 @@ static int nsh_nullstdio(FAR struct console_stdio_s *pstate)
     {
       /* Configure standard I/O to use /dev/null */
 
-      nsh_configstdio(fd, pstate);
+      nsh_configstdio(fd);
 
       /* We can close the original file descriptor now (unless it was one of
        * 0-2)
@@ -224,7 +225,7 @@ restart:
 
   /* Configure standard I/O */
 
-  nsh_configstdio(fd, pstate);
+  nsh_configstdio(fd);
 
   /* We can close the original file descriptor (unless it was one of 0-2) */
 
@@ -306,7 +307,7 @@ int nsh_consolemain(int argc, FAR char *argv[])
   /* Configure to use /dev/null if we do not have a valid console. */
 
 #ifndef CONFIG_DEV_CONSOLE
-  nsh_nullstdio(pstate);
+  nsh_nullstdio();
 #endif
 
   /* Execute the one-time start-up script (output may go to /dev/null) */
@@ -347,7 +348,7 @@ int nsh_consolemain(int argc, FAR char *argv[])
        * valid console device.
        */
 
-      nsh_nullstdio(pstate);
+      nsh_nullstdio();
     }
 }
 

Reply via email to