-
Notifications
You must be signed in to change notification settings - Fork 166
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
Unify inotify public interface across backends and accept impl AsFd
#1105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! inotify support for working with inotifies | ||
|
||
pub use crate::backend::fs::inotify::{CreateFlags, WatchFlags}; | ||
use crate::backend::fs::syscalls; | ||
use crate::fd::{AsFd, OwnedFd}; | ||
use crate::io; | ||
|
||
/// `inotify_init1(flags)`—Creates a new inotify object. | ||
/// | ||
/// Use the [`CreateFlags::CLOEXEC`] flag to prevent the resulting file | ||
/// descriptor from being implicitly passed across `exec` boundaries. | ||
#[doc(alias = "inotify_init1")] | ||
#[inline] | ||
pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> { | ||
syscalls::inotify_init1(flags) | ||
} | ||
|
||
/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify. | ||
/// | ||
/// This registers or updates a watch for the filesystem path `path` and | ||
/// returns a watch descriptor corresponding to this watch. | ||
/// | ||
/// Note: Due to the existence of hardlinks, providing two different paths to | ||
/// this method may result in it returning the same watch descriptor. An | ||
/// application should keep track of this externally to avoid logic errors. | ||
#[inline] | ||
pub fn inotify_add_watch<P: crate::path::Arg>( | ||
inot: impl AsFd, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add the TODO comments about changing this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #753 (comment). I feel like it'll be more effective to run a global pass on the whole lib rather than trying to remember the spots impls need to be fixed. If you disagree, I'll be happy to add the TODOs here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, makes sense. |
||
path: P, | ||
flags: WatchFlags, | ||
) -> io::Result<i32> { | ||
path.into_with_c_str(|path| syscalls::inotify_add_watch(inot.as_fd(), path, flags)) | ||
} | ||
|
||
/// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify. | ||
/// | ||
/// The watch descriptor provided should have previously been returned by | ||
/// [`inotify_add_watch`] and not previously have been removed. | ||
#[doc(alias = "inotify_rm_watch")] | ||
#[inline] | ||
pub fn inotify_remove_watch(inot: impl AsFd, wd: i32) -> io::Result<()> { | ||
syscalls::inotify_rm_watch(inot.as_fd(), wd) | ||
} |
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.
Could you restore these three
SAFETY
comments? I know they're not super interesting, but they're there for the benefit of people auditing the code. They record what we believed the relevant safety considerations are, so that if it ever turns out that we missed something, it's easier to understand the intent of the code.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.
Makes sense, restored.