-
Notifications
You must be signed in to change notification settings - Fork 381
Support F_GETFL and F_SETFL for fcntl #4212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tiif
wants to merge
16
commits into
rust-lang:master
Choose a base branch
from
tiif:setfl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d7f0d20
Add F_SETFL flag
tiif e177d69
Add SETFL
tiif fd668d7
Add basic test for setfl
tiif 26831b0
Add test for threaded setfl
tiif 54b38d4
Add comment to test
tiif 091a151
Fix the blocking test
tiif 5bc4382
Add a FIXME
tiif 62510f7
Shift comment to the right place
tiif a5106f1
Remove spurious change
tiif 1df03f9
macos don't have SOCK_NONBLOCK
tiif 6a2f794
Fix typo in error message
tiif b42da06
Add comment for is_nonblock field in AnonSocket
tiif 71f89b6
Inline cmd_name and fix typo
tiif fdf379a
Remove comment for O_NONBLOCK == SOCK_NONBLOCK
tiif 1609781
Modify test to use one thread
tiif b22019d
Move all test to use isolation mode
tiif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@ignore-target: windows # File handling is not implemented yet | ||
//~^ ERROR: deadlock: the evaluated program deadlocked | ||
//@compile-flags: -Zmiri-preemption-rate=0 | ||
use std::thread; | ||
|
||
/// If an O_NONBLOCK flag is set while the fd is blocking, that fd will not be woken up. | ||
fn main() { | ||
let mut fds = [-1, -1]; | ||
let res = unsafe { libc::pipe(fds.as_mut_ptr()) }; | ||
assert_eq!(res, 0); | ||
let mut buf: [u8; 5] = [0; 5]; | ||
let _thread1 = thread::spawn(move || { | ||
// Add O_NONBLOCK flag while pipe is still block on read. | ||
let new_flag = libc::O_NONBLOCK; | ||
let res = unsafe { libc::fcntl(fds[0], libc::F_SETFL, new_flag) }; | ||
assert_eq!(res, 0); | ||
}); | ||
// Main thread will block on read. | ||
let _res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) }; | ||
//~^ ERROR: deadlock: the evaluated program deadlocked | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error: deadlock: the evaluated program deadlocked | ||
| | ||
= note: the evaluated program deadlocked | ||
= note: (no span available) | ||
= note: BACKTRACE on thread `unnamed-ID`: | ||
|
||
error: deadlock: the evaluated program deadlocked | ||
--> tests/fail-dep/libc/fcntl_fsetfl_while_blocking.rs:LL:CC | ||
| | ||
LL | let _res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) }; | ||
| ^ the evaluated program deadlocked | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `main` at tests/fail-dep/libc/fcntl_fsetfl_while_blocking.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this match real implementations -- only returning O_NONBLOCK and no other flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overlooked something, we need to return
O_RDWR
forsocketpair
,O_RDONLY
andO_WRONLY
forpipe
. So we need to add something to differentiate betweensocketpair
andpipe
's reading / writing end here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we should have
get_flags
andset_flags
methods on the FD trait so this logic can live with the FD implementation.When a socketpair's peer FD has been closed, does it become RDONLY?