MCPcopy Index your code
hub / github.com/RustPython/RustPython / close_filetable_fds

Function close_filetable_fds

crates/stdlib/src/posixsubprocess.rs:473–507  ·  view source on GitHub ↗
(keep: KeepFds<'_>)

Source from the content-addressed store, hash-verified

471
472#[cfg(target_os = "redox")]
473fn close_filetable_fds(keep: KeepFds<'_>) -> nix::Result<()> {
474 use nix::fcntl;
475 use std::os::fd::{FromRawFd, OwnedFd};
476 let filetable = fcntl::open(
477 c"/scheme/thisproc/current/filetable",
478 fcntl::OFlag::O_RDONLY,
479 nix::sys::stat::Mode::empty(),
480 )?;
481 let read_one = || -> nix::Result<_> {
482 let mut byte = 0;
483 let n = nix::unistd::read(&filetable, std::slice::from_mut(&mut byte))?;
484 Ok((n > 0).then_some(byte))
485 };
486 while let Some(c) = read_one()? {
487 let mut parser = IntParser::default();
488 if parser.feed(c).is_err() {
489 continue;
490 }
491 let done = loop {
492 let Some(c) = read_one()? else { break true };
493 if parser.feed(c).is_err() {
494 break false;
495 }
496 };
497
498 let fd = parser.num as i32;
499 if fd != filetable.as_raw_fd() && keep.should_keep(fd) {
500 let _ = unistd::close(fd);
501 }
502 if done {
503 break;
504 }
505 }
506 Ok(())
507}
508
509fn close_fds_brute_force(keep: KeepFds<'_>) {
510 let max_fd = nix::unistd::sysconf(nix::unistd::SysconfVar::OPEN_MAX)

Callers 1

close_fdsFunction · 0.85

Calls 7

is_errMethod · 0.80
should_keepMethod · 0.80
closeFunction · 0.70
openFunction · 0.50
readFunction · 0.50
feedMethod · 0.45
as_raw_fdMethod · 0.45

Tested by

no test coverage detected