-
Notifications
You must be signed in to change notification settings - Fork 119
Cmd pdeathsig #943
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
Cmd pdeathsig #943
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
use std::{ | ||
io::{Read, Seek}, | ||
os::unix::process::CommandExt, | ||
process::Command, | ||
}; | ||
|
||
|
@@ -15,6 +16,9 @@ pub trait CommandRunExt { | |
/// Execute the child process. | ||
fn run(&mut self) -> Result<()>; | ||
|
||
/// Ensure the child does not outlive the parent. | ||
fn lifecycle_bind(&mut self) -> &mut Self; | ||
|
||
/// Execute the child process and capture its output. This uses `run` internally | ||
/// and will return an error if the child process exits abnormally. | ||
fn run_get_output(&mut self) -> Result<Box<dyn std::io::BufRead>>; | ||
|
@@ -84,6 +88,19 @@ impl CommandRunExt for Command { | |
self.status()?.check_status(stderr) | ||
} | ||
|
||
#[allow(unsafe_code)] | ||
fn lifecycle_bind(&mut self) -> &mut Self { | ||
// SAFETY: This API is safe to call in a forked child. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A docs reference would be good (even if it's just to say that this is implemented with prctl and point to the list in signal-safety manpage)... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, the rustix docs for this function do link directly to the prctl man page right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think while we could have more safety explanations in cases like this, what we have here is actually better than some of the other (few) |
||
unsafe { | ||
self.pre_exec(|| { | ||
rustix::process::set_parent_process_death_signal(Some( | ||
cgwalters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rustix::process::Signal::Term, | ||
)) | ||
.map_err(Into::into) | ||
cgwalters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
} | ||
} | ||
|
||
/// Output a debug-level log message with this command. | ||
fn log_debug(&mut self) -> &mut Self { | ||
// We unconditionally log at trace level, so avoid double logging | ||
|
Uh oh!
There was an error while loading. Please reload this page.