* 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:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user