-
Notifications
You must be signed in to change notification settings - Fork 666
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
add support for openat, fstatat, readlink, readlinkat #552
Conversation
03c6d29
to
02e9d39
Compare
I cannot explain the build error happen on travis. Works fine locally. |
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.
Thanks for doing this! There are a couple of changes I'd like made to keep with nix conventions. Otherwise looks good. If you feel up to it, could you also add the other fooat
syscalls?
src/sys/stat.rs
Outdated
mod consts { | ||
use libc::c_int; | ||
|
||
bitflags!( |
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.
Please use the constants from the libc crate. There's a macro libc_bitflags
to help with this; for an example, see:
Lines 9 to 20 in 5c90289
libc_bitflags!{ | |
pub flags ProtFlags: libc::c_int { | |
PROT_NONE, | |
PROT_READ, | |
PROT_WRITE, | |
PROT_EXEC, | |
#[cfg(any(target_os = "linux", target_os = "android"))] | |
PROT_GROWSDOWN, | |
#[cfg(any(target_os = "linux", target_os = "android"))] | |
PROT_GROWSUP, | |
} | |
} |
It looks like you might have to add AT_NO_AUTOMOUNT
to libc, as well as add the constants to non-linux systems. Let me know if you need any help or guidance doing that!
src/sys/stat.rs
Outdated
use libc::c_int; | ||
|
||
bitflags!( | ||
flags FstatatFlag: c_int { |
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.
This should be called AtFlags
according to the conventions: https://github.com/nix-rust/nix/blob/master/CONVENTIONS.md#bitflags
The flag is used in a bunch of other at
functions that use these flags, like openat
, linkat
, unlinkat
, ... So naming this after fstatat
doesn't make too much sense. :-)
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.
Hm, not all of them use all these flags, but at least linkat
does.
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 saw that nix unify some flags with the same name prefix, but I did not understand the reasoning here. Because some flags are only accepted by some system calls. For instance AT_EMPTY_PATH
is not accepted by fchownat
and even for the same function different operating systems differ in flags they accept for a system call wrapper. Would this not lead to subtle bugs, when porting applications?
Oh I'm also confused about the CI failures! Tests pass on my machine. I probably won't get to look into it in detail for a few more days. If you figure out out, please let me know what it was! |
wait for rust-lang/libc#549 to be merged. |
fstatat
173223c
to
de49221
Compare
e2ca81a
to
4bd1af0
Compare
src/fcntl.rs
Outdated
unsafe { libc::readlink(cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) } | ||
})); | ||
|
||
Errno::result(res).map(move |len| OsStr::from_bytes(&buffer[..(len as usize)])) |
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.
ok, this solution is wrong: if the buffer is too small, the buffer is truncated without notifications. I see two options here:
- Remove buffer from arguments and reallocate buffer internally until it fits the result of readlink (this is what the rust/go stdlib do)
- return ENAMETOOLONG if len > buffer.len()
Which one fits into the philosophy of nix better?
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 decided to use strategy 2 for the moment. If people want to use the first option, they could also use the rust std.
Looks good, thanks! @homu r+ |
📌 Commit 55d7b5c has been approved by |
⚡ Test exempted - status |
add support for openat, fstatat, readlink, readlinkat
No description provided.