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

Additional documentation additions #452

Merged
merged 4 commits into from
Nov 2, 2016

Conversation

posborne
Copy link
Member

This is a second round of doc additions. There are also some funcitonal changes to APIs for getting/setting hostname that need to be reviewed.

r? @nix-rust/nix-maintainers

The previous one was entirely too generic.

Signed-off-by: Paul Osborne <[email protected]>
Copy link
Contributor

@fiveop fiveop 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 getting the documentation process started. In the long run, I would like to have some formal rules on how documentation should look like, because I think this will result in more consistent and more concise documentation.

/// for a list of potential problems that maight cause execv to fail.
///
/// Both `::nix::unistd::execv` and `::nix::unistd::execve` take as arguments a
/// slice of `::std::ffi::CString`s for `args` and `env`. Each element in
Copy link
Contributor

Choose a reason for hiding this comment

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

execv does not have the env parameter

/// See `::nix::unistd::execve` for additoinal details. `execvp` behaves the
/// sme as execv except that it will examine the `PATH` environment variables
/// for file names not specified with a leading slash. For example, `execv`
/// would not work if I specified "bash" for the path argument, but `execvp`
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer if the documentation where written consistently in the third person.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that can be accommodated. In general, I am of the opinion that documentation changes moving forward should be fact-checked and merged first and improved in terms of content, quality, and consistency later, particularly given the somewhat poor state of our documentation at present.

/// [fork(2)](http://man7.org/linux/man-pages/man2/fork.2.html) and
/// [setsid(2)](http://man7.org/linux/man-pages/man2/setsid.2.html) and, as
/// such, error that could be returned by either of those functions could also
/// show up as errors here.
Copy link
Contributor

Choose a reason for hiding this comment

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

What good is an abstraction, if we need to look at the implementation for documentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am referring users to the libc man pages, not to an implementation. I think the former is acceptable. This is basically the same approach taking by the man pages for this call. We can go further with time, but I think this is a reasonable start.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

/// 2. Parent process exits
/// 3. Child process continues to run.
///
/// There are a couple options here whose names and meaning can be a bit
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer having less prose here. Just explain what the parameters are for, not why it is necessary to document them.

let len = name.len() as size_t;
/// Get the host name and store it int the provided buffer, returning the actual
/// length stored in the buffer (see
/// [gethostname(2)](http://man7.org/linux/man-pages/man2/gethostname.2.html)).
Copy link
Contributor

Choose a reason for hiding this comment

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

But we don't return the length (directly).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes. This needs to be updated. I went through a few iterations and ended up changing how this worked.

/// println!("Hostname: {}", hostname);
/// ```
pub fn gethostname<'a>(buffer: &'a mut [u8]) -> Result<&'a CStr> {
let ptr = buffer.as_mut_ptr() as *mut c_char;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an aside with respect to this PR:

Shouldn't we change this method to just return the hostname if possible, by using our own buffer?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could and I considered this, but I wanted to provide a zero-cost abstraction first (the user may already have a buffer). I would consider adding a variant as you mentioned -- not sure what it would be named exactly.

Copy link
Member

@kamalmarhubi kamalmarhubi Nov 1, 2016

Choose a reason for hiding this comment

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

Regarding this function, we cannot guarantee it is a valid &CStr that comes back:

gethostname() returns the null-terminated hostname in the character array name, which has a length of len bytes. If the null-terminated hostname is too large to fit, then the name is truncated, and no error is returned (but see NOTES below). POSIX.1 says that if such truncation occurs, then it is unspecified whether the returned buffer includes a terminating null byte.

http://man7.org/linux/man-pages/man2/gethostname.2.html#DESCRIPTION

Copy link
Member

Choose a reason for hiding this comment

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

Also I'd prefer API changes in a separate PR from doc changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding this function, we cannot guarantee it is a valid &CStr that comes back:

This is why I ensure that the last byte in the buffer is NUL.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I missed that.

@posborne
Copy link
Member Author

posborne commented Nov 1, 2016

Thanks for getting the documentation process started. In the long run, I would like to have some formal rules on how documentation should look like, because I think this will result in more consistent and more concise documentation.

Sure, I'm not opposed to aiming for consistency, but I think our primary goal needs to be improving the state of the documentation by at least having the basics for all public functionality. Making it easy for doc changes to get merged and encouraging people to contribute are probably the things that will help us most. We can update for consistency later.

@fiveop
Copy link
Contributor

fiveop commented Nov 1, 2016

I agree with you that something, so long as it's not wrong, is better than nothing. I was just voicing what I would like to aim for.

r=me, after you've done whatever changes you deem necessary given my comments.

@posborne
Copy link
Member Author

posborne commented Nov 1, 2016

I agree with you that something, so long as it's not wrong, is better than nothing. I was just voicing what I would like to aim for.

Sure, I'll try to clean stuff up tonight. Thanks for the review and the understanding!

written from the underlying system call at all. This has been updated to
return a `&CStr` within the provided buffer that is always properly
NUL-terminated (this is not guaranteed by the call with all platforms/libc
implementations).
Copy link
Member

Choose a reason for hiding this comment

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

I would like both of these changes moved to a non-doc PR. That PR can include the docs for those functions, but I think it's best to have API changes not happen in a PR that only advertises doc changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I can do that. They are separate commits now.

/// println!("Hostname: {}", hostname);
/// ```
pub fn gethostname<'a>(buffer: &'a mut [u8]) -> Result<&'a CStr> {
let ptr = buffer.as_mut_ptr() as *mut c_char;
Copy link
Member

Choose a reason for hiding this comment

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

Ah I missed that.

@posborne posborne force-pushed the additional-documentation-additions branch from 99a1726 to 2f220fc Compare November 2, 2016 04:08
These make the language consistent in the 3rd person, fix a few
minor mistakes, and remove some superflous prose.

Signed-off-by: Paul Osborne <[email protected]>
@posborne
Copy link
Member Author

posborne commented Nov 2, 2016

I stripped this down to just the documentation commits and addressed comments, so getting this merged up. @homu r=fiveop

@homu
Copy link
Contributor

homu commented Nov 2, 2016

📌 Commit 173f2ac has been approved by fiveop

homu added a commit that referenced this pull request Nov 2, 2016
…iveop

Additional documentation additions

This is a second round of doc additions.  There are also some funcitonal changes to APIs for getting/setting hostname that need to be reviewed.

r? @nix-rust/nix-maintainers
@kamalmarhubi
Copy link
Member

@homu retry 173f2ac

@homu
Copy link
Contributor

homu commented Nov 2, 2016

⚡ Test exempted - status

@homu homu merged commit 173f2ac into nix-rust:master Nov 2, 2016
homu added a commit that referenced this pull request Nov 2, 2016
…iveop

Additional documentation additions

This is a second round of doc additions.  There are also some funcitonal changes to APIs for getting/setting hostname that need to be reviewed.

r? @nix-rust/nix-maintainers
@kamalmarhubi
Copy link
Member

@homu r=fiveop

@posborne posborne deleted the additional-documentation-additions branch November 2, 2016 04:37
homu added a commit that referenced this pull request Jan 17, 2017
…lmarhubi

Gethostname sethostname updates

These changes have been previously discussed some with #452 but we decided it made sense to separate things out a bit more.

r? @kamalmarhubi @fiveop
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.

4 participants