-
Notifications
You must be signed in to change notification settings - Fork 679
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
Additional documentation additions #452
Conversation
Signed-off-by: Paul Osborne <[email protected]>
Signed-off-by: Paul Osborne <[email protected]>
The previous one was entirely too generic. Signed-off-by: Paul Osborne <[email protected]>
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 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 |
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.
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` |
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 would prefer if the documentation where written consistently in the third person.
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.
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. |
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.
What good is an abstraction, if we need to look at the implementation for documentation?
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 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.
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.
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 |
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 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)). |
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.
But we don't return the length (directly).
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.
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; |
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 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?
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.
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.
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.
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
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.
Also I'd prefer API changes in a separate PR from doc changes.
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.
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.
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.
Ah I missed that.
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. |
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. |
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). |
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 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.
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.
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; |
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.
Ah I missed that.
99a1726
to
2f220fc
Compare
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]>
I stripped this down to just the documentation commits and addressed comments, so getting this merged up. @homu r=fiveop |
📌 Commit 173f2ac has been approved by |
…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
⚡ Test exempted - status |
…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
@homu r=fiveop |
…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
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