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/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f3e3fe65 fix ECHO problem
5f3e3fe65 is described below

commit 5f3e3fe65582e43ea842f4169942d2bd6c5371a9
Author: zhanghu5 <[email protected]>
AuthorDate: Sun Oct 8 11:34:05 2023 +0800

    fix ECHO problem
    
    only when devfd and stdfd both are tty, we call tcsetattr
    
    Signed-off-by: zhanghu5 <[email protected]>
---
 system/cu/cu_main.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c
index 9b646195b..0997014cb 100644
--- a/system/cu/cu_main.c
+++ b/system/cu/cu_main.c
@@ -137,7 +137,7 @@ static int set_termios(FAR struct cu_globals_s *cu, int 
nocrlf)
   int ret;
   struct termios tio;
 
-  if (isatty(cu->devfd))
+  if (isatty(cu->devfd) && isatty(cu->stdfd))
     {
       tio = cu->devtio;
 
@@ -186,38 +186,31 @@ static int set_termios(FAR struct cu_globals_s *cu, int 
nocrlf)
           cu_error("set_termios: ERROR during tcsetattr(): %d\n", errno);
           return ret;
         }
-    }
 
-  /* Let the remote machine to handle all crlf/echo except Ctrl-C */
+      /* Let the remote machine to handle all crlf/echo except Ctrl-C */
 
-  if (cu->stdfd >= 0)
-  {
-    tio = cu->stdtio;
+      tio = cu->stdtio;
 
-    tio.c_iflag = 0;
-    tio.c_oflag = 0;
-    tio.c_lflag &= ~ECHO;
+      tio.c_iflag = 0;
+      tio.c_oflag = 0;
+      tio.c_lflag &= ~ECHO;
 
-    ret = tcsetattr(cu->stdfd, TCSANOW, &tio);
-    if (ret)
-      {
-        cu_error("set_termios: ERROR during tcsetattr(): %d\n", errno);
-        return ret;
-      }
-  }
+      ret = tcsetattr(cu->stdfd, TCSANOW, &tio);
+      if (ret)
+        {
+          cu_error("set_termios: ERROR during tcsetattr(): %d\n", errno);
+          return ret;
+        }
+    }
 
   return 0;
 }
 
 static void retrieve_termios(FAR struct cu_globals_s *cu)
 {
-  if (isatty(cu->devfd))
+  if (isatty(cu->devfd) && isatty(cu->stdfd))
     {
       tcsetattr(cu->devfd, TCSANOW, &cu->devtio);
-    }
-
-  if (cu->stdfd >= 0)
-    {
       tcsetattr(cu->stdfd, TCSANOW, &cu->stdtio);
     }
 }

Reply via email to