Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes 1.85 #362

Merged
merged 12 commits into from
Apr 1, 2024
12 changes: 11 additions & 1 deletion include/boost/process/detail/posix/pipe_out.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@
#include <boost/process/pipe.hpp>
#include <boost/process/detail/posix/handler.hpp>
#include <unistd.h>
#include <array>
#include <boost/process/detail/used_handles.hpp>

namespace boost { namespace process { namespace detail { namespace posix {

template<int p1, int p2>
struct pipe_out : handler_base_ext
struct pipe_out : handler_base_ext, ::boost::process::detail::uses_handles
{
int sink;
int source; //opposite end

std::array<int, 4> get_used_handles()
{
const auto pp1 = p1 != -1 ? p1 : p2;
const auto pp2 = p2 != -1 ? p2 : p1;

return {source, sink, pp1, pp2};
}

pipe_out(int sink, int source) : sink(sink), source(source) {}

template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/detail/windows/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline auto native_environment_impl<Char>::get(const pointer_type id) -> string_
{
auto err = ::boost::winapi::GetLastError();
if (err == ::boost::winapi::ERROR_ENVVAR_NOT_FOUND_)//well, then we consider that an empty value
return "";
return string_type();
else
throw process_error(std::error_code(err, std::system_category()),
"GetEnvironmentVariable() failed");
Expand Down
28 changes: 19 additions & 9 deletions include/boost/process/v2/detail/process_handle_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,32 @@ struct basic_process_handle_win


template<typename Executor1>
basic_process_handle_win(basic_process_handle_win<Executor1> && handle)
: pid_(handle.pid_), handle_(std::move(handle.handle_))
basic_process_handle_win(basic_process_handle_win<Executor1> && other)
: pid_(other.pid_), handle_(std::move(other.handle_))
{
other.pid_ = static_cast<DWORD>(-1);
}

basic_process_handle_win(basic_process_handle_win && handle)
: pid_(handle.id()), handle_(std::move(handle.handle_))
basic_process_handle_win(basic_process_handle_win && other)
: pid_(other.pid_), handle_(std::move(other.handle_))
{
handle.pid_ = static_cast<DWORD>(-1);
other.pid_ = static_cast<DWORD>(-1);
}

basic_process_handle_win& operator=(basic_process_handle_win && handle)
basic_process_handle_win& operator=(basic_process_handle_win && other)
{
pid_ = handle.pid_;
handle_ = std::move(handle.handle_);
handle.pid_ = static_cast<DWORD>(-1);
pid_ = other.pid_;
handle_ = std::move(other.handle_);
other.pid_ = static_cast<DWORD>(-1);
return *this;
}

template<typename Executor1>
basic_process_handle_win& operator=(basic_process_handle_win<Executor1> && other)
{
pid_ = other.pid_;
handle_ = std::move(other.handle_);
other.pid_ = static_cast<DWORD>(-1);
return *this;
}

Expand Down
3 changes: 3 additions & 0 deletions include/boost/process/v2/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/cstring_ref.hpp>
#include <boost/process/v2/detail/utf8.hpp>

#include <boost/type_traits.hpp>

#include <functional>
#include <memory>
#include <numeric>
#include <vector>

#if !defined(GENERATING_DOCUMENTATION)
#if defined(BOOST_PROCESS_V2_WINDOWS)
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/v2/execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async_execute(basic_process<Executor> proc,
WaitHandler && handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
{
std::unique_ptr<basic_process<Executor>> pro_(new basic_process<Executor>(std::move(proc)));
auto exec = proc.get_executor();
auto exec = pro_->get_executor();
return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose<WaitHandler, void(error_code, int)>(
detail::execute_op<Executor>{std::move(pro_)}, handler, exec);
}
Expand Down
6 changes: 5 additions & 1 deletion include/boost/process/v2/exit_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ typedef int native_exit_code_type;

namespace detail
{
constexpr native_exit_code_type still_active = 0x7f;
constexpr native_exit_code_type still_active = 0x17f;
static_assert(WIFSTOPPED(still_active), "Expected still_active to indicate WIFSTOPPED");
static_assert(!WIFEXITED(still_active), "Expected still_active to not indicate WIFEXITED");
static_assert(!WIFSIGNALED(still_active), "Expected still_active to not indicate WIFSIGNALED");
static_assert(!WIFCONTINUED(still_active), "Expected still_active to not indicate WIFCONTINUED");
}

inline bool process_is_running(int code)
Expand Down
7 changes: 2 additions & 5 deletions include/boost/process/v2/ext/impl/cwd.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code

#elif defined(__FreeBSD__)

// FIXME: Add error handling.
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
filesystem::path path;
Expand All @@ -139,9 +138,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code
filestat *fst = nullptr;
STAILQ_FOREACH(fst, head, next) {
if (fst->fs_uflags & PS_FST_UFLAG_CDIR)
{
path = filesystem::canonical(fst->fs_path, ec);
}
}
procstat_freefiles(proc_stat, head);
}
Expand All @@ -160,7 +157,6 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code

#elif defined(__DragonFly__)

// FIXME: Add error handling.
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
filesystem::path path;
Expand All @@ -185,7 +181,8 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
pclose(fp);
if (pclose(fp) == -1)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
Expand Down
2 changes: 2 additions & 0 deletions include/boost/process/v2/pid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/detail/throw_error.hpp>

#include <vector>

BOOST_PROCESS_V2_BEGIN_NAMESPACE

#if defined(GENERATING_DOCUMENTATION)
Expand Down
4 changes: 2 additions & 2 deletions include/boost/process/v2/posix/detail/close_handles.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void close_all(const std::vector<int> & whitelist, error_code & ec)
idx++)
{
const auto mine = whitelist[idx];
const auto next = whitelist[idx];
const auto next = whitelist[idx + 1];
if ((mine + 1) != next && (mine != next))
{
::close_range(mine + 1, next - 1, 0);
Expand Down Expand Up @@ -132,7 +132,7 @@ void close_all(const std::vector<int> & whitelist, error_code & ec)
idx++)
{
const auto mine = whitelist[idx];
const auto next = whitelist[idx];
const auto next = whitelist[idx + 1];
if ((mine + 1) != next && (mine != next))
{
::close_range(mine + 1, next - 1, CLOSE_RANGE_UNSHARE);
Expand Down
5 changes: 5 additions & 0 deletions test/posix_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

#include <boost/process/filesystem.hpp>

#if !defined(BOOST_PROCESS_USE_STD_FS)
#include <boost/filesystem/directory.hpp>
#endif


#include <system_error>


Expand Down
2 changes: 1 addition & 1 deletion test/v2/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ BOOST_AUTO_TEST_CASE(async_request_exit)
#endif
);

asio::steady_timer tim{ctx, std::chrono::milliseconds(50)};
asio::steady_timer tim{ctx, std::chrono::milliseconds(250)};
asio::cancellation_signal sig;

bpv::async_execute(std::move(proc),
Expand Down
Loading