This is an automated email from the ASF dual-hosted git repository. masayuki pushed a commit to branch releases/10.0 in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 8e7b4d2bea60d4bb0d1c023e45d36d26466bc08d Author: Masayuki Ishikawa <[email protected]> AuthorDate: Thu Oct 29 16:23:53 2020 +0900 nshlib: Fix nsh_configstdio() in nsh_usbconsole.c Summary: - This commit fixes nsh_configstdio() to setup stdout and stderr Impact: - Affect nsh_usbconsole only Testing: - Tested with stm32f4discovery:usbnsh Signed-off-by: Masayuki Ishikawa <[email protected]> --- nshlib/nsh_usbconsole.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c index c323f28..28f63bc 100644 --- a/nshlib/nsh_usbconsole.c +++ b/nshlib/nsh_usbconsole.c @@ -75,7 +75,7 @@ * ****************************************************************************/ -static void nsh_configstdio(int fd) +static void nsh_configstdio(int fd, FAR struct console_stdio_s *pstate) { /* Make sure the stdout, and stderr are flushed */ @@ -87,6 +87,16 @@ static void nsh_configstdio(int fd) dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); + + /* Setup the stdout */ + + pstate->cn_outfd = 1; + pstate->cn_outstream = fdopen(1, "a"); + + /* Setup the stderr */ + + pstate->cn_errfd = 2; + pstate->cn_errstream = fdopen(2, "a"); } /**************************************************************************** @@ -97,7 +107,7 @@ static void nsh_configstdio(int fd) * ****************************************************************************/ -static int nsh_nullstdio(void) +static int nsh_nullstdio(FAR struct console_stdio_s *pstate) { int fd; @@ -108,7 +118,7 @@ static int nsh_nullstdio(void) { /* Configure standard I/O to use /dev/null */ - nsh_configstdio(fd); + nsh_configstdio(fd, pstate); /* We can close the original file descriptor now (unless it was one of * 0-2) @@ -133,7 +143,7 @@ static int nsh_nullstdio(void) * ****************************************************************************/ -static int nsh_waitusbready(void) +static int nsh_waitusbready(FAR struct console_stdio_s *pstate) { char inch; ssize_t nbytes; @@ -214,7 +224,7 @@ restart: /* Configure standard I/O */ - nsh_configstdio(fd); + nsh_configstdio(fd, pstate); /* We can close the original file descriptor (unless it was one of 0-2) */ @@ -296,7 +306,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(); + nsh_nullstdio(pstate); #endif /* Execute the one-time start-up script (output may go to /dev/null) */ @@ -325,7 +335,7 @@ int nsh_consolemain(int argc, FAR char *argv[]) * standard I/O to the USB serial device. */ - ret = nsh_waitusbready(); + ret = nsh_waitusbready(pstate); UNUSED(ret); /* Eliminate warning if not used */ DEBUGASSERT(ret == OK); @@ -337,7 +347,7 @@ int nsh_consolemain(int argc, FAR char *argv[]) * valid console device. */ - nsh_nullstdio(); + nsh_nullstdio(pstate); } }
