Repository: hannobraun/inotify-rs (language: rust)

Issue:
wrapper abstraction does not lend itself to multithreading
When one thread reads from the inotify fd and another closes it, bad things can happen.
- The reading thread gets stuck in `wait_for_events` forever.
- The inotify fd becomes invalid (⇒ bad file descriptor).
- The inotify fd is recycled by the OS (⇒ undefined bahavior).

I'd be happy to submit a PR to fix this. However, any solution I can come up with involves at least some API breakage. Therefore I'd really like to get some input first.

(ref passcod/rsnotify#37)



Discussion / hints:
Thanks for reporting!

I think the root issue is that `INotify` allows the inotify API to be misused in such a way. I wrote it when I had much less experience with Rust, and it clearly shows.

> I'd be happy to submit a PR to fix this. However, any solution I can come up with involves at least some API breakage.

I'd be very thankful for that! Any amount of breakage is fine, as the API is so clearly wrong :)

> Therefore I'd really like to get some input first.

What I would do first, is read the inotify documentation carefully, to find out what the story about multi-threaded usage is. If it's allowed, there should be a way to safely expose it. If not, the wrapper needs to reflect that.

Both outcomes would be fine with me. The priority is to provide a correct API. If it comes down to restricting the API, it would make sense to coordinate with rsnotify, to make sure their needs are met.


Fix patch:
diff --git a/src/wrapper.rs b/src/wrapper.rs
index 712f035..eaa14f6 100644
--- a/src/wrapper.rs
+++ b/src/wrapper.rs
@@ -27,7 +27,6 @@ use ffi::inotify_event;
 
 pub type Watch = c_int;
 
-#[derive(Clone)]
 pub struct INotify {
     pub fd: c_int,
     events: Vec<Event>,


Test patch: