Skip to content

Conversation

@dilyanpalauzov
Copy link

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 of fctnl)).

Actually the definitions in /usr/include/bits/fcntl-linux.h are:

#define FD_CLOEXEC        1       /* Actually anything with low bit set goes */
#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);

…ot work on Linux

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);
dilyanpalauzov pushed a commit to dilyanpalauzov/nrjavaserial that referenced this pull request Nov 5, 2025
…ot 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant