This commit is contained in:
pjht 2024-11-24 16:34:00 -06:00
parent a6f70cd09c
commit 7fdba5b51c
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 39 additions and 24 deletions

View File

@ -110,39 +110,54 @@ pub fn spawn(
let stdin = match self.stdin.take() { let stdin = match self.stdin.take() {
Some(Stdio::Null) => None, Some(Stdio::Null) => None,
None | Some(Stdio::Inherit) => { None | Some(Stdio::Inherit) => {
STDIN.get().unwrap().as_ref().map(|file| { STDIN
let file = file.duplicate()?; .get()
let res = Ok::<_, io::Error>((file.fs_pid, file.fd)); .unwrap()
crate::mem::drop(file); // do not close the temporary file struct .as_ref()
res .map(|file| {
}).transpose()? let file = file.duplicate()?;
}, let res = Ok::<_, io::Error>((file.fs_pid, file.fd));
crate::mem::drop(file); // do not close the temporary file struct
res
})
.transpose()?
}
Some(Stdio::MakePipe) => todo!(), Some(Stdio::MakePipe) => todo!(),
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)), Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
}; };
let stdout = match self.stdout.take() { let stdout = match self.stdout.take() {
Some(Stdio::Null) => None, Some(Stdio::Null) => None,
None | Some(Stdio::Inherit) => { None | Some(Stdio::Inherit) => {
STDOUT.get().unwrap().as_ref().map(|file| { STDOUT
let file = file.duplicate()?; .get()
let res = Ok::<_, io::Error>((file.fs_pid, file.fd)); .unwrap()
crate::mem::drop(file); // do not close the temporary file struct .as_ref()
res .map(|file| {
}).transpose()? let file = file.duplicate()?;
}, let res = Ok::<_, io::Error>((file.fs_pid, file.fd));
crate::mem::drop(file); // do not close the temporary file struct
res
})
.transpose()?
}
Some(Stdio::MakePipe) => todo!(), Some(Stdio::MakePipe) => todo!(),
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)), Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
}; };
let stderr = match self.stderr.take() { let stderr = match self.stderr.take() {
Some(Stdio::Null) => None, Some(Stdio::Null) => None,
None | Some(Stdio::Inherit) => { None | Some(Stdio::Inherit) => {
STDERR.get().unwrap().as_ref().map(|file| { STDERR
let file = file.duplicate()?; .get()
let res = Ok::<_, io::Error>((file.fs_pid, file.fd)); .unwrap()
crate::mem::drop(file); // do not close the temporary file struct .as_ref()
res .map(|file| {
}).transpose()? let file = file.duplicate()?;
}, let res = Ok::<_, io::Error>((file.fs_pid, file.fd));
crate::mem::drop(file); // do not close the temporary file struct
res
})
.transpose()?
}
Some(Stdio::MakePipe) => todo!(), Some(Stdio::MakePipe) => todo!(),
Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)), Some(Stdio::InheritFile(file)) => Some((file.fs_pid, file.fd)),
}; };

View File

@ -97,7 +97,7 @@ pub fn init() {
}; };
let stdio: [Option<(u64, u64)>; 3] = let stdio: [Option<(u64, u64)>; 3] =
postcard::from_bytes(&rpc::send_call(proc_man_pid, 8, 1, &[]).get_return()).unwrap(); postcard::from_bytes(&rpc::send_call(proc_man_pid, 8, 1, &[]).get_return()).unwrap();
STDIN.get_or_init(|| stdio[0].map(|(fs_pid, fd)| File{fs_pid, fd})); STDIN.get_or_init(|| stdio[0].map(|(fs_pid, fd)| File { fs_pid, fd }));
STDOUT.get_or_init(|| stdio[1].map(|(fs_pid, fd)| File{fs_pid, fd})); STDOUT.get_or_init(|| stdio[1].map(|(fs_pid, fd)| File { fs_pid, fd }));
STDERR.get_or_init(|| stdio[2].map(|(fs_pid, fd)| File{fs_pid, fd})); STDERR.get_or_init(|| stdio[2].map(|(fs_pid, fd)| File { fs_pid, fd }));
} }