From 81ad643b008560074c31864c910c9b846ebe600e Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 7 Feb 2023 15:48:11 +0800 Subject: [PATCH] ec use locations. --- include/boost/process/v2/cstring_ref.hpp | 2 +- include/boost/process/v2/detail/config.hpp | 29 +++++++- .../v2/detail/impl/environment_posix.ipp | 6 +- .../v2/detail/impl/environment_win.ipp | 12 ++-- .../process/v2/detail/impl/last_error.ipp | 14 ---- .../v2/detail/impl/process_handle_windows.ipp | 31 ++++---- include/boost/process/v2/detail/impl/utf8.ipp | 20 +++--- .../boost/process/v2/detail/last_error.hpp | 7 +- include/boost/process/v2/exit_code.hpp | 2 +- .../process/v2/ext/detail/impl/proc_info.ipp | 10 +-- include/boost/process/v2/ext/impl/cmd.ipp | 44 ++++++------ include/boost/process/v2/ext/impl/cwd.ipp | 18 ++--- include/boost/process/v2/ext/impl/env.ipp | 22 +++--- include/boost/process/v2/ext/impl/exe.ipp | 10 +-- include/boost/process/v2/impl/pid.ipp | 72 +++++++++---------- include/boost/process/v2/impl/shell.ipp | 6 +- .../process/v2/posix/default_launcher.hpp | 12 ++-- .../v2/posix/fork_and_forget_launcher.hpp | 4 +- .../process/v2/posix/pdfork_launcher.hpp | 12 ++-- .../boost/process/v2/posix/vfork_launcher.hpp | 4 +- include/boost/process/v2/stdio.hpp | 10 ++- .../process/v2/windows/as_user_launcher.hpp | 2 +- .../process/v2/windows/default_launcher.hpp | 2 +- .../v2/windows/with_logon_launcher.hpp | 2 +- .../v2/windows/with_token_launcher.hpp | 2 +- test/v2/pid.cpp | 2 - 26 files changed, 189 insertions(+), 168 deletions(-) diff --git a/include/boost/process/v2/cstring_ref.hpp b/include/boost/process/v2/cstring_ref.hpp index 72c544487..42a374f48 100644 --- a/include/boost/process/v2/cstring_ref.hpp +++ b/include/boost/process/v2/cstring_ref.hpp @@ -106,7 +106,7 @@ struct basic_cstring_ref BOOST_CXX14_CONSTEXPR const_reference at(size_type pos) const { if (pos >= size()) - throw std::out_of_range("cstring-view out of range"); + throw_exception(std::out_of_range("cstring-view out of range")); return view_[pos]; } BOOST_CONSTEXPR const_reference front() const {return *view_;} diff --git a/include/boost/process/v2/detail/config.hpp b/include/boost/process/v2/detail/config.hpp index 4febb8ca7..0c985d181 100644 --- a/include/boost/process/v2/detail/config.hpp +++ b/include/boost/process/v2/detail/config.hpp @@ -97,6 +97,14 @@ namespace filesystem = std::filesystem; using std::quoted; using std::optional; +#define BOOST_PROCESS_V2_RETURN_EC(ev) \ + return ::BOOST_PROCESS_V2_NAMESPACE::error_code(ev, ::BOOST_PROCESS_V2_NAMESPACE::system_category()); \ + +#define BOOST_PROCESS_V2_ASSIGN_EC(ec, ...) ec.assign(__VA_ARGS__); +#define BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) \ + ec.assign(::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error()); \ + + #else using boost::system::error_code ; @@ -112,6 +120,25 @@ namespace filesystem = std::filesystem; namespace filesystem = boost::filesystem; #endif +#define BOOST_PROCESS_V2_RETURN_EC(ev) \ +{ \ + static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \ + return ::BOOST_PROCESS_V2_NAMESPACE::error_code(ev, ::BOOST_PROCESS_V2_NAMESPACE::system_category(), &loc##__LINE__); \ +} + +#define BOOST_PROCESS_V2_ASSIGN_EC(ec, ...) \ +{ \ + static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \ + ec.assign(__VA_ARGS__, &loc##__LINE__); \ +} + +#define BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) \ +{ \ + static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \ + ec.assign(::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(), &loc##__LINE__); \ +} + + #endif BOOST_PROCESS_V2_END_NAMESPACE @@ -150,6 +177,4 @@ BOOST_PROCESS_V2_END_NAMESPACE #define BOOST_PROCESS_V2_HAS_PROCESS_HANDLE 1 #endif - - #endif //BOOST_PROCESS_V2_DETAIL_CONFIG_HPP diff --git a/include/boost/process/v2/detail/impl/environment_posix.ipp b/include/boost/process/v2/detail/impl/environment_posix.ipp index 7d9ad564a..0f76b816f 100644 --- a/include/boost/process/v2/detail/impl/environment_posix.ipp +++ b/include/boost/process/v2/detail/impl/environment_posix.ipp @@ -34,7 +34,7 @@ basic_cstring_ref> get( auto res = ::getenv(key.c_str()); if (res == nullptr) { - ec.assign(ENOENT, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category()) return {}; } return res; @@ -45,13 +45,13 @@ void set(basic_cstring_ref> key, error_code & ec) { if (::setenv(key.c_str(), value.c_str(), true)) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void unset(basic_cstring_ref> key, error_code & ec) { if (::unsetenv(key.c_str())) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } diff --git a/include/boost/process/v2/detail/impl/environment_win.ipp b/include/boost/process/v2/detail/impl/environment_win.ipp index 37e72dc26..86792f2e3 100644 --- a/include/boost/process/v2/detail/impl/environment_win.ipp +++ b/include/boost/process/v2/detail/impl/environment_win.ipp @@ -50,7 +50,7 @@ std::basic_string> get( buf.resize(size); if (buf.size() == 0) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return buf; } @@ -60,14 +60,14 @@ void set(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableW(key.c_str(), value.c_str())) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void unset(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableW(key.c_str(), nullptr)) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } @@ -88,7 +88,7 @@ std::basic_string> get( buf.resize(size); if (buf.size() == 0) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return buf; } @@ -98,14 +98,14 @@ void set(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableA(key.c_str(), value.c_str())) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void unset(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableA(key.c_str(), nullptr)) - ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } diff --git a/include/boost/process/v2/detail/impl/last_error.ipp b/include/boost/process/v2/detail/impl/last_error.ipp index f9c294c25..8254fdb63 100644 --- a/include/boost/process/v2/detail/impl/last_error.ipp +++ b/include/boost/process/v2/detail/impl/last_error.ipp @@ -28,20 +28,6 @@ error_code get_last_error() } -void throw_last_error() -{ - throw system_error(get_last_error()); -} -void throw_last_error(const char * msg) -{ - throw system_error(get_last_error(), msg); -} -void throw_last_error(const std::string & msg) -{ - throw system_error(get_last_error(), msg); -} - - } BOOST_PROCESS_V2_END_NAMESPACE diff --git a/include/boost/process/v2/detail/impl/process_handle_windows.ipp b/include/boost/process/v2/detail/impl/process_handle_windows.ipp index 638bc0141..535bc011d 100644 --- a/include/boost/process/v2/detail/impl/process_handle_windows.ipp +++ b/include/boost/process/v2/detail/impl/process_handle_windows.ipp @@ -34,7 +34,7 @@ void get_exit_code_( error_code & ec) { if (!::GetExitCodeProcess(handle, &exit_code)) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } @@ -42,7 +42,12 @@ HANDLE open_process_(DWORD pid) { auto proc = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, pid); if (proc == nullptr) - detail::throw_last_error("open_process()"); + { + error_code ec; + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + throw system_error(ec, "open_process()"); + } + return proc; } @@ -61,7 +66,7 @@ bool check_handle_(HANDLE handle, error_code & ec) { if (handle == INVALID_HANDLE_VALUE) { - ec.assign(ERROR_INVALID_HANDLE_STATE, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()) return false; } return true; @@ -71,7 +76,7 @@ bool check_pid_(pid_type pid_, error_code & ec) { if (pid_ == 0) { - ec.assign(ERROR_INVALID_HANDLE_STATE, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()) return false; } return true; @@ -94,7 +99,7 @@ static BOOL CALLBACK enum_window(HWND hwnd, LPARAM param) LRESULT res = ::SendMessageW(hwnd, WM_CLOSE, 0, 0); if (res) - data->ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(data->ec) return res == 0; } @@ -103,25 +108,25 @@ void request_exit_(pid_type pid_, error_code & ec) enum_windows_data_t data{ec, pid_}; if (!::EnumWindows(enum_window, reinterpret_cast(&data))) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void interrupt_(pid_type pid_, error_code & ec) { if (!::GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid_)) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void terminate_(HANDLE handle, error_code & ec, DWORD & exit_status) { if (!::TerminateProcess(handle, 260)) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void check_running_(HANDLE handle, error_code & ec, DWORD & exit_status) { if (!::GetExitCodeProcess(handle, &exit_status)) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } #if !defined(BOOST_PROCESS_V2_DISABLE_UNDOCUMENTED_API) @@ -130,7 +135,7 @@ void suspend_(HANDLE handle, error_code & ec) auto nt_err = NtSuspendProcess(handle); ULONG dos_err = RtlNtStatusToDosError(nt_err); if (dos_err) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } void resume_(HANDLE handle, error_code & ec) @@ -138,17 +143,17 @@ void resume_(HANDLE handle, error_code & ec) auto nt_err = NtResumeProcess(handle); ULONG dos_err = RtlNtStatusToDosError(nt_err); if (dos_err) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } #else void suspend_(HANDLE, error_code & ec) { - ec.assign(ERROR_CALL_NOT_IMPLEMENTED, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_CALL_NOT_IMPLEMENTED, system_category()) } void resume_(HANDLE handle, error_code & ec) { - ec.assign(ERROR_CALL_NOT_IMPLEMENTED, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_CALL_NOT_IMPLEMENTED, system_category()) } #endif diff --git a/include/boost/process/v2/detail/impl/utf8.ipp b/include/boost/process/v2/detail/impl/utf8.ipp index 22623df69..5a3c20913 100644 --- a/include/boost/process/v2/detail/impl/utf8.ipp +++ b/include/boost/process/v2/detail/impl/utf8.ipp @@ -27,13 +27,13 @@ inline void handle_error(error_code & ec) switch (err) { case ERROR_INSUFFICIENT_BUFFER: - ec.assign(error::insufficient_buffer, error::utf8_category); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::utf8_category) break; case ERROR_NO_UNICODE_TRANSLATION: - ec.assign(error::invalid_character, error::utf8_category); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::utf8_category) break; default: - ec.assign(err, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) } } @@ -242,7 +242,7 @@ std::size_t convert_to_utf8(const wchar_t * in, std::size_t size, if (*from > max_wchar) { from_next = from; to_next = to; - ec.assign(error::invalid_character, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) return 0u; } @@ -270,7 +270,7 @@ std::size_t convert_to_utf8(const wchar_t * in, std::size_t size, if (to == to_end && i != cont_octet_count) { from_next = from; to_next = to - (i + 1); - ec.assign(error::insufficient_buffer, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) return 0u; } ++from; @@ -280,7 +280,7 @@ std::size_t convert_to_utf8(const wchar_t * in, std::size_t size, // Were we done or did we run out of destination space if (from != from_end) - ec.assign(error::insufficient_buffer, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) return to_next - out; } @@ -315,7 +315,7 @@ std::size_t convert_to_wide(const char * in, std::size_t size, if (invalid_leading_octet(*from)) { from_next = from; to_next = to; - ec.assign(error::invalid_character, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) return 0u; } @@ -339,7 +339,7 @@ std::size_t convert_to_wide(const char * in, std::size_t size, if (invalid_continuing_octet(*from)) { from_next = from; to_next = to; - ec.assign(error::invalid_character, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) return 0u; } @@ -356,7 +356,7 @@ std::size_t convert_to_wide(const char * in, std::size_t size, // rewind "from" to before the current character translation from_next = from - (i + 1); to_next = to; - ec.assign(error::insufficient_buffer, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) return 0u; } *to++ = ucs_result; @@ -365,7 +365,7 @@ std::size_t convert_to_wide(const char * in, std::size_t size, to_next = to; if (from != from_end) - ec.assign(error::insufficient_buffer, error::get_utf8_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) return to_next - out; } diff --git a/include/boost/process/v2/detail/last_error.hpp b/include/boost/process/v2/detail/last_error.hpp index 05e09ee0a..6b2d70f66 100644 --- a/include/boost/process/v2/detail/last_error.hpp +++ b/include/boost/process/v2/detail/last_error.hpp @@ -9,14 +9,13 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE -namespace detail { +namespace detail +{ BOOST_PROCESS_V2_DECL error_code get_last_error(); -BOOST_PROCESS_V2_DECL void throw_last_error(); -BOOST_PROCESS_V2_DECL void throw_last_error(const char * msg); -BOOST_PROCESS_V2_DECL void throw_last_error(const std::string & msg); } + BOOST_PROCESS_V2_END_NAMESPACE #if defined(BOOST_PROCESS_V2_HEADER_ONLY) diff --git a/include/boost/process/v2/exit_code.hpp b/include/boost/process/v2/exit_code.hpp index 5ac307030..3835d9f94 100644 --- a/include/boost/process/v2/exit_code.hpp +++ b/include/boost/process/v2/exit_code.hpp @@ -148,7 +148,7 @@ struct code_as_error_handler void operator()(error_code ec, native_exit_code_type code) { if (!ec) - ec.assign(code, category); + BOOST_PROCESS_V2_ASSIGN_EC(ec, code, category) std::move(handler_)(ec); } diff --git a/include/boost/process/v2/ext/detail/impl/proc_info.ipp b/include/boost/process/v2/ext/detail/impl/proc_info.ipp index ba866735a..4de38dad6 100644 --- a/include/boost/process/v2/ext/detail/impl/proc_info.ipp +++ b/include/boost/process/v2/ext/detail/impl/proc_info.ipp @@ -48,19 +48,19 @@ std::wstring cwd_cmd_from_proc(HANDLE proc, int type, boost::system::error_code if (error) { - ec.assign(error, boost::system::system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, boost::system::system_category()) return {}; } if (!ReadProcessMemory(proc, pbi.PebBaseAddress, &peb, sizeof(peb), &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } if (!ReadProcessMemory(proc, peb.ProcessParameters, &upp, sizeof(upp), &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -79,7 +79,7 @@ std::wstring cwd_cmd_from_proc(HANDLE proc, int type, boost::system::error_code if (!ReadProcessMemory(proc, buf, &buffer[0], len, &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -112,7 +112,7 @@ HANDLE open_process_with_debug_privilege(boost::process::v2::pid_type pid, boost if (!proc) proc = OpenProcess(PROCESS_ALL_ACCESS, false, pid); if (!proc) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return proc; } #endif diff --git a/include/boost/process/v2/ext/impl/cmd.ipp b/include/boost/process/v2/ext/impl/cmd.ipp index efe201935..614e6919c 100644 --- a/include/boost/process/v2/ext/impl/cmd.ipp +++ b/include/boost/process/v2/ext/impl/cmd.ipp @@ -146,7 +146,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) else return cmd(proc.get(), ec); @@ -161,7 +161,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto size = sizeof(argmax); if (sysctl(mib, 2, &argmax, &size, nullptr, 0) == -1) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -174,7 +174,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (sysctl(mib, 3, &*procargs.begin(), &size, nullptr, 0) != 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -191,7 +191,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto e = std::find(itr, end, '\0'); if (e == end && n < argc) // something off { - ec.assign(EINVAL, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()) return {}; } argv[n] = &*itr; @@ -216,7 +216,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto r = ::read(f, &*(procargs.end() - 4096), 4096); if (r < 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) ::close(f); return {}; } @@ -247,7 +247,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto e = std::find(itr, end, '\0'); if (e == end && n < argc) // something off { - ec.assign(EINVAL, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()) return {}; } argv[n] = &*itr; @@ -273,7 +273,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) std::unique_ptr proc_stat{procstat_open_sysctl()}; if (!proc_stat) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -294,14 +294,14 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (!proc_info) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } char **cmd = procstat_getargv(proc_stat.get(), proc_info.get(), 0); if (!cmd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } auto res = make_cmd_shell_::clone(cmd); @@ -326,17 +326,17 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; - if (!kd) {ec = detail::get_last_error(); return {};} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) { char **cmd = kvm_getargv(kd.get(), proc_info, 0); if (cmd) return make_cmd_shell_::clone(cmd); else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -358,17 +358,17 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; - if (!kd) {ec = detail::get_last_error(); return vec;} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;} if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &cntp))) { char **cmd = kvm_getargv2(kd.get(), proc_info, 0); if (cmd) return make_cmd_shell_::clone(cmd); else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -389,17 +389,17 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; - if (!kd) {ec = detail::get_last_error(); return vec;} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;} if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp))) { char **cmd = kvm_getargv(kd.get(), proc_info, 0); if (cmd) return make_cmd_shell_::clone(cmd); else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) kvm_close(kd); return {}; } @@ -412,7 +412,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) proc *proc_info = nullptr; user *proc_user = nullptr; kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); - if (!kd) {ec = detail::get_last_error(); return {};} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} if ((proc_info = kvm_getproc(kd, pid))) { if ((proc_user = kvm_getu(kd, proc_info))) @@ -427,13 +427,13 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) +[](int, char ** argv) {::free(argv);}) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) kvm_close(kd); return {}; diff --git a/include/boost/process/v2/ext/impl/cwd.ipp b/include/boost/process/v2/ext/impl/cwd.ipp index 0afb14c1e..a73dbbcdb 100644 --- a/include/boost/process/v2/ext/impl/cwd.ipp +++ b/include/boost/process/v2/ext/impl/cwd.ipp @@ -66,7 +66,7 @@ filesystem::path cwd(HANDLE proc, boost::system::error_code & ec) if (!buffer.empty()) return filesystem::canonical(buffer, ec); else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ""; } @@ -81,7 +81,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) else return cwd(proc.get(), ec); return {}; @@ -104,7 +104,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code if (proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi)) > 0) return filesystem::canonical(vpi.pvi_cdir.vip_path, ec); else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ""; } @@ -139,15 +139,15 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code procstat_freefiles(proc_stat, head); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) procstat_freeprocs(proc_stat, proc_info); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) procstat_close(proc_stat); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return path; } @@ -177,11 +177,11 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code path = filesystem::canonical(str.c_str(), ec); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) pclose(fp); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return path; } @@ -207,7 +207,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code filesystem::canonical(strbuff, ec); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } return ""; diff --git a/include/boost/process/v2/ext/impl/env.ipp b/include/boost/process/v2/ext/impl/env.ipp index e4eee7dc7..a6d87e6fc 100644 --- a/include/boost/process/v2/ext/impl/env.ipp +++ b/include/boost/process/v2/ext/impl/env.ipp @@ -153,19 +153,19 @@ env_view env(HANDLE proc, boost::system::error_code & ec) if (error) { - ec.assign(error, boost::system::system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, boost::system::system_category()) return {}; } if (!ReadProcessMemory(proc, pbi.PebBaseAddress, &peb, sizeof(peb), &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } if (!ReadProcessMemory(proc, peb.ProcessParameters, &upp, sizeof(upp), &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -176,7 +176,7 @@ env_view env(HANDLE proc, boost::system::error_code & ec) if (!ReadProcessMemory(proc, buf, ev.handle_.get(), len, &nRead)) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -204,7 +204,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) else return env(proc.get(), ec); @@ -220,7 +220,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto size = sizeof(argmax); if (sysctl(mib, 2, &argmax, &size, nullptr, 0) == -1) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } @@ -233,7 +233,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (sysctl(mib, 3, &*procargs.begin(), &size, nullptr, 0) != 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } std::uint32_t nargs; @@ -291,7 +291,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) auto r = ::read(f, buf.get() + size, 4096); if (r < 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) ::close(f); return {}; } @@ -358,18 +358,18 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) ev.handle_.reset(eeo); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) } procstat_freeprocs(proc_stat, proc_info); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) procstat_close(proc_stat); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ev; } diff --git a/include/boost/process/v2/ext/impl/exe.ipp b/include/boost/process/v2/ext/impl/exe.ipp index 18f981bc5..8b5bd9933 100644 --- a/include/boost/process/v2/ext/impl/exe.ipp +++ b/include/boost/process/v2/ext/impl/exe.ipp @@ -77,7 +77,7 @@ filesystem::path exe(HANDLE proc, boost::system::error_code & ec) return filesystem::canonical(buffer, ec); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ""; } @@ -103,7 +103,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) else return exe(proc.get(), ec); } @@ -119,7 +119,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code { return filesystem::canonical(buffer, ec); } - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ""; } @@ -159,7 +159,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code } } - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ""; } @@ -167,7 +167,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - ec.assign(ENOTSUP, boost::system::system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) return ""; } diff --git a/include/boost/process/v2/impl/pid.ipp b/include/boost/process/v2/impl/pid.ipp index aa3d164b7..61e848bb3 100644 --- a/include/boost/process/v2/impl/pid.ipp +++ b/include/boost/process/v2/impl/pid.ipp @@ -73,7 +73,7 @@ std::vector all_pids(boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } PROCESSENTRY32 pe; @@ -95,7 +95,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } PROCESSENTRY32 pe; @@ -122,7 +122,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } PROCESSENTRY32 pe; @@ -150,7 +150,7 @@ std::vector all_pids(boost::system::error_code & ec) vec.reserve(proc_listpids(PROC_ALL_PIDS, 0, nullptr, 0)); if (proc_listpids(PROC_ALL_PIDS, 0, &vec[0], sizeof(pid_type) * vec.size())) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } auto itr = std::partition(vec.begin(), vec.end(), [](pid_type pt) {return pt != 0;}); @@ -165,7 +165,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) proc_bsdinfo proc_info; if (proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &proc_info, sizeof(proc_info)) <= 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } else @@ -179,7 +179,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) vec.reserve(proc_listpids(PROC_PPID_ONLY, (uint32_t)pid, nullptr, 0)); if (proc_listpids(PROC_PPID_ONLY, (uint32_t)pid, &vec[0], sizeof(pid_type) * vec.size())) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {}; } auto itr = std::partition(vec.begin(), vec.end(), [](pid_type pt) {return pt != 0;}); @@ -196,7 +196,7 @@ std::vector all_pids(boost::system::error_code & ec) DIR *proc = opendir("/proc"); if (!proc) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } struct dirent *ent = nullptr; @@ -218,7 +218,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) FILE *stat = fopen(buffer, "r"); if (!stat) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } else @@ -243,7 +243,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) if (!token) { fclose(stat); - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } } @@ -284,7 +284,7 @@ std::vector all_pids(boost::system::error_code & ec) free(proc_info); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -298,7 +298,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) free(proc_info); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } @@ -320,7 +320,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) free(proc_info); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -344,7 +344,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) @@ -355,7 +355,7 @@ std::vector all_pids(boost::system::error_code & ec) vec.push_back(proc_info[i].kp_pid); } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -377,7 +377,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) @@ -388,7 +388,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } @@ -410,7 +410,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) @@ -425,7 +425,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -447,7 +447,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &cntp))) @@ -459,7 +459,7 @@ std::vector all_pids(boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -479,7 +479,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &cntp))) @@ -487,7 +487,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } @@ -507,7 +507,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &cntp))) @@ -522,7 +522,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -544,7 +544,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &cntp))) @@ -559,7 +559,7 @@ std::vector all_pids(boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -579,7 +579,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp))) @@ -587,7 +587,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } @@ -607,7 +607,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &cntp))) @@ -622,7 +622,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } @@ -645,7 +645,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } while ((proc_info = kvm_nextproc(kd))) @@ -656,7 +656,7 @@ std::vector all_pids(boost::system::error_code & ec) } else { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) break; } } @@ -678,7 +678,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } if ((proc_info = kvm_getproc(kd, pid))) @@ -686,7 +686,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ppid; } @@ -706,7 +706,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); if (!kd) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec; } while ((proc_info = kvm_nextproc(kd))) @@ -719,7 +719,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } else { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) break; } } diff --git a/include/boost/process/v2/impl/shell.ipp b/include/boost/process/v2/impl/shell.ipp index 12a9fa2c3..da78404f7 100644 --- a/include/boost/process/v2/impl/shell.ipp +++ b/include/boost/process/v2/impl/shell.ipp @@ -69,7 +69,11 @@ void shell::parse_() { argv_ = ::CommandLineToArgvW(input_.c_str(), &argc_); if (argv_ == nullptr) - detail::throw_last_error(); + { + error_code ec; + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + throw system_error(ec, "shell::parse"); + } } shell::~shell() diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index a2bb3b6cf..f07d64fd8 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -364,12 +364,12 @@ struct default_launcher pipe_guard pg; if (::pipe(pg.p)) { - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC)) { - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } ec = detail::on_setup(*this, executable, argv, inits ...); @@ -390,7 +390,7 @@ struct default_launcher detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } else if (pid == 0) @@ -406,7 +406,7 @@ struct default_launcher ::execve(executable.c_str(), const_cast(argv), const_cast(env)); ignore_unused(::write(pg.p[1], &errno, sizeof(int))); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) detail::on_exec_error(*this, executable, argv, ec, inits...); ::exit(EXIT_FAILURE); return basic_process{exec}; @@ -422,12 +422,12 @@ struct default_launcher int err = errno; if ((err != EAGAIN) && (err != EINTR)) { - ec.assign(err, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) break; } } if (count != 0) - ec.assign(child_error, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()) if (ec) { diff --git a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp index 1b92b5d7e..d97557f18 100644 --- a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp +++ b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp @@ -94,7 +94,7 @@ struct fork_and_forget_launcher : default_launcher detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } else if (pid == 0) @@ -107,7 +107,7 @@ struct fork_and_forget_launcher : default_launcher if (!ec) ::execve(executable.c_str(), const_cast(argv), const_cast(env)); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) detail::on_exec_error(*this, executable, argv, ec, inits...); ::exit(EXIT_FAILURE); return basic_process{exec}; diff --git a/include/boost/process/v2/posix/pdfork_launcher.hpp b/include/boost/process/v2/posix/pdfork_launcher.hpp index 80f79c93c..1f6d7ffce 100644 --- a/include/boost/process/v2/posix/pdfork_launcher.hpp +++ b/include/boost/process/v2/posix/pdfork_launcher.hpp @@ -85,12 +85,12 @@ struct pdfork_launcher : default_launcher pipe_guard pg; if (::pipe(pg.p)) { - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC)) { - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } ec = detail::on_setup(*this, executable, argv, inits ...); @@ -111,7 +111,7 @@ struct pdfork_launcher : default_launcher detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } else if (pid == 0) @@ -128,7 +128,7 @@ struct pdfork_launcher : default_launcher ::execve(executable.c_str(), const_cast(argv), const_cast(env)); default_launcher::ignore_unused(::write(pg.p[1], &errno, sizeof(int))); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) detail::on_exec_error(*this, executable, argv, ec, inits...); ::exit(EXIT_FAILURE); return basic_process{exec}; @@ -143,12 +143,12 @@ struct pdfork_launcher : default_launcher int err = errno; if ((err != EAGAIN) && (err != EINTR)) { - ec.assign(err, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) break; } } if (count != 0) - ec.assign(child_error, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()) if (ec) { diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index fde3842a5..d156aad3e 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -96,7 +96,7 @@ struct vfork_launcher : default_launcher detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) return basic_process{exec}; } else if (pid == 0) @@ -108,7 +108,7 @@ struct vfork_launcher : default_launcher if (!ec) ::execve(executable.c_str(), const_cast(argv), const_cast(env)); - ec.assign(errno, system_category()); + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) detail::on_exec_error(*this, executable, argv, ec, inits...); ::exit(EXIT_FAILURE); return basic_process{exec}; diff --git a/include/boost/process/v2/stdio.hpp b/include/boost/process/v2/stdio.hpp index df373afc4..f211fba22 100644 --- a/include/boost/process/v2/stdio.hpp +++ b/include/boost/process/v2/stdio.hpp @@ -69,7 +69,11 @@ struct process_io_binding { DWORD res; if (!::GetHandleInformation(h, &res)) - detail::throw_last_error("get_flags"); + { + error_code ec; + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + throw system_error(ec, "get_flags"); + } return res; } @@ -176,7 +180,7 @@ struct process_io_binding fd = p[1]; if (::fcntl(p[0], F_SETFD, FD_CLOEXEC) == -1) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ; } fd_needs_closing = true; @@ -195,7 +199,7 @@ struct process_io_binding fd = p[0]; if (::fcntl(p[1], F_SETFD, FD_CLOEXEC) == -1) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return ; } fd_needs_closing = true; diff --git a/include/boost/process/v2/windows/as_user_launcher.hpp b/include/boost/process/v2/windows/as_user_launcher.hpp index cf1c8b712..c1b1e30b0 100644 --- a/include/boost/process/v2/windows/as_user_launcher.hpp +++ b/include/boost/process/v2/windows/as_user_launcher.hpp @@ -107,7 +107,7 @@ struct as_user_launcher : default_launcher if (ok == 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index 6b71202e4..1ce0fe0e1 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -314,7 +314,7 @@ struct default_launcher auto ec__ = detail::get_last_error(); if (ok == 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/with_logon_launcher.hpp b/include/boost/process/v2/windows/with_logon_launcher.hpp index c18a02631..df8e82287 100644 --- a/include/boost/process/v2/windows/with_logon_launcher.hpp +++ b/include/boost/process/v2/windows/with_logon_launcher.hpp @@ -111,7 +111,7 @@ struct with_logon_launcher : default_launcher if (ok == 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/with_token_launcher.hpp b/include/boost/process/v2/windows/with_token_launcher.hpp index c3e8383c5..2775f7774 100644 --- a/include/boost/process/v2/windows/with_token_launcher.hpp +++ b/include/boost/process/v2/windows/with_token_launcher.hpp @@ -106,7 +106,7 @@ struct with_token_launcher : default_launcher if (ok == 0) { - ec = detail::get_last_error(); + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/test/v2/pid.cpp b/test/v2/pid.cpp index aa77177fd..532bfd489 100644 --- a/test/v2/pid.cpp +++ b/test/v2/pid.cpp @@ -19,7 +19,6 @@ BOOST_AUTO_TEST_CASE(test_pid) auto all = bp2::all_pids(); auto itr = std::find(all.begin(), all.end(), bp2::current_pid()); -#if !defined(__APPLE___) && !defined(__MACH__) BOOST_CHECK_GT(all.size(), 0u); BOOST_CHECK(itr != all.end()); @@ -39,6 +38,5 @@ BOOST_AUTO_TEST_CASE(test_pid) return (!children.empty() || !grand_children.empty()); }; BOOST_CHECK_NE(grand_child_pids(bp2::root_pid, children, grand_children), false); -#endif }