From f5748e36b3593226229df2b1cc3b4b51b698a79e Mon Sep 17 00:00:00 2001 From: AJIOB Date: Mon, 22 Dec 2025 10:18:10 +0300 Subject: [PATCH] Fix `/dev/fd` not found error --- .../boost/process/v1/detail/posix/handles.hpp | 18 +++++++++++++----- src/posix/close_handles.cpp | 8 ++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/boost/process/v1/detail/posix/handles.hpp b/include/boost/process/v1/detail/posix/handles.hpp index bd1b498e4..e87cc5f52 100644 --- a/include/boost/process/v1/detail/posix/handles.hpp +++ b/include/boost/process/v1/detail/posix/handles.hpp @@ -27,8 +27,12 @@ inline std::vector get_handles(std::error_code & ec) std::unique_ptr dir{::opendir("/dev/fd"), +[](DIR* p){::closedir(p);}}; if (!dir) { - ec = ::boost::process::v1::detail::get_last_error(); - return {}; + dir = {::opendir("/proc/self/fd"), +[](DIR* p){::closedir(p);}}; + if (!dir) + { + ec = ::boost::process::v1::detail::get_last_error(); + return {}; + } } else ec.clear(); @@ -60,7 +64,7 @@ inline std::vector get_handles() auto res = get_handles(ec); if (ec) - boost::process::v1::detail::throw_error(ec, "open_dir(\"/dev/fd\") failed"); + boost::process::v1::detail::throw_error(ec, "open_dir(\"/dev/fd\") and open_dir(\"/proc/self/fd\") failed"); return res; } @@ -113,8 +117,12 @@ struct limit_handles_ : handler_base_ext auto dir = ::opendir("/dev/fd"); if (!dir) { - exec.set_error(::boost::process::v1::detail::get_last_error(), "opendir(\"/dev/fd\")"); - return; + dir = ::opendir("/proc/self/fd"); + if (!dir) + { + exec.set_error(::boost::process::v1::detail::get_last_error(), "opendir(\"/proc/self/fd\")"); + return; + } } auto my_fd = dirfd(dir); diff --git a/src/posix/close_handles.cpp b/src/posix/close_handles.cpp index 5795a3b1c..b29b73e0c 100644 --- a/src/posix/close_handles.cpp +++ b/src/posix/close_handles.cpp @@ -181,8 +181,12 @@ void close_all(const std::vector & whitelist, error_code & ec) std::unique_ptr dir{::opendir("/dev/fd"), +[](DIR* p){::closedir(p);}}; if (dir.get() == nullptr) { - ec = BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); - return ; + dir = {::opendir("/proc/self/fd"), +[](DIR* p){::closedir(p);}}; + if (dir.get() == nullptr) + { + ec = BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + return ; + } } auto dir_fd = dirfd(dir.get());