98 auto closedir = [](DIR * d)
105 std::string path(
"/proc/");
106 path += std::to_string(getpid());
108 DIR * d(opendir(path.c_str()));
109 std::unique_ptr<DIR,
decltype(closedir)> auto_close(d, closedir);
113 dirent
const * ent(readdir(d));
119 char const * basename(ent->d_name);
120 if(basename[0] ==
'.')
126 if(basename[0] >=
'0'
127 && basename[0] <=
'2'
128 && basename[1] ==
'\0')
134 int const fd(std::atoi(basename));
143 if(allowed.find(fd) == allowed.end())
146 ssize_t
const l(readlink((path +
'/' + basename).c_str(), link,
sizeof(link) - 1));
156 <<
"warning: file descriptor "
160 <<
") leaked on invocation. Parent PID "
174 throw file_inherited(
"found unexpected file descriptor leaks.");