-
Notifications
You must be signed in to change notification settings - Fork 674
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
feat: I/O safety for 'sys/inotify' #1913
Conversation
The CI failure looks directly related to this PR. |
Yes, that's why this PR needs to be blocked until the merge of #1863
|
457ec50
to
835ff2c
Compare
@asomers I have fixed the error (by using the old |
src/sys/inotify.rs
Outdated
@@ -152,12 +152,12 @@ impl Inotify { | |||
/// | |||
/// For more information see, [inotify_add_watch(2)](https://man7.org/linux/man-pages/man2/inotify_add_watch.2.html). | |||
pub fn add_watch<P: ?Sized + NixPath>( | |||
self, | |||
&mut self, |
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.
Why &mut self
and not &self
?
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.
Semantically, inotify_add_watch modifies the existing inotify instance, though this can not be reflected in the implementation of this binding.
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 consider this is a case of "internal mutability". The correctness of the the method doesn't depend on it having exclusive access to the the structure, so we can remove the mut
.
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.
Get it, this can also be applied to rm_watch and read_events
835ff2c
to
9d74330
Compare
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.
bors r+
It seems this broke monitoring Inotify with Epoll since it removed the AsRawFd but didn't implement any other way to combine it will Epoll (or plain Poll for that matter). This makes it impossible to monitor both inotify files and some other FDs at the same time. See also issue #1998 |
What this PR does:
Changes the
fd
field ofstruct Inotify
fromRawFd
toOwnedFd
Changes the interfaces of functions in the
impl Inotify {}
From:
To:
In the previous implementation, these functions can take
self
by value asstruct Inotify
wasCopy
. With the changes in1
applied,struct Inotify
is no longerCopy
, so we have to takeself
by reference.Blocks until the merge of #1863 as this PR needs
read(2)
to be I/O-safe.