Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a convenience method .pid() for WaitStatus.#722

Merged
bors[bot] merged 1 commit into
nix-rust:masterfrom
marmistrz:wait_getpid
Aug 8, 2017
Merged

Add a convenience method .pid() for WaitStatus.#722
bors[bot] merged 1 commit into
nix-rust:masterfrom
marmistrz:wait_getpid

Conversation

@marmistrz
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread test/sys/test_wait.rs Outdated
let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");

match fork().unwrap() {
Child => {},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't allow the child to return. It's vulnerable to deadlocks in the test harness code. Instead, call _exit(0).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You mean that the test harness executes the function as a normal function, so the forked process will duplicate what test harness does?

Why _exit and not std::process::exit? The former is unsafe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, the forked process duplicates the entire test harness. But it doesn't duplicate any threads other than the one that called fork. So if one of those other threads held a mutex that is required by this thread during its teardown phase, then this thread will deadlock. The reason to use _exit instead of sys::process::exit is subtler, and it's because _exit doesn't do any C-level teardown. See fork(2).

Copy link
Copy Markdown
Contributor Author

@marmistrz marmistrz Aug 7, 2017

Choose a reason for hiding this comment

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

You mean the reasons like this: https://stackoverflow.com/questions/5422831/what-is-the-difference-between-using-exit-exit-in-a-conventional-linux-fo
(double buffer flushing or double execution of atexit handlers?)

Why is there no clean way of doing _exit without unsafe constructs if we're exposing fork as a public function?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Like that, but worse because the parent is a multi-threaded process. In a multi-threaded process, even memory allocation could theoretically deadlock, so until the child execs, it is limited to only calling async-signal-safe functions, which are a pretty restrictive set.

@asomers
Copy link
Copy Markdown
Member

asomers commented Aug 7, 2017

This all looks good to me, though you still need to squash. I'll give @Susurrus a day or so to comment before I merge it.

@marmistrz
Copy link
Copy Markdown
Contributor Author

@asomers Can you squash while merging? The GitHub web UI allows it.

@asomers
Copy link
Copy Markdown
Member

asomers commented Aug 7, 2017

@marmistrz I can't squash while merging, because nix doesn't use the GitHub web UI. We use bors instead. bors prevents test failures caused by merge conflicts, but unfortunately can't automatically squash.

Comment thread CHANGELOG.md Outdated
([#672](https://github.com/nix-rust/nix/pull/672))
- Added protocol families in `AddressFamily` enum.
([#647](https://github.com/nix-rust/nix/pull/647))
- Added a convenience method `.pid()` to the `enum WaitStatus`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead "Added the pid() method to WaitStatus for extracting the PID."

Comment thread src/sys/wait.rs Outdated
/// Extracts the PID from the WaitStatus if the status is not StillAlive.
pub fn pid(&self) -> Option<Pid> {
use self::WaitStatus::*;
match self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not certain if this StackOverflow comment is correct, but it would read nicer if you did match *self to get rid of the & on every match arm.

@marmistrz
Copy link
Copy Markdown
Contributor Author

Squashed.

@asomers
Copy link
Copy Markdown
Member

asomers commented Aug 8, 2017

bors r+

bors Bot added a commit that referenced this pull request Aug 8, 2017
722: Add a convenience method .pid() for WaitStatus. r=asomers
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Aug 8, 2017

@bors bors Bot merged commit 0370de6 into nix-rust:master Aug 8, 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.

3 participants