Skip to content
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

Added inotify bindings. #1016

Merged
merged 1 commit into from
Mar 6, 2019
Merged

Added inotify bindings. #1016

merged 1 commit into from
Mar 6, 2019

Conversation

vdagonneau
Copy link
Contributor

Hi !

I needed inotify bindings and noticed that nix did not have any so here is a PR to add it.

There was another PR from 2015 to add support for inotify that was never merged. I took some of the feedback and applied it here.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to finish this PR, you'll also need tests and documentation. BTW, have you seen the "inotify" crate? It may already do everything you need.

src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
@vdagonneau
Copy link
Contributor Author

vdagonneau commented Jan 21, 2019

I updated the code taking your remarks into account, I also added some documentation and testing.

I am not sure how to integrate my ffi code into libc, I would appreciate pointers on how to do that.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring the user to manipulate raw pointers is way too low level for a Nix API. The point of Nix is that it takes care of stuff like that. Can you come up with a cleaner API?

test/sys/test_inotify.rs Outdated Show resolved Hide resolved
@asomers
Copy link
Member

asomers commented Jan 22, 2019

Submitting a PR to libc is easy. Just checkout https://github.com/rust-lang/libc/ . Copy the format for existing code. The hardest part is sometimes figuring out which file to modify. If inotify is the same on all Linux architectures, then your changes should go into src/unix/notbsd/linux/mod.rs.

src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a two-event test? Only testing a single event leaves a big coverage gap.

src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
test/sys/test_inotify.rs Outdated Show resolved Hide resolved
test/sys/test_inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
@vdagonneau
Copy link
Contributor Author

I removed all the ffi code from the pull request and submitted a pull request in the libc.

@asomers
Copy link
Member

asomers commented Jan 26, 2019

Could you please link this PR to the libc PR?

@vdagonneau
Copy link
Contributor Author

Hi, I'm sorry for the delay, I was on vacation with very limited access to internet. The libc PR is at: rust-lang/libc#1230.

@vdagonneau
Copy link
Contributor Author

The code I needed has been merged into the libc.

src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Outdated Show resolved Hide resolved
src/sys/inotify.rs Show resolved Hide resolved
src/sys/inotify.rs Show resolved Hide resolved
src/sys/mod.rs Outdated Show resolved Hide resolved
test/sys/test_inotify.rs Outdated Show resolved Hide resolved
@asomers
Copy link
Member

asomers commented Feb 13, 2019

The build is failing on Android because of undefined symbols. You'll have to figure out whether Android actually has those symbols or not. If so, then you should add them to libc. If not, then you can remove this module on Android.

@vdagonneau
Copy link
Contributor Author

I'm having problems integrating the changes for android into libc; It is likely not as simple as I initially thought to support inotify for android.

Maybe we can start by merging the support for Linux only?

@asomers
Copy link
Member

asomers commented Feb 18, 2019

What's the problem? Does android use a different API?

@vdagonneau
Copy link
Contributor Author

The Android API is mostly the same with one little exception: inotify_rm_watch takes a uint32_t as its second argument on Android and an int on Linux.

Android: https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/SYSCALLS.TXT

Linux: https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/unix/sysv/linux/sys/inotify.h;hb=HEAD

@asomers
Copy link
Member

asomers commented Feb 19, 2019

That sounds pretty simple. What's the problem?

@vdagonneau
Copy link
Contributor Author

Nothing really, it just took me a while to track down that slight difference in API.

@asomers
Copy link
Member

asomers commented Feb 19, 2019

So the only difference between Linux and Android is signededness? Lame. Android is full of unforced errors like that. Anyway, this PR looks good to me! All it needs now is a squash.

@vdagonneau
Copy link
Contributor Author

Yes just the signededness, do you know where this kind of errors comes from ? It seems very weird to me.

@asomers
Copy link
Member

asomers commented Feb 19, 2019

Honestly, I don't know why Android has so many errors like that. There doesn't seem to be much excuse for it.

@vdagonneau
Copy link
Contributor Author

I squashed my commits, seems like everything is ready for merging!

@asomers
Copy link
Member

asomers commented Feb 20, 2019

Oh I forgot: you need a CHANGELOG entry too.

@asomers
Copy link
Member

asomers commented Feb 20, 2019

The CHANGELOG looks good, but I'm afraid your commits have become unsquashed. Could you resquash them?

@asomers
Copy link
Member

asomers commented Feb 20, 2019

Unfortunately that latested merge screwed up the PR history. I'm afraid you'll have to rebase onto master.

@vdagonneau
Copy link
Contributor Author

Ah, I'm a little lost in my git history now. It might take me some time to figure everything out.

@vdagonneau
Copy link
Contributor Author

Ok, I think the git history looks good now.

@asomers
Copy link
Member

asomers commented Feb 21, 2019

bors r+

bors bot added a commit that referenced this pull request Feb 21, 2019
1016: Added inotify bindings. r=asomers a=vdagonneau

Hi !

I needed inotify bindings and noticed that nix did not have any so here is a PR to add it.

There was another PR from 2015 to add support for inotify that was never merged. I took some of the feedback and applied it here.

Co-authored-by: Vincent Dagonneau <vincentdagonneau@gmail.com>
@bors
Copy link
Contributor

bors bot commented Feb 21, 2019

Timed out

@asomers
Copy link
Member

asomers commented Feb 21, 2019

bors retry

@vdagonneau
Copy link
Contributor Author

Seems like something went wrong with bors. Any way I can help ?

@asomers
Copy link
Member

asomers commented Mar 6, 2019

The evidence is gone now, but this might've been due to the Rust 1.33.0 problems. They're fixed now.

bors retry

bors bot added a commit that referenced this pull request Mar 6, 2019
1016: Added inotify bindings. r=asomers a=vdagonneau

Hi !

I needed inotify bindings and noticed that nix did not have any so here is a PR to add it.

There was another PR from 2015 to add support for inotify that was never merged. I took some of the feedback and applied it here.

Co-authored-by: Vincent Dagonneau <vincentdagonneau@gmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 6, 2019

Build succeeded

@bors bors bot merged commit 3966d0b into nix-rust:master Mar 6, 2019
@SteveLauC SteveLauC mentioned this pull request Nov 19, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants