Forward signals to the child processes of agent-sandbox
This commit is contained in:
+7
-2
@@ -24,6 +24,7 @@ use std::process::ExitStatus;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::sandbox::Bwrap;
|
||||
use crate::signals::ForwardedSignals;
|
||||
|
||||
const CLEANUP_GRACE_PERIOD: Duration = Duration::from_secs(5);
|
||||
|
||||
@@ -100,7 +101,8 @@ fn resolve_run_user_from_proc() -> Option<String> {
|
||||
pub fn run(config: SandboxConfig) -> Result<ExitStatus, SandboxError> {
|
||||
preflight::check(&config)?;
|
||||
|
||||
let bwrap = Bwrap::build(&config)?;
|
||||
let forwarded_signals = ForwardedSignals::detect();
|
||||
let mut bwrap = Bwrap::build(&config, &forwarded_signals.build_signal_reset_prefix())?;
|
||||
|
||||
if config.dry_run {
|
||||
println!("{}", bwrap.shell_quoted());
|
||||
@@ -108,7 +110,10 @@ pub fn run(config: SandboxConfig) -> Result<ExitStatus, SandboxError> {
|
||||
}
|
||||
|
||||
process_tree::become_subreaper()?;
|
||||
let status = bwrap.run()?;
|
||||
let signal_forwarder = forwarded_signals.capture()?;
|
||||
// bwrap ignores them: its death would SIGKILL the entrypoint through --die-with-parent.
|
||||
let bwrap_process = bwrap.spawn(signal_forwarder.ignore_forwarded_signals())?;
|
||||
let status = signal_forwarder.forward_until_exit(&bwrap_process)?;
|
||||
process_tree::terminate_and_reap_all(CLEANUP_GRACE_PERIOD)?;
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user