Repository navigation
netlink: honor SOCK_NONBLOCK and SOCK_CLOEXEC on the virtual socket - #362
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handle_socket ignored the flags in the socket type. The child end of the socketpair always came back blocking and close-on-exec, so socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK, NETLINK_ROUTE) got a blocking fd, and a caller that left out SOCK_CLOEXEC got one that closes on exec anyway. Python is an easy way to hit the first one: it trusts SOCK_NONBLOCK and never calls fcntl, so recv on such a socket blocks forever instead of raising BlockingIOError once there is nothing left to read.
The child end now gets O_NONBLOCK when SOCK_NONBLOCK was passed, and newfd_flags follows SOCK_CLOEXEC. Callers that pass neither, like glibc, see no change.
I added an integration test that creates the socket through libc with no flag, with SOCK_NONBLOCK and with SOCK_CLOEXEC and checks O_NONBLOCK and FD_CLOEXEC on each, then checks that a Python SOCK_NONBLOCK socket gets EAGAIN from an empty recv. On main the recv hangs until the 30s guard in the test fires. With the change the whole test_netlink_virt suite passes.