in xar/XarMacOS.cpp [40:54]
void tools::xar::close_non_std_fds() {
// Get list of pids (and their types).
int buffer_size = proc_pidinfo(getpid(), PROC_PIDLISTFDS, 0, nullptr, 0);
XAR_PCHECK_SIMPLE(buffer_size > -1);
auto num_pids = static_cast<size_t>(buffer_size) / sizeof(proc_fdinfo);
std::vector<proc_fdinfo> proc_fds(num_pids, proc_fdinfo{});
proc_pidinfo(getpid(), PROC_PIDLISTFDS, 0, proc_fds.data(), buffer_size);
// Close each fd, but only if it's PROX_FDTYPE_VNODE and not any of [0, 1, 2].
for (auto fd : proc_fds) {
if (fd.proc_fdtype == PROX_FDTYPE_VNODE && fd.proc_fd > 2) {
close(fd.proc_fd);
}
}
}