-
Notifications
You must be signed in to change notification settings - Fork 61
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
Shared exe-unit process module #3168
Changes from all commits
5d512e0
9c8e7e6
2a2ca29
82d6899
57cb4c9
59eb7c2
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.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,16 @@ use std::time::Duration; | |
#[cfg(feature = "lock")] | ||
pub mod lock; | ||
|
||
#[cfg(unix)] | ||
mod unix; | ||
#[cfg(unix)] | ||
pub use unix::*; | ||
|
||
#[cfg(windows)] | ||
mod win; | ||
#[cfg(windows)] | ||
pub use win::*; | ||
|
||
#[cfg(unix)] | ||
use shared_child::unix::SharedChildExt; | ||
|
||
|
@@ -20,6 +30,16 @@ use winapi::um::{ | |
wincon::{GenerateConsoleCtrlEvent, CTRL_BREAK_EVENT}, | ||
}; | ||
|
||
#[derive(Clone, Debug, thiserror::Error)] | ||
pub enum ProcessError { | ||
#[error("Unsupported: {0}")] | ||
Unsupported(String), | ||
#[error("Usage limit exceeded: {0}")] | ||
UsageLimitExceeded(String), | ||
#[error("Other error: {0}")] | ||
Other(String), | ||
} | ||
|
||
pub trait ProcessGroupExt<T> { | ||
fn new_process_group(&mut self) -> &mut T; | ||
} | ||
|
@@ -80,12 +100,21 @@ pub enum ExeUnitExitStatus { | |
#[derive(Clone)] | ||
pub struct ProcessHandle { | ||
process: Arc<SharedChild>, | ||
// Windows process will be killed once `job_object` is dropped | ||
#[allow(unused)] | ||
#[cfg(windows)] | ||
job_object: JobObject, | ||
} | ||
|
||
impl ProcessHandle { | ||
pub fn new(command: &mut Command) -> Result<ProcessHandle> { | ||
let process = Arc::new(SharedChild::spawn(command)?); | ||
#[cfg(windows)] | ||
let job_object = JobObject::try_new_current()?; | ||
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 left |
||
Ok(ProcessHandle { | ||
process: Arc::new(SharedChild::spawn(command)?), | ||
process, | ||
#[cfg(windows)] | ||
job_object, | ||
}) | ||
} | ||
|
||
|
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.
Having conditionally existing field is hard to maintain. I'm wondering if we could have empty job object implementation for unix?
In general all these conditional compilation in process handling is hard to maintain, because we need to compile with different features to be sure it will compile... But it was already done like this before, so we can leave it as is if it would require to much work.