While searching the fd directory using std::filesystem::directory_iterator,
we can close the file descriptor of the directory_iterator. In this case,
the std::filesystem::filesystem_error exception will be thrown.
To avoid throwing the exception, the method uses std::vector to store
file descriptors. And then, the method closes all file descriptors using
the vector.
Change-Id: I281ba065ec1a8b90d90791a31f4abe3e4724fad3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
if (aul_listen_fd != nullptr)
aul_fd = atoi(aul_listen_fd);
+ std::vector<int> fds;
try {
fs::path proc_path("/proc/self/fd");
for (const auto& entry : fs::directory_iterator(proc_path)) {
if (fd < 3 || fd == aul_fd)
continue;
- close(fd);
+ fds.push_back(fd);
}
+
+ for (auto fd : fds)
+ close(fd);
} catch (const fs::filesystem_error& e) {
_E("Execption occurs. error(%s)", e.what());
}