Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions include/boost/process/v1/detail/posix/handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ inline std::vector<native_handle_type> get_handles(std::error_code & ec)
std::unique_ptr<DIR, void(*)(DIR*)> 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();
Expand Down Expand Up @@ -60,7 +64,7 @@ inline std::vector<native_handle_type> 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;
}
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/posix/close_handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ void close_all(const std::vector<int> & whitelist, error_code & ec)
std::unique_ptr<DIR, void(*)(DIR*)> 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());
Expand Down
Loading