2
0
mirror of https://github.com/boostorg/process.git synced 2026-01-20 04:42:24 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Klemens Morgenstern
0d2da65866 ec use locations. 2023-02-08 00:10:20 +08:00
Klemens Morgenstern
7c3ba4b784 xproc fixes 2023-02-08 00:10:20 +08:00
38 changed files with 449 additions and 243 deletions

View File

@@ -8,4 +8,6 @@ A special thank you goes to [@http://www.intra2net.com/ Intra2net AG] (especiall
Great thanks also goes to Boris Schaeling, who despite having boost.process rejected, went on to work on it and maintained it up until this day and participated in the development of the current version.
Many Thanks, to [@https://github.com/time-killer-games Samuel Venable] for contributing the v2::ext functionality and all the research that went into it.
[endsect]

View File

@@ -263,7 +263,7 @@ public:
auto st1 = key + ::boost::process::detail::equal_sign<Char>();
while (*p != nullptr)
{
const auto len = std::char_traits<Char>::length(*p);
const int len = std::char_traits<Char>::length(*p);
if ((std::distance(st1.begin(), st1.end()) < len)
&& std::equal(st1.begin(), st1.end(), *p))
break;

View File

@@ -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_;}

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -101,9 +101,8 @@ struct basic_process_handle_signal
handle.pid_ = -1;
}
pid_type id() const
{ return pid_; }
native_handle_type native_handle() {return pid_;}
pid_type id() const { return pid_; }
native_handle_type native_handle() {return {};}
void terminate_if_running(error_code &)
{

View File

@@ -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);
}

View File

@@ -0,0 +1,16 @@
//
// Copyright (c) 2023 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_PROCESS_V2_EXT_HPP
#define BOOST_PROCESS_V2_EXT_HPP
#include <boost/process/v2/ext/cmd.hpp>
#include <boost/process/v2/ext/cwd.hpp>
#include <boost/process/v2/ext/env.hpp>
#include <boost/process/v2/ext/exe.hpp>
#endif //BOOST_PROCESS_V2_EXT_HPP

View File

@@ -20,7 +20,8 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace ext {
/// Get the argument vector from a given pid
/// @{
/// Get the argument vector of another process
BOOST_PROCESS_V2_DECL shell cmd(pid_type pid, error_code & ec);
BOOST_PROCESS_V2_DECL shell cmd(pid_type pid);
@@ -32,15 +33,25 @@ BOOST_PROCESS_V2_DECL shell cmd(HANDLE handle);
template<typename Executor>
BOOST_PROCESS_V2_DECL shell cmd(basic_process_handle<Executor> & handle, error_code & ec)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return cmd(handle.native_handle(), ec);
#else
return cmd(handle.id(), ec);
#endif
}
template<typename Executor>
BOOST_PROCESS_V2_DECL shell cmd(basic_process_handle<Executor> & handle)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return cmd(handle.native_handle());
#else
return cmd(handle.id());
#endif
}
/// @}
} // namespace ext
BOOST_PROCESS_V2_END_NAMESPACE

View File

@@ -15,26 +15,38 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace ext {
/// Obtain the current path of a process
/// @{
/// Obtain the current path of another process
BOOST_PROCESS_V2_DECL filesystem::path cwd(pid_type pid, error_code & ec);
BOOST_PROCESS_V2_DECL filesystem::path cwd(pid_type pid);
template<typename Executor>
BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle<Executor> & handle, error_code & ec)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return cwd(handle.native_handle(), ec);
#else
return cwd(handle.id(), ec);
#endif
}
template<typename Executor>
BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle<Executor> & handle)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return cwd(handle.native_handle());
#else
return cwd(handle.id());
#endif
}
/// @}
#if defined(BOOST_PROCESS_V2_WINDOWS)
BOOST_PROCESS_V2_DECL filesystem::path cwd(HANDLE handle, error_code & ec);
BOOST_PROCESS_V2_DECL filesystem::path cwd(HANDLE handle);
#endif
template<typename Executor>
BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle<Executor> & handle, error_code & ec)
{
return cwd(handle.native_handle(), ec);
}
template<typename Executor>
BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle<Executor> & handle)
{
return cwd(handle.native_handle());
}
} // namespace ext

View File

@@ -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

View File

@@ -26,6 +26,9 @@ namespace ext
#if defined(BOOST_PROCESS_V2_WINDOWS)
using native_env_handle_type = wchar_t *;
using native_env_iterator = wchar_t *;
#elif defined(__FreeBSD__)
using native_env_handle_type = char **;
using native_env_iterator = char **;
#else
using native_env_handle_type = char *;
using native_env_iterator = char *;
@@ -45,6 +48,7 @@ BOOST_PROCESS_V2_DECL const environment::char_type * dereference(native_env_iter
namespace ext {
/// The view of an environment
struct env_view
{
using native_handle_type = detail::ext::native_env_handle_type;
@@ -105,26 +109,38 @@ struct env_view
detail::ext::native_env_handle_deleter> handle_;
};
/// Get the argument vector from a given pid
/// @{
/// Get the environment of another process.
BOOST_PROCESS_V2_DECL env_view env(pid_type pid, error_code & ec);
BOOST_PROCESS_V2_DECL env_view env(pid_type pid);
template<typename Executor>
BOOST_PROCESS_V2_DECL env_view env(basic_process_handle<Executor> & handle, error_code & ec)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return env(handle.native_handle(), ec);
#else
return env(handle.id(), ec);
#endif
}
template<typename Executor>
BOOST_PROCESS_V2_DECL env_view env(basic_process_handle<Executor> & handle)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return env(handle.native_handle());
#else
return env(handle.id());
#endif
}
/// @}
#if defined(BOOST_PROCESS_V2_WINDOWS)
BOOST_PROCESS_V2_DECL env_view env(HANDLE handle, error_code & ec);
BOOST_PROCESS_V2_DECL env_view env(HANDLE handle);
#endif
template<typename Executor>
BOOST_PROCESS_V2_DECL env_view env(basic_process_handle<Executor> & handle, error_code & ec)
{
return env(handle.native_handle(), ec);
}
template<typename Executor>
BOOST_PROCESS_V2_DECL env_view env(basic_process_handle<Executor> & handle)
{
return env(handle.native_handle());
}
} // namespace ext

View File

@@ -16,27 +16,40 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace ext {
/// Return the executable path from pid
/// @{
/// Return the executable of another process by pid or handle.
BOOST_PROCESS_V2_DECL filesystem::path exe(pid_type pid, error_code & ec);
BOOST_PROCESS_V2_DECL filesystem::path exe(pid_type pid);
#if defined(BOOST_PROCESS_V2_WINDOWS)
BOOST_PROCESS_V2_DECL filesystem::path exe(HANDLE handle, error_code & ec);
BOOST_PROCESS_V2_DECL filesystem::path exe(HANDLE handle);
#endif
template<typename Executor>
filesystem::path exe(basic_process_handle<Executor> & handle, error_code & ec)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return exe(handle.native_handle(), ec);
#else
return exe(handle.id(), ec);
#endif
}
template<typename Executor>
filesystem::path exe(basic_process_handle<Executor> & handle)
{
#if defined(BOOST_PROCESS_V2_WINDOWS)
return exe(handle.native_handle());
#else
return exe(handle.id());
#endif
}
///@}
#if defined(BOOST_PROCESS_V2_WINDOWS)
BOOST_PROCESS_V2_DECL filesystem::path exe(HANDLE handle, error_code & ec);
BOOST_PROCESS_V2_DECL filesystem::path exe(HANDLE handle);
#endif
} // namespace ext
BOOST_PROCESS_V2_END_NAMESPACE

View File

@@ -92,13 +92,12 @@ struct make_cmd_shell_
str_lengths += (std::strlen(*c) + 1);
}
// yes, not the greatest solution.
std::string buffer;
res.buffer_.resize(str_lengths);
res.argv_ = new char*[res.argc_ + 1];
res.free_argv_ = +[](int argc, char ** argv) {delete[] argv;};
res.argv_[res.argc_] = nullptr;
auto p = &buffer[sizeof(int) * (res.argc_) + 1];
auto p = &*res.buffer_.begin();
for (int i = 0; i < res.argc_; i++)
{
@@ -147,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);
@@ -162,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 {};
}
@@ -175,11 +174,11 @@ 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 {};
}
int argc = *reinterpret_cast<int*>(procargs.data());
int argc = *reinterpret_cast<const int*>(procargs.data());
auto itr = procargs.begin() + sizeof(argc);
std::unique_ptr<char*[]> argv{new char*[argc + 1]};
@@ -192,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;
@@ -217,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 {};
}
@@ -248,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;
@@ -274,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 {};
}
@@ -295,26 +294,19 @@ 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 {};
}
struct free_argv
{
struct procstat * proc_stat;
~free_argv()
{
procstat_freeargv(proc_stat);
}
};
return make_cmd_shell_::clone(cmd);
auto res = make_cmd_shell_::clone(cmd);
procstat_freeargv(proc_stat.get());
return res;
}
#elif defined(__DragonFly__)
@@ -334,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 {};
}
@@ -366,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;
}
@@ -397,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 {};
}
@@ -420,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)))
@@ -435,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 {};

View File

@@ -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 {};
@@ -101,10 +101,10 @@ filesystem::path cwd(HANDLE proc)
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
proc_vnodepathinfo vpi;
if (proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi)) > 0) {
if (proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi)) > 0)
return filesystem::canonical(vpi.pvi_cdir.vip_path, ec);
}
ec = detail::get_last_error();
else
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 "";

View File

@@ -77,7 +77,7 @@ const environment::char_type * dereference(native_env_iterator iterator)
return iterator;
}
#else
#elif (defined(__APPLE___) || defined(__MACH__))
void native_env_handle_deleter::operator()(native_env_handle_type h) const
{
@@ -97,6 +97,36 @@ native_env_iterator find_end(native_env_iterator nh)
return nh ;
}
const environment::char_type * dereference(native_env_iterator iterator)
{
return iterator;
}
#elif defined(__FreeBSD__)
void native_env_handle_deleter::operator()(native_env_handle_type h) const
{
delete [] h;
}
native_env_iterator next(native_env_iterator nh)
{
return ++nh ;
}
native_env_iterator find_end(native_env_iterator nh)
{
while (*nh != nullptr)
nh++;
return nh ;
}
const environment::char_type * dereference(native_env_iterator iterator)
{
return *iterator;
}
#endif
}
@@ -123,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 {};
}
@@ -146,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 {};
}
@@ -174,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);
@@ -190,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 {};
}
@@ -203,37 +233,38 @@ 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;
memcpy(&nargs, &*procargs.begin(), sizeof(nargs));
char *cp = &*procargs.begin() + sizeof(nargs);
for (; cp < &&*procargs.begin()[size]; cp++) {
if (*cp == '\0') break;
}
for (; cp < &*procargs.end(); cp++)
if (*cp == '\0')
break;
if (cp == &procargs[s]) {
if (cp == &procargs[size])
return {};
}
for (; cp < &&*procargs.begin()[size]; cp++) {
for (; cp < &*procargs.end(); cp++)
if (*cp != '\0') break;
}
if (cp == &&*procargs.begin()[size]) {
if (cp == &*procargs.end())
return {};
}
int i = 0;
char *sp = cp;
std::vector<char> vec;
while ((*sp != '\0' || i < nargs) && sp < &&*procargs.begin()[size]) {
if (i >= nargs) {
while ((*sp != '\0' || i < nargs) && sp < &*procargs.end()) {
if (i >= nargs)
vec.push_back(*sp);
}
sp += 1;
}
@@ -260,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 {};
}
@@ -279,6 +310,69 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
return ev;
}
#elif defined(__FreeBSD__)
env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
env_view ev;
unsigned cntp = 0;
procstat *proc_stat = procstat_open_sysctl();
if (proc_stat != nullptr)
{
kinfo_proc *proc_info = procstat_getprocs(proc_stat, KERN_PROC_PID, pid, &cntp);
if (proc_info != nullptr)
{
char **env = procstat_getenvv(proc_stat, proc_info, 0);
if (env != nullptr)
{
auto e = env;
std::size_t n = 0u, len = 0u;
while (e && *e != nullptr)
{
n ++;
len += std::strlen(*e);
e++;
}
std::size_t mem_needed =
// environ - nullptr - strlen + null terminators
(n * sizeof(char*)) + sizeof(char*) + len + n;
char * out = new (std::nothrow) char[mem_needed];
if (out != nullptr)
{
auto eno = reinterpret_cast<char**>(out);
auto eeo = eno;
auto str = out + (n * sizeof(char*)) + sizeof(char*);
e = env;
while (*e != nullptr)
{
auto len = std::strlen(*e) + 1u;
std::memcpy(str, *e, len);
*eno = str;
str += len;
eno ++;
e++;
}
*eno = nullptr;
ev.handle_.reset(eeo);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
}
procstat_freeprocs(proc_stat, proc_info);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
procstat_close(proc_stat);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
return ev;
}
#endif
env_view env(boost::process::v2::pid_type pid)

View File

@@ -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 "";
}
@@ -154,11 +154,12 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code
strbuff.resize(len);
if (sysctl(mib, 4, &strbuff[0], &len, nullptr, 0) == 0)
{
return filesystem::canonical(strbuff, ec);
strbuff.resize(len - 1);
return filesystem::canonical(strbuff, ec);
}
}
ec = detail::get_last_error();
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
return "";
}
@@ -166,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 "";
}

View File

@@ -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
@@ -177,9 +177,9 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
{
std::vector<pid_type> vec;
vec.reserve(proc_listpids(PROC_PPID_ONLY, (uint32_t)pid, nullptr, 0));
if (proc_listpids(PROC_PPID_ONLY, (uint32_t)pid, &proc_info[0], sizeof(pid_type) * cntp))
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;
}
}

View File

@@ -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()
@@ -111,7 +115,7 @@ void shell::parse_()
shell::~shell()
{
if (argv_ != nullptr && free_argv_)
if (argv_ != nullptr && free_argv_ != nullptr)
free_argv_(argc_, argv_);
}

View File

@@ -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)
{

View File

@@ -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};

View File

@@ -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)
{

View File

@@ -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};

View File

@@ -215,13 +215,13 @@ struct basic_process
process_handle_.request_exit(ec);
}
/// Send the process a signal requesting it to stop. This may rely on undocmented functions.
/// Send the process a signal requesting it to stop. This may rely on undocumented functions.
void suspend(error_code &ec)
{
process_handle_.suspend(ec);
}
/// Send the process a signal requesting it to stop. This may rely on undocmented functions.
/// Send the process a signal requesting it to stop. This may rely on undocumented functions.
void suspend()
{
error_code ec;
@@ -231,13 +231,13 @@ struct basic_process
}
/// Send the process a signal requesting it to resume. This may rely on undocmented functions.
/// Send the process a signal requesting it to resume. This may rely on undocumented functions.
void resume(error_code &ec)
{
process_handle_.resume(ec);
}
/// Send the process a signal requesting it to resume. This may rely on undocmented functions.
/// Send the process a signal requesting it to resume. This may rely on undocumented functions.
void resume()
{
error_code ec;

View File

@@ -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;

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -59,13 +59,13 @@ test-suite standalone :
[ run utf8.cpp test_impl ]
[ run cstring_ref.cpp test_impl ]
[ run environment.cpp test_impl ]
[ run pid.cpp test_impl ]
[ run pid.cpp test_impl : : : <target-os>darwin:<build>no ]
[ run shell.cpp test_impl ]
;
test-suite with_target :
[ run process.cpp test_impl : --log_level=all --catch_system_errors=no -- : target ]
[ run windows.cpp test_impl : --log_level=all --catch_system_errors=no -- : target : <build>no <target-os>windows:<build>yes <target-os>windows:<source>Advapi32 ]
[ run ext.cpp test_impl : --log_level=all --catch_system_errors=no -- : target ]
[ run ext.cpp test_impl : --log_level=all --catch_system_errors=no -- : target : <target-os>darwin:<build>no ]
;

View File

@@ -22,7 +22,8 @@ BOOST_AUTO_TEST_CASE(test_exe)
namespace bp2 = boost::process::v2;
auto pth = bp2::ext::exe(bp2::current_pid());
BOOST_CHECK(!pth.empty());
BOOST_CHECK_EQUAL(master_test_suite().argv[0], pth.string());
BOOST_CHECK_EQUAL(bp2::filesystem::canonical(master_test_suite().argv[0]).string(),
bp2::filesystem::canonical(pth).string());
}
@@ -30,7 +31,7 @@ BOOST_AUTO_TEST_CASE(test_child_exe)
{
namespace bp2 = boost::process::v2;
using boost::unit_test::framework::master_test_suite;
const auto pth = bp2::filesystem::canonical(master_test_suite().argv[1]);
const auto pth = bp2::filesystem::canonical(master_test_suite().argv[0]);
boost::asio::io_context ctx;
bp2::process proc(ctx, pth, {"sleep", "10000"});
@@ -66,7 +67,7 @@ BOOST_AUTO_TEST_CASE(cmd)
BOOST_AUTO_TEST_CASE(cmd_exe)
{
using boost::unit_test::framework::master_test_suite;
const auto pth = master_test_suite().argv[1];
const auto pth = master_test_suite().argv[0];
namespace bp2 = boost::process::v2;
@@ -101,8 +102,8 @@ BOOST_AUTO_TEST_CASE(test_cwd)
BOOST_AUTO_TEST_CASE(test_cwd_exe)
{
using boost::unit_test::framework::master_test_suite;
const auto pth = master_test_suite().argv[1];
namespace bp2 = boost::process::v2;
const auto pth = bp2::filesystem::absolute(master_test_suite().argv[0]);
auto tmp = bp2::filesystem::temp_directory_path();
@@ -122,6 +123,7 @@ BOOST_AUTO_TEST_CASE(test_env)
namespace bp2 = boost::process::v2;
auto env = bp2::ext::env(bp2::current_pid());
std::size_t e = 0;
for (const auto & kp : bp2::environment::current())
{
@@ -130,15 +132,20 @@ BOOST_AUTO_TEST_CASE(test_env)
{
return kp.key() == kp_.key();
});
BOOST_REQUIRE(itr != env.end());
BOOST_CHECK_EQUAL(kp.value(), (*itr).value());
if (itr != env.end())
{
BOOST_CHECK_EQUAL(kp.value(), (*itr).value());
e++;
}
}
BOOST_CHECK_GT(e, 0u);
}
BOOST_AUTO_TEST_CASE(test_env_exe)
{
using boost::unit_test::framework::master_test_suite;
const auto pth = master_test_suite().argv[1];
const auto pth = master_test_suite().argv[0];
namespace bp2 = boost::process::v2;
auto tmp = bp2::filesystem::temp_directory_path();

View File

@@ -18,6 +18,8 @@ BOOST_AUTO_TEST_CASE(test_pid)
auto all = bp2::all_pids();
auto itr = std::find(all.begin(), all.end(), bp2::current_pid());
BOOST_CHECK_GT(all.size(), 0u);
BOOST_CHECK(itr != all.end());
std::vector<bp2::pid_type> children, grand_children;
@@ -36,4 +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);
}

View File

@@ -221,6 +221,8 @@ BOOST_AUTO_TEST_CASE(print_args_out)
bpv::error_code ec;
auto sz = asio::read(rp, st, ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, st, ec);
BOOST_CHECK_NE(sz, 0u);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
@@ -267,6 +269,8 @@ BOOST_AUTO_TEST_CASE(print_args_err)
bpv::error_code ec;
auto sz = asio::read(rp, st, ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, st, ec);
BOOST_CHECK_NE(sz , 0u);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
@@ -320,6 +324,9 @@ BOOST_AUTO_TEST_CASE(echo_file)
bpv::error_code ec;
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, asio::dynamic_buffer(out), ec);
BOOST_CHECK(sz != 0);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
BOOST_CHECK_MESSAGE(out == test_data, out);
@@ -344,6 +351,9 @@ BOOST_AUTO_TEST_CASE(print_same_cwd)
bpv::error_code ec;
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, asio::dynamic_buffer(out), ec);
BOOST_CHECK(sz != 0);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
BOOST_CHECK_MESSAGE(bpv::filesystem::path(out) == bpv::filesystem::current_path(),
@@ -373,6 +383,9 @@ BOOST_AUTO_TEST_CASE(popen)
std::string res;
boost::system::error_code ec;
std::size_t n = asio::read(proc, asio::dynamic_buffer(res), ec);
while (ec == asio::error::interrupted)
n += asio::read(rp, asio::dynamic_buffer(res), ec);
BOOST_CHECK_MESSAGE(ec == asio::error::eof || ec == asio::error::broken_pipe, ec.message());
BOOST_REQUIRE_GE(n, 1u);
// remove EOF
@@ -406,6 +419,9 @@ BOOST_AUTO_TEST_CASE(print_other_cwd)
bpv::error_code ec;
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, asio::dynamic_buffer(out), ec);
BOOST_CHECK(sz != 0);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
BOOST_CHECK_MESSAGE(bpv::filesystem::path(out) == target,
@@ -436,7 +452,7 @@ std::string read_env(const char * name, Inits && ... inits)
std::string out;
bpv::error_code ec;
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, asio::dynamic_buffer(out), ec);
@@ -534,6 +550,7 @@ BOOST_AUTO_TEST_CASE(bind_launcher)
auto sz = asio::read(rp, asio::dynamic_buffer(out), ec);
while (ec == asio::error::interrupted)
sz += asio::read(rp, asio::dynamic_buffer(out), ec);
BOOST_CHECK(sz != 0);
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
BOOST_CHECK_MESSAGE(bpv::filesystem::path(out) == target,