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

add support for openat, fstatat, readlink, readlinkat #552

Merged
merged 3 commits into from
Mar 26, 2017

Conversation

Mic92
Copy link
Contributor

@Mic92 Mic92 commented Mar 8, 2017

No description provided.

@Mic92 Mic92 force-pushed the fstatat branch 9 times, most recently from 03c6d29 to 02e9d39 Compare March 8, 2017 23:14
@Mic92
Copy link
Contributor Author

Mic92 commented Mar 8, 2017

I cannot explain the build error happen on travis. Works fine locally.

Copy link
Member

@kamalmarhubi kamalmarhubi left a 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!(
Copy link
Member

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:

nix/src/sys/mman.rs

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 {
Copy link
Member

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. :-)

Copy link
Member

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.

Copy link
Contributor Author

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?

@kamalmarhubi
Copy link
Member

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!

@Mic92
Copy link
Contributor Author

Mic92 commented Mar 13, 2017

wait for rust-lang/libc#549 to be merged.

@Mic92 Mic92 mentioned this pull request Mar 20, 2017
@Mic92 Mic92 changed the title add support for fstatat add support for openat, fstatat, readlink, readlinkat Mar 20, 2017
@Mic92 Mic92 force-pushed the fstatat branch 2 times, most recently from 173223c to de49221 Compare March 20, 2017 23:21
@Mic92 Mic92 force-pushed the fstatat branch 2 times, most recently from e2ca81a to 4bd1af0 Compare March 20, 2017 23:59
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)]))
Copy link
Contributor Author

@Mic92 Mic92 Mar 22, 2017

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:

  1. Remove buffer from arguments and reallocate buffer internally until it fits the result of readlink (this is what the rust/go stdlib do)
  2. return ENAMETOOLONG if len > buffer.len()

Which one fits into the philosophy of nix better?

Copy link
Contributor Author

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.

@posborne
Copy link
Member

Looks good, thanks! @homu r+

@homu
Copy link
Contributor

homu commented Mar 26, 2017

📌 Commit 55d7b5c has been approved by posborne

@homu
Copy link
Contributor

homu commented Mar 26, 2017

⚡ Test exempted - status

@homu homu merged commit 55d7b5c into nix-rust:master Mar 26, 2017
homu added a commit that referenced this pull request Mar 26, 2017
add support for openat, fstatat, readlink, readlinkat
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

4 participants