mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 04:22:15 +00:00
ec use locations.
This commit is contained in:
@@ -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_;}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -34,7 +34,7 @@ basic_cstring_ref<char_type, value_char_traits<char>> 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<char_type, key_char_traits<char_type>> 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<char_type, key_char_traits<char_type>> 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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ std::basic_string<char_type, value_char_traits<char_type>> 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<char_type, key_char_traits<char_type>> 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<char_type, key_char_traits<char_type>> 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<char, value_char_traits<char>> 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<char, key_char_traits<char>> 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<char, key_char_traits<char>> 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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<LONG_PTR>(&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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -146,7 +146,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
|
||||
};
|
||||
std::unique_ptr<void, del> 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<struct procstat, cl_proc_stat> 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<kvm_t, closer> 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<kvm_t, closer> 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<kvm_t, closer> 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 {};
|
||||
|
||||
@@ -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<void, del> 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 "";
|
||||
|
||||
@@ -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<void, del> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void, del> 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 "";
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ std::vector<pid_type> 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<pid_type> 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<pid_type> 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<pid_type> 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<pid_type> 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<pid_type> 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<pid_type> 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<pid_type> all_pids(boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<kvm_t, closer> 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<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<pid_type> all_pids(boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<kvm_t, closer> 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<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<pid_type> all_pids(boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<kvm_t, closer> 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<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<pid_type> all_pids(boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> 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<kvm_t, closer> 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<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
|
||||
std::unique_ptr<kvm_t, closer> 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<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
|
||||
}
|
||||
else
|
||||
{
|
||||
ec = detail::get_last_error();
|
||||
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<Executor>{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<Executor>{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<Executor>{exec};
|
||||
}
|
||||
else if (pid == 0)
|
||||
@@ -406,7 +406,7 @@ struct default_launcher
|
||||
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(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<Executor>{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)
|
||||
{
|
||||
|
||||
@@ -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<Executor>{exec};
|
||||
}
|
||||
else if (pid == 0)
|
||||
@@ -107,7 +107,7 @@ struct fork_and_forget_launcher : default_launcher
|
||||
if (!ec)
|
||||
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(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<Executor>{exec};
|
||||
|
||||
@@ -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<Executor>{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<Executor>{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<Executor>{exec};
|
||||
}
|
||||
else if (pid == 0)
|
||||
@@ -128,7 +128,7 @@ struct pdfork_launcher : default_launcher
|
||||
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(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<Executor>{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)
|
||||
{
|
||||
|
||||
@@ -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<Executor>{exec};
|
||||
}
|
||||
else if (pid == 0)
|
||||
@@ -108,7 +108,7 @@ struct vfork_launcher : default_launcher
|
||||
if (!ec)
|
||||
::execve(executable.c_str(), const_cast<char * const *>(argv), const_cast<char * const *>(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<Executor>{exec};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user