system/cu: Skip the terminal related stuff if dev isn't a tty

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-09-04 02:31:17 +08:00 committed by Alin Jerpelea
parent 3ff51d108b
commit b60cdf4927

View File

@ -131,10 +131,11 @@ static int set_termios(FAR struct cu_globals_s *cu, int rate,
static int set_termios(FAR struct cu_globals_s *cu, int nocrlf)
#endif
{
int rc = 0;
int ret;
struct termios tio;
if (isatty(cu->devfd))
{
tio = cu->devtio;
#ifdef CONFIG_SERIAL_TERMIOS
@ -154,7 +155,7 @@ static int set_termios(FAR struct cu_globals_s *cu, int nocrlf)
break;
}
/* set baudrate */
/* Set baudrate */
if (rate != 0)
{
@ -169,7 +170,7 @@ static int set_termios(FAR struct cu_globals_s *cu, int nocrlf)
tio.c_oflag = OPOST;
/* enable or disable \n -> \r\n conversion during write */
/* Enable or disable \n -> \r\n conversion during write */
if (nocrlf == 0)
{
@ -180,8 +181,8 @@ static int set_termios(FAR struct cu_globals_s *cu, int nocrlf)
if (ret)
{
cu_error("set_termios: ERROR during tcsetattr(): %d\n", errno);
rc = -1;
goto errout;
return ret;
}
}
/* Let the remote machine to handle all crlf/echo except Ctrl-C */
@ -197,19 +198,21 @@ static int set_termios(FAR struct cu_globals_s *cu, int nocrlf)
ret = tcsetattr(cu->stdfd, TCSANOW, &tio);
if (ret)
{
cu_error("set_termios: ERROR during tcsetattr(): %d\n",
errno);
rc = -1;
cu_error("set_termios: ERROR during tcsetattr(): %d\n", errno);
return ret;
}
}
errout:
return rc;
return 0;
}
static void retrieve_termios(FAR struct cu_globals_s *cu)
{
if (isatty(cu->devfd))
{
tcsetattr(cu->devfd, TCSANOW, &cu->devtio);
}
if (cu->stdfd >= 0)
{
tcsetattr(cu->stdfd, TCSANOW, &cu->stdtio);
@ -367,12 +370,15 @@ int main(int argc, FAR char *argv[])
/* Remember serial device termios attributes */
if (isatty(cu->devfd))
{
ret = tcgetattr(cu->devfd, &cu->devtio);
if (ret)
{
cu_error("cu_main: ERROR during tcgetattr(): %d\n", errno);
goto errout_with_devfd;
}
}
/* Remember std termios attributes if it is a tty. Try to select
* right descriptor that is used to refer to tty