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 wrappers for sysconf(3), pathconf(2), and fpathconf(2) #630

Merged
merged 1 commit into from
Jul 15, 2017

Conversation

asomers
Copy link
Member

@asomers asomers commented Jun 25, 2017

No description provided.

@Susurrus
Copy link
Contributor

I'd prefer to get the missing constants added to libc before merging this since there's a small and clear list of missing constants. Would you be able to do that?

@asomers
Copy link
Member Author

asomers commented Jun 25, 2017

Already working on it.

@Susurrus
Copy link
Contributor

Awesome, 👍

@Susurrus
Copy link
Contributor

And otherwise this PR seems fine to me, though I'd ask that you squash these commits into one.

@asomers
Copy link
Member Author

asomers commented Jun 25, 2017

Upstream PR at rust-lang/libc#628

@asomers
Copy link
Member Author

asomers commented Jun 27, 2017

All the Travis builds failed with an error like "error: "rustup" "target" "list" failed with exit code: Some(1)". Lame. I'll try forcing a rebuild in the morning.

@asomers asomers mentioned this pull request Jun 28, 2017
10 tasks
Copy link
Contributor

@Susurrus Susurrus left a 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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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

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?

Copy link
Member Author

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 sysconf with an unsupported varible
// Note: If future versions of FreeBSD add support for this option then the test
// must be modified.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Misspelled

@Susurrus
Copy link
Contributor

Susurrus commented Jul 9, 2017

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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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?

@Susurrus
Copy link
Contributor

Just some doc comment improvements. I found these by running cargo doc --no-deps --open and looking at the generated docs.

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.
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Member Author

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,
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@Susurrus
Copy link
Contributor

This time I went through some of the enum variants and a few are missing constants in libc. I'd like us to stop declaring constants here and only do them in libc. I know there was just a release of libc and you wanted to get this into the next version of nix, so we either wait until a release contains those constants or we push this from the current release.

@asomers asomers changed the title Add wrappers for sysconf(3), pathconf(3), and fpathconf(3) Add wrappers for sysconf(3), pathconf(2), and fpathconf(2) Jul 13, 2017
@asomers
Copy link
Member Author

asomers commented Jul 15, 2017

Susurrus stated his conditional approval on me adding a few more comments for SysconfVar and PathconfVar, so here it is:

bors r+ susurrus

bors bot added a commit that referenced this pull request Jul 15, 2017
630: Add wrappers for sysconf(3), pathconf(2), and fpathconf(2) r=asomers
@bors
Copy link
Contributor

bors bot commented Jul 15, 2017

@bors bors bot merged commit b259964 into nix-rust:master Jul 15, 2017
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.

2 participants