alnyan/yggdrasil: add an option to change process root
This commit is contained in:
@@ -7,6 +7,7 @@ use yggdrasil_rt::process::{ProcessId, Signal, SpawnFlags};
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
use crate::io;
|
||||
use crate::path::Path;
|
||||
use crate::process::{Child, Command, ExitStatus};
|
||||
use crate::sealed::Sealed;
|
||||
use crate::sys_common::{AsInner, AsInnerMut};
|
||||
@@ -28,7 +29,11 @@ pub trait CommandExt: Sealed {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
unsafe fn attach_tracing(&mut self) -> &mut Command;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
fn disable_aslr(&mut self) -> &mut Command;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
fn change_root<P: AsRef<Path>>(&mut self, new: P) -> &mut Command;
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
@@ -58,6 +63,11 @@ impl CommandExt for Command {
|
||||
self.as_inner_mut().flags |= SpawnFlags::DISABLE_ASLR;
|
||||
self
|
||||
}
|
||||
|
||||
fn change_root<P: AsRef<Path>>(&mut self, new: P) -> &mut Command {
|
||||
self.as_inner_mut().change_root(new);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
|
||||
@@ -17,6 +17,7 @@ pub struct Command {
|
||||
args: Vec<String>,
|
||||
env: CommandEnv,
|
||||
cwd: Option<PathBuf>,
|
||||
pub(crate) root: Option<PathBuf>,
|
||||
|
||||
pub(crate) pgroup: Option<OsProcessGroupId>,
|
||||
pub(crate) gain_terminal: Option<RawFd>,
|
||||
@@ -39,6 +40,7 @@ impl Command {
|
||||
args: vec![],
|
||||
env: Default::default(),
|
||||
cwd: None,
|
||||
root: None,
|
||||
pgroup: None,
|
||||
gain_terminal: None,
|
||||
attach_trace: false,
|
||||
@@ -164,6 +166,7 @@ impl Command {
|
||||
}));
|
||||
|
||||
let directory = self.cwd.as_ref().map(|cwd| cwd.to_str().unwrap());
|
||||
let root = self.root.as_ref().map(|root| root.to_str().unwrap());
|
||||
|
||||
let environment = &Vec::from_iter(envs.iter().map(|x| x.as_str()));
|
||||
|
||||
@@ -172,6 +175,7 @@ impl Command {
|
||||
arguments,
|
||||
environment,
|
||||
directory,
|
||||
root,
|
||||
optional: &optional,
|
||||
flags: self.flags,
|
||||
};
|
||||
@@ -180,6 +184,10 @@ impl Command {
|
||||
|
||||
Ok(Process { pid })
|
||||
}
|
||||
|
||||
pub(crate) fn change_root<P: AsRef<Path>>(&mut self, root: P) {
|
||||
self.root = Some(root.as_ref().into());
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for CommandArgs<'a> {
|
||||
|
||||
Reference in New Issue
Block a user