* Make posix_spawn_file_actions_t an iterator
* Fix bug that caused the spawned process to not start * Make the spawned process inherit the parent's file descriptos
This commit is contained in:
@@ -495,9 +495,9 @@ pub fn fexec_impl(
|
||||
}
|
||||
|
||||
// Dropping this FD will cause the address space switch.
|
||||
drop(addrspace_selection_fd);
|
||||
|
||||
if extrainfo.same_process {
|
||||
drop(addrspace_selection_fd);
|
||||
unreachable!();
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
@@ -33,7 +33,7 @@ pub enum Operation {
|
||||
}
|
||||
|
||||
pub struct OperationNode {
|
||||
operation: Operation,
|
||||
pub operation: Operation,
|
||||
next: *const OperationNode,
|
||||
}
|
||||
|
||||
@@ -44,6 +44,32 @@ pub struct posix_spawn_file_actions_t {
|
||||
tail: *mut OperationNode,
|
||||
}
|
||||
|
||||
pub struct FileActionsIter<'a> {
|
||||
curr: Option<&'a OperationNode>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for FileActionsIter<'a> {
|
||||
type Item = &'a OperationNode;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let curr = self.curr?;
|
||||
self.curr = unsafe { curr.next.as_ref() };
|
||||
Some(curr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a posix_spawn_file_actions_t {
|
||||
type Item = &'a OperationNode;
|
||||
|
||||
type IntoIter = FileActionsIter<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
FileActionsIter {
|
||||
curr: unsafe { self.head.as_ref() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_op(file_actions: &mut posix_spawn_file_actions_t, op: Operation) -> Result<()> {
|
||||
let new = unsafe { malloc(size_of::<OperationNode>()) };
|
||||
let new_ref = unsafe {
|
||||
|
||||
@@ -79,8 +79,10 @@ fn spawn(
|
||||
if let Some(pid) = pid {
|
||||
*pid = v;
|
||||
}
|
||||
})
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
|
||||
@@ -1209,6 +1209,15 @@ impl Pal for Sys {
|
||||
let executable = File::open(program, fcntl::O_RDONLY)?;
|
||||
let cwd = path::clone_cwd().unwrap();
|
||||
let proc_fd = child.proc_fd.unwrap();
|
||||
let curr_proc_fd = redox_rt::current_proc_fd();
|
||||
let file_table = RtTcb::current()
|
||||
.thread_fd()
|
||||
.dup(b"filetable")?
|
||||
.dup(b"copy")?;
|
||||
|
||||
let new_file_table = child.thr_fd.dup(b"current-filetable")?;
|
||||
|
||||
new_file_table.write(&file_table.as_raw_fd().to_ne_bytes())?;
|
||||
|
||||
let extra_info = redox_rt::proc::ExtraInfo {
|
||||
cwd: Some(cwd.as_bytes()),
|
||||
@@ -1280,7 +1289,10 @@ impl Pal for Sys {
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(i32::try_from(child.pid).unwrap())
|
||||
let start_fd = child.thr_fd.dup(b"start")?;
|
||||
start_fd.write(&[0])?;
|
||||
|
||||
Ok(pid_t::try_from(child.pid).unwrap())
|
||||
}
|
||||
|
||||
fn symlinkat(path1: CStr, fd: c_int, path2: CStr) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user