-
Notifications
You must be signed in to change notification settings - Fork 675
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 wrappers for sysconf(3), pathconf(2), and fpathconf(2) #630
Conversation
I'd prefer to get the missing constants added to |
Already working on it. |
Awesome, 👍 |
And otherwise this PR seems fine to me, though I'd ask that you squash these commits into one. |
Upstream PR at rust-lang/libc#628 |
All the Travis builds failed with an error like "error: |
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.
In general looks pretty good for me, just some docs and a minor code refactoring.
src/unistd.rs
Outdated
/// unsupported (for option variables) | ||
/// - `Err(x)`: an error occurred | ||
/// | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html |
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.
It'd be good to give this a proper title for when docs are generated.
src/unistd.rs
Outdated
/// Returns the value of a path-dependent configurable system variable. Most | ||
/// supported variables also have associated compile-time constants, but POSIX | ||
/// allows their values to change at runtime. There are generally two types of | ||
/// pathconf variables: options and limits. See pathconf(3) for more details. |
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.
Backticks around pathconf(3)
.
src/unistd.rs
Outdated
/// unsupported (for option variables) | ||
/// - Err(x): an error occurred | ||
/// | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html |
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.
Same as above.
Errno::clear(); | ||
libc::sysconf(var as c_int) | ||
}; | ||
if raw == -1 { |
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.
Can you use Errno::result()
here to clean up this code a bit?
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.
No, because sysconf
will return -1 with errno
set to 0 to indicate that the requested variable is not supported. Our Errno::result
class can't handle that.
test/test_unistd.rs
Outdated
|
||
// Test sysconf with an unsupported varible | ||
// Note: If future versions of FreeBSD add support for this option then the test | ||
// must be modified. |
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.
"should" not "must"
src/unistd.rs
Outdated
@@ -819,6 +821,431 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> { | |||
Ok((fd, PathBuf::from(pathname))) | |||
} | |||
|
|||
/// Variable names for `pathconf` | |||
// Note: POSIX 1003.1-2008 requires all of these symbols to be |
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.
Why not have this note be part of the doc comment? If you put a space between it and the first line, it might be a nice detail to have in the docs.
src/unistd.rs
Outdated
} | ||
|
||
/// Variable names for `sysconf` | ||
// Note: All of these symbols are standardized by POSIX 1003.1-2008, but haven't |
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.
Same as above.
src/unistd.rs
Outdated
} | ||
|
||
/// Like `pathconf`, but for file descriptors instead of paths | ||
/// # Parameters |
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.
Needs a blank line above.
src/unistd.rs
Outdated
/// Like `pathconf`, but for file descriptors instead of paths | ||
/// # Parameters | ||
/// | ||
/// - `fd`: Lookup the value of `var` for this file descriptor |
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 comment is more of a comment about the entire function then this specific argument.
src/unistd.rs
Outdated
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
#[repr(i32)] | ||
pub enum SysconfVar { | ||
AIO_LISTIO_MAX = libc::_SC_AIO_LISTIO_MAX, |
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.
These should all be indented.
src/unistd.rs
Outdated
_POSIX2_UPE = libc::_SC_2_UPE, | ||
_POSIX2_VERSION = libc::_SC_2_VERSION, | ||
PAGE_SIZE = libc::_SC_PAGE_SIZE, | ||
// POSIX requires an alias PAGESIZE == PAGE_SIZE, but Rust doesn't like |
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.
It'd be nice if this were able to be documented in the docs for this enum value. Maybe add a doc comment for PAGE_SIZE
that says this as well since that way the user could search nix
docs and find this instead of having to search the source code.
src/unistd.rs
Outdated
/// unsupported (for option variables) | ||
/// - Err(x): an error occurred | ||
/// | ||
/// # Referencces |
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.
Misspelled.
src/unistd.rs
Outdated
/// unsupported (for option variables) | ||
/// - `Err(x)`: an error occurred | ||
/// | ||
/// # Referencces |
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.
Misspelled
src/unistd.rs
Outdated
/// unsupported (for option variables) | ||
/// - `Err(x)`: an error occurred | ||
/// | ||
/// # Referencces |
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.
Misspelled
And please squash this into 1 commit in the next round. |
src/unistd.rs
Outdated
/// | ||
/// # References | ||
/// | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html |
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 make these bulleted, as they just show up on a single line when docs are generated. Also if you could make them links, use the title of the manpage as the title for them or providing a summary would be great.
/// Returns the value of a configurable system variable. Most supported | ||
/// variables also have associated compile-time constants, but POSIX | ||
/// allows their values to change at runtime. There are generally two types of | ||
/// sysconf variables: options and limits. See sysconf(3) for more details. |
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.
Can you turn "sysconf(3)" into a link to the man pages. You could then remove the "References" section at the end.
src/unistd.rs
Outdated
/// | ||
/// # References | ||
/// | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html |
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 doesn't turn into a path when you have it like this. Can you linkify it?
Just some doc comment improvements. I found these by running |
src/unistd.rs
Outdated
/// Returns the value of a path-dependent configurable system variable. Most | ||
/// supported variables also have associated compile-time constants, but POSIX | ||
/// allows their values to change at runtime. There are generally two types of | ||
/// `pathconf` variables: options and limits. See pathconf(2) for more details. |
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.
Can you turn pathconf(2)
into a link and also put it between backticks?
/// The implementation supports the Software Development Utilities option. | ||
_POSIX2_SW_DEV = libc::_SC_2_SW_DEV, | ||
/// The implementation supports the User Portability Utilities option. | ||
_POSIX2_UPE = libc::_SC_2_UPE, |
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 shouldn't be defined here, but in libc
. Can you upstream these into libc
instead of defining them here? I'd like to do this for all of the constants that are missing in libc
and then the libc_enum!
macro can be used for defining all of these.
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.
In this case, I don't think I can use libc_enum!
because the abstract variable names differ from the sysconf symbol names. Unless, that is, I switch naming conventions and simply use the SC forms for nix's public API.
/// | ||
/// POSIX also defines an alias named `PAGESIZE`, but Rust does not allow two | ||
/// enum constants to have the same value, so nix omits `PAGESIZE`. | ||
PAGE_SIZE = libc::_SC_PAGE_SIZE, |
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.
Why isn't this named the same thing?
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.
Because "PAGE_SIZE" is the abstract variable, and _SC_PAGE_SIZE
is the sysconf
variable name.
#[cfg(any(target_os="dragonfly", target_os="freebsd", target_os = "ios", | ||
target_os="linux", target_os = "macos", target_os="openbsd"))] | ||
/// The implementation supports timeouts. | ||
_POSIX_TIMEOUTS = libc::_SC_TIMEOUTS, |
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.
These should also be defined in libc
and not here.
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.
libc contains all the definitions that it needs. But the situation is fairly confusing. Let me explain:
POSIX says that some "variables" can have values that are either fixed at compile time or changeable at runtime. The variable is an abstract thing; not a C symbol. But there are two C symbols associated with it: one to look it up at build time and one to look it up at runtime via sysconf
. In this case, the variable's abstract name is "_POSIX_TIMEOUTS", it's build time symbols is _POSIX_TIMEOUTS
, and its runtime symbol is _SC_TIMEOUTS
(the "SC" stands for "sysconf"). See http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html . The table's left column has the abstract variable names, and the right column has the sysconf names. I used the abstract names for nix, reasoning that there's no need to namespace them with "SC" since Rust has real namespaces.
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.
Interesting, thanks for explaining it. I would like to see this explanation included in the docs for both of the enums so that it's clear to the users what's going on. I don't like these decisions to be completely lost in GitHub PRs.
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.
Once you've done that, go ahead and r+ susurrus for me, as I think this looks good.
This time I went through some of the enum variants and a few are missing constants in |
Susurrus stated his conditional approval on me adding a few more comments for bors r+ susurrus |
Build succeeded |
No description provided.