Skip to content

Conversation

@waywardmonkeys
Copy link
Contributor

The return value of fcntl when passed F_SETFL isn't guaranteed
to return the flags passed in as its return value. It will be -1
in the event of an error, but no other value is to be relied upon.

Fortunately, we weren't relying upon the value apart from
occasionally checking for an error.

This is as it is specified in https://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.html

Closes Interlisp/medley#87.

The return value of `fcntl` when passed `F_SETFL` isn't guaranteed
to return the flags passed in as its return value. It will be `-1`
in the event of an error, but no other value is to be relied upon.

Fortunately, we weren't relying upon the value apart from
occasionally checking for an error.

This is as it is specified in https://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.html

Closes Interlisp/medley#87.
Copy link
Collaborator

@nbriggs nbriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good time to move consistently to O_NDELAY (from FNDELAY) and O_ASYNC (from FASYNC) since those are the POSIX names and the others are just included for compatibility. Also, we could switch style to

     [res =] fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NDELAY);
...
     [res =] fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY);

(I'm not a fan of 65535 - FNDELAY)

@waywardmonkeys
Copy link
Contributor Author

I have a separate bug for that change and plan to do it as a separate PR. I want to keep the changes here limited to fixing the one thing.

Copy link
Collaborator

@nbriggs nbriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@nbriggs nbriggs merged commit 3e2a2d7 into Interlisp:master Dec 29, 2020
@waywardmonkeys waywardmonkeys deleted the fcntl-F_SETFL-return-value-not-meaningful branch December 29, 2020 02:34
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.

maiko: fnctl with F_SETFL has no valid return value apart from -1

2 participants