Skip to content

Commit 21975be

Browse files
author
root
committed
SerialImp.c:RXTXCommDriver(testRead) - fcntl(,F_SETFL, O_RDWR) does not work on Linux
NeuronRobotics#257 On linux F_SETFL cannot change O_RDONLY, O_WRONLY, O_RDWR - https://man7.org/linux/man-pages/man2/F_GETFL.2const.html. FD_CLOEXEC is supposed to be altered by F_SETFD, not by F_SETFL - https://man7.org/linux/man-pages/man2/f_setfd.2const.html and it is not a command by its own (second parameter of fctnl) but a parameter (third parameter). Actually the definitions in usr/include/bits/fcntl-linux.h are: fcntl-linux.h:#define FD_CLOEXEC 1 /* Actually anything with low bit set goes */ fcntl-linux.h:#define F_GETFD 1 /* Get file descriptor flags. */ so int cmd=FD_CLOEXEC|F_SETFL; ret= fcntl(fd,cmd,O_RDWR | O_NOCTTY | O_NONBLOCK); was doing ret= fcntl(fd, F_GETFD | F_SETFL ,O_RDWR | O_NOCTTY | O_NONBLOCK);
1 parent 9cc4e2e commit 21975be

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

src/main/c/src/SerialImp.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,18 +4422,13 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)(
44224422
//report_warning("\ntestRead(): Attempting to open: ");
44234423
//report_warning(name);
44244424
fd=localOpen ( name, O_RDONLY | O_NONBLOCK |O_NOCTTY);
4425-
int cmd=FD_CLOEXEC|F_SETFL;
44264425
//report_error("\ntestRead(): Setting ownership flags");
44274426
ret= fcntl(fd,F_SETOWN,getpid());
44284427
//report_error( strerror(errno) );
44294428

44304429
//report_error("\ntestRead(): Forcing unlock flags");
44314430
ret = fcntl(fd,F_UNLCK);
44324431
//report_error( strerror(errno) );
4433-
4434-
//report_error("\ntestRead(): Setting read/write flags");
4435-
ret= fcntl(fd,cmd,O_RDWR | O_NOCTTY | O_NONBLOCK);
4436-
//report_error( strerror(errno) );
44374432
#else
44384433
fd=localOpen ( name, O_RDWR | O_NOCTTY | O_NONBLOCK );
44394434
#endif

0 commit comments

Comments
 (0)