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
*
****************************************************************************/
-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);
}
}
