in xar/XarLinux.cpp [38:54]
void tools::xar::close_non_std_fds() {
auto dir_fd = open("/proc/self/fd", O_RDONLY | O_DIRECTORY);
DIR* dir_handle = nullptr;
if (dir_fd >= 0 && (dir_handle = fdopendir(dir_fd))) {
for (auto dent = readdir(dir_handle); dent; dent = readdir(dir_handle)) {
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) {
continue;
}
int fd = std::atoi(dent->d_name);
if (fd != dir_fd && fd > 2) {
close(fd);
}
}
closedir(dir_handle);
}
}