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

Fix fork test and enable doc test #1462

Merged
merged 1 commit into from
Jul 10, 2021

Conversation

sporksmith
Copy link
Contributor

Replaces println! with raw libc::write. println! isn't guaranteed
to be async-signal-safe, and almost certainly isn't due to internal
buffering and locking.

Adds a call to libc::_exit in the child arm, so that it doesn't fall
through and start executing the parent code.

Adds a call to waitpid in the parent arm, to clean up the child
process.

Removes the no_run directive, so that it's run in the doc tests.

Replaces `println!`  with raw `libc::write`. `println!` isn't guaranteed
to be async-signal-safe, and almost certainly *isn't* due to internal
buffering and locking.

Adds a call to `libc::_exit` in the child arm, so that it doesn't fall
through and start executing the parent code.

Adds a call to `waitpid` in the parent arm, to clean up the child
process.

Removes the `no_run` directive, so that it's run in the doc tests.
/// }
/// Ok(ForkResult::Child) => {
/// // Unsafe to use `println!` (or `unwrap`) here. See Safety.
/// write(libc::STDOUT_FILENO, "I'm a new child process\n".as_bytes()).ok();
Copy link
Member

Choose a reason for hiding this comment

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

Should you explicitly nul-terminate this string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't think so. The underlying syscall takes an explicit length parameter (which the nix wrapper provides for us)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's right. Because you're writing to stdout, there's no need to nul-terminate. stdout never ends.

@sporksmith sporksmith requested a review from asomers July 9, 2021 16:17
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

@bors bors bot merged commit a6cd121 into nix-rust:master Jul 10, 2021
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