From 2dbd902a76f42952850b022dfdb7fcd81d37712e 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: Mon, 3 Nov 2025 23:20:23 +0200 Subject: [PATCH] SerialImp.c:RXTXPort(open) - avoid noop fcntl() and pointless assignments The file is already opened with O_RDWR | O_NOCTTY | O_NONBLOCK. * O_RDWR cannot be changed on linux with F_SETFL - https://man7.org/linux/man-pages/man2/F_GETFL.2const.html * The last page lists explicitly what can be changed by F_SETFL and O_NOCTTY is not mentioned. * O_NONBLOCK is already set when opening the file * FD_CLOEXEC is supposed to be set with F_SETFD - https://man7.org/linux/man-pages/man2/F_SETFD.2const.html * remove pointless assignments --- src/main/c/src/SerialImp.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/c/src/SerialImp.c b/src/main/c/src/SerialImp.c index 3b7c5e25..a9c862bf 100644 --- a/src/main/c/src/SerialImp.c +++ b/src/main/c/src/SerialImp.c @@ -713,17 +713,12 @@ JNIEXPORT jint JNICALL RXTXPort(open)( See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details. */ #if defined(__linux__) - int ret; //report_error("\nnative open(): Setting ownership flags"); - ret= fcntl(fd,F_SETOWN,getpid()); + fcntl(fd,F_SETOWN,getpid()); //report_error( strerror(errno) ); //report_error("\nnativec(): Forcing unlock flags"); - ret = fcntl(fd,F_UNLCK); - //report_error( strerror(errno) ); - - //report_error("\nnative open(): Setting read/write flags"); - ret= fcntl(fd,F_SETFL,O_CLOEXEC|O_RDWR|O_NONBLOCK); + fcntl(fd,F_UNLCK); //report_error( strerror(errno) ); #endif if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))