From aff84a257489e9171d9b502e4318e8b82c909ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Wed, 5 Nov 2025 18:54:33 +0200 Subject: [PATCH] SerialImp.c:RXTXCommDriver(testRead) - ignore tcgetattr() failures for hidraw device If tcgetattr(fd, &ttyset) fails and errno is EINVAL 22 Invalid Argument, or ENOTTY - https://en.wikipedia.org/wiki/Not_a_typewriter, then this is not a serial device and do not try to adjust its settings. First obtain the flags, so that these can be restored later. --- src/main/c/src/SerialImp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/c/src/SerialImp.c b/src/main/c/src/SerialImp.c index 3b7c5e25..5c690411 100644 --- a/src/main/c/src/SerialImp.c +++ b/src/main/c/src/SerialImp.c @@ -4458,11 +4458,6 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( int saved_flags; struct termios saved_termios; - if (tcgetattr(fd, &ttyset) < 0) { - ret = JNI_FALSE; - goto END; - } - /* save, restore later */ if ( ( saved_flags = fcntl(fd, F_GETFL ) ) < 0 ) { @@ -4471,6 +4466,12 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( goto END; } + if (tcgetattr(fd, &ttyset) < 0) { + if (errno == EINVAL || errno == ENOTTY) goto NOT_TERMINAL; + ret = JNI_FALSE; + goto END; + } + memcpy( &saved_termios, &ttyset, sizeof( struct termios ) ); if ( fcntl( fd, F_SETFL, O_NONBLOCK ) < 0 ) @@ -4490,7 +4491,7 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( tcsetattr( fd, TCSANOW, &saved_termios ); goto END; } - +NOT_TERMINAL: /* The following may mess up if both EAGAIN and EWOULDBLOCK