* 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:
R Aadarsh
2026-05-16 15:12:34 +05:30
parent ad83227225
commit e3d2257f64
4 changed files with 44 additions and 4 deletions
+27 -1
View File
@@ -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 {
+3 -1
View File
@@ -79,8 +79,10 @@ fn spawn(
if let Some(pid) = pid {
*pid = v;
}
})
})?;
}
Ok(())
}
#[unsafe(no_mangle)]