/
usr
/
include
/
boost
/
process
/
detail
/
posix
/
/usr/include/boost/process/detail/posix
mkdir
upload
Name
Size
Mode
Actions
asio_fwd.hpp
1342
0644
edit
dl
rm
async_handler.hpp
1187
0644
edit
dl
rm
async_in.hpp
3541
0644
edit
dl
rm
async_out.hpp
5794
0644
edit
dl
rm
async_pipe.hpp
11386
0644
edit
dl
rm
basic_cmd.hpp
4551
0644
edit
dl
rm
basic_pipe.hpp
5660
0644
edit
dl
rm
child_handle.hpp
1432
0644
edit
dl
rm
close_in.hpp
1053
0644
edit
dl
rm
close_out.hpp
1735
0644
edit
dl
rm
cmd.hpp
2531
0644
edit
dl
rm
compare_handles.hpp
1029
0644
edit
dl
rm
environment.hpp
9960
0644
edit
dl
rm
env_init.hpp
979
0644
edit
dl
rm
exe.hpp
569
0644
edit
dl
rm
executor.hpp
15541
0644
edit
dl
rm
fd.hpp
2621
0644
edit
dl
rm
file_descriptor.hpp
1884
0644
edit
dl
rm
file_in.hpp
1407
0644
edit
dl
rm
file_out.hpp
2198
0644
edit
dl
rm
group_handle.hpp
2068
0644
edit
dl
rm
group_ref.hpp
1088
0644
edit
dl
rm
handler.hpp
1739
0644
edit
dl
rm
handles.hpp
3945
0644
edit
dl
rm
io_context_ref.hpp
4036
0644
edit
dl
rm
is_running.hpp
2304
0644
edit
dl
rm
null_in.hpp
1305
0644
edit
dl
rm
null_out.hpp
2089
0644
edit
dl
rm
on_exit.hpp
1001
0644
edit
dl
rm
pipe_in.hpp
2375
0644
edit
dl
rm
pipe_out.hpp
3091
0644
edit
dl
rm
search_path.hpp
1218
0644
edit
dl
rm
shell_path.hpp
878
0644
edit
dl
rm
sigchld_service.hpp
4102
0644
edit
dl
rm
signal.hpp
1898
0644
edit
dl
rm
start_dir.hpp
1093
0644
edit
dl
rm
terminate.hpp
1199
0644
edit
dl
rm
use_vfork.hpp
781
0644
edit
dl
rm
wait_for_exit.hpp
6689
0644
edit
dl
rm
wait_group.hpp
3423
0644
edit
dl
rm
Edit:
/usr/include/boost/process/detail/posix/handles.hpp
(3945B)
// Copyright (c) 2019 Klemens D. Morgenstern // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROCESS_DETAIL_POSIX_HANDLES_HPP_ #define BOOST_PROCESS_DETAIL_POSIX_HANDLES_HPP_ #include <vector> #include <system_error> #include <dirent.h> #include <sys/stat.h> #include <algorithm> #include <boost/process/detail/posix/handler.hpp> namespace boost { namespace process { namespace detail { namespace posix { using native_handle_type = int; inline std::vector<native_handle_type> get_handles(std::error_code & ec) { std::vector<native_handle_type> res; std::unique_ptr<DIR, void(*)(DIR*)> dir{::opendir("/dev/fd"), +[](DIR* p){::closedir(p);}}; if (!dir) { ec = ::boost::process::detail::get_last_error(); return {}; } else ec.clear(); auto my_fd = ::dirfd(dir.get()); struct ::dirent * ent_p; while ((ent_p = readdir(dir.get())) != nullptr) { if (ent_p->d_name[0] == '.') continue; const auto conv = std::atoi(ent_p->d_name); if (conv == 0 && (ent_p->d_name[0] != '0' && ent_p->d_name[1] != '\0')) continue; if (conv == my_fd) continue; res.push_back(conv); } return res; } inline std::vector<native_handle_type> get_handles() { std::error_code ec; auto res = get_handles(ec); if (ec) boost::process::detail::throw_error(ec, "open_dir(\"/dev/fd\") failed"); return res; } inline bool is_stream_handle(native_handle_type handle, std::error_code & ec) { struct ::stat stat_; if (::fstat(handle, &stat_) != 0) { ec = ::boost::process::detail::get_last_error(); } else ec.clear(); return S_ISCHR (stat_.st_mode) //This macro returns non-zero if the file is a character special file (a device like a terminal). || S_ISBLK (stat_.st_mode) // This macro returns non-zero if the file is a block special file (a device like a disk). || S_ISREG (stat_.st_mode) // This macro returns non-zero if the file is a regular file. || S_ISFIFO (stat_.st_mode) // This macro returns non-zero if the file is a FIFO special file, or a pipe. See section 15. Pipes and FIFOs. || S_ISSOCK (stat_.st_mode) ;// This macro returns non-zero if the file is a socket. See section 16. Sockets.; } inline bool is_stream_handle(native_handle_type handle) { std::error_code ec; auto res = is_stream_handle(handle, ec); if (ec) boost::process::detail::throw_error(ec, "fstat() failed"); return res; } struct limit_handles_ : handler_base_ext { limit_handles_() {} ~limit_handles_() {} mutable std::vector<int> used_handles; template<typename Executor> void on_setup(Executor & exec) const { used_handles = get_used_handles(exec); } template<typename Executor> void on_exec_setup(Executor & exec) const { auto dir = ::opendir("/dev/fd"); if (!dir) { exec.set_error(::boost::process::detail::get_last_error(), "opendir(\"/dev/fd\")"); return; } auto my_fd = ::dirfd(dir); struct ::dirent * ent_p; while ((ent_p = readdir(dir)) != nullptr) { if (ent_p->d_name[0] == '.') continue; const auto conv = std::atoi(ent_p->d_name); if ((conv == my_fd) || (conv == -1)) continue; if (std::find(used_handles.begin(), used_handles.end(), conv) != used_handles.end()) continue; if (::close(conv) != 0) { exec.set_error(::boost::process::detail::get_last_error(), "close() failed"); return; } } ::closedir(dir); } }; }}}} #endif //PROCESS_HANDLES_HPP
Save
cmd:
run