alnyan/yggdrasil: ability to set terminal control group for new proc

This commit is contained in:
2023-11-14 17:30:42 +02:00
parent 957d3dec43
commit 8a5d469dc3
3 changed files with 41 additions and 0 deletions
+1
View File
@@ -1,6 +1,7 @@
#![stable(feature = "os", since = "1.0.0")]
pub(crate) mod io;
pub mod process;
#[unstable(feature = "yggdrasil_raw_fd", issue = "none")]
pub mod fd {
+28
View File
@@ -0,0 +1,28 @@
#![stable(feature = "os", since = "1.0.0")]
use crate::process::Command;
use crate::sealed::Sealed;
use crate::sys_common::AsInnerMut;
use yggdrasil_rt::io::RawFd;
#[unstable(feature = "yggdrasil_os", issue = "none")]
pub trait CommandExt: Sealed {
#[unstable(feature = "yggdrasil_os", issue = "none")]
fn process_group(&mut self, pgroup: u32) -> &mut Command;
#[unstable(feature = "yggdrasil_os", issue = "none")]
unsafe fn gain_terminal<F: Into<RawFd>>(&mut self, fd: F) -> &mut Command;
}
#[unstable(feature = "yggdrasil_os", issue = "none")]
impl CommandExt for Command {
fn process_group(&mut self, pgroup: u32) -> &mut Command {
self.as_inner_mut().pgroup = Some(pgroup);
self
}
unsafe fn gain_terminal<F: Into<RawFd>>(&mut self, fd: F) -> &mut Command {
self.as_inner_mut().gain_terminal = Some(fd.into());
self
}
}
+12
View File
@@ -159,6 +159,8 @@ pub struct Command {
program: String,
args: Vec<String>,
env: CommandEnv,
pub(crate) pgroup: Option<u32>,
pub(crate) gain_terminal: Option<RawFd>,
stdin: Stdio,
stdout: Stdio,
@@ -175,6 +177,8 @@ impl Command {
program,
args: vec![],
env: Default::default(),
pgroup: None,
gain_terminal: None,
stdin: Stdio::Inherit,
stdout: Stdio::Inherit,
stderr: Stdio::Inherit,
@@ -286,6 +290,14 @@ impl Command {
});
}
if let Some(pgroup) = self.pgroup {
optional.push(SpawnOption::SetProcessGroup(pgroup));
}
if let Some(fd) = self.gain_terminal {
optional.push(SpawnOption::GainTerminal(fd));
}
let program = self.program.as_str();
let arguments = &Vec::from_iter(
crate::iter::once(self.program.as_str())