Switch to nonblocking I/O, read from stdin.
Opened this issue · 1 comments
The original fanotify example program that serves the basis of the rfanotify
port uses poll
on the fanotify
descriptor in nonblocking mode. It also polls stdin
to allow the user to quit gracefully by entering any input to stdin
.
Presently rfanotify
reads from the fanotify
descriptor in a blocking fashion. It also doesn't read from stdin
or offer any graceful exit, requiring the user to send a signal instead.
I should switch rfanotify
to use InitFlags::FAN_NONBLOCK
with Fanotify::init
and implement an async approach to reading events and monitoring stdin. Since I'm super new to rust I punted on non-blocking I/O in the first version.
I've had luck in a private repo rewriting the Nix bindings to be async
using tokio
and tokio-fd
. I think the resulting changes are much too heavy-weight to be useful to the upstream nix
project. For the rfanotify
example it might be best to try and rig something up with mio
using the existing nix
bindings set up with InitFlags::FAN_NOBLOCK
.
Guidance here would be welcome. I'm too much of a Rust noob to imagine the best path forward to make the nix
bindings small enough to be accepted upstream one day but also flexible enough to allow projects like rfanotify
to implement non-blocking reads of events without needing to reinvent the nix
bindings with external libraries.