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

Compare commits

..

1 Commits

Author SHA1 Message Date
Klemens Morgenstern
13c4b0aa14 added wait_pid to be run in set_error. 2023-10-05 10:51:24 +08:00
15 changed files with 33 additions and 66 deletions

View File

@@ -262,7 +262,10 @@ class executor
return;
//EAGAIN not yet forked, EINTR interrupted, i.e. try again
else if ((err != EAGAIN ) && (err != EINTR))
set_error(std::error_code(err, std::system_category()), "Error read pipe");
{
set_error(std::error_code(err, std::system_category()), "Error read pipe");
return;
}
}
set_error(ec, std::move(msg));
}
@@ -324,6 +327,9 @@ public:
void set_error(const std::error_code &ec, const char* msg)
{
if (pid != 0 && pid != -1) // reap-zombie
::waitpid(pid, nullptr, 0);
internal_error_handle(ec, msg, has_error_handler(), has_ignore_error(), shall_use_vfork());
}
void set_error(const std::error_code &ec, const std::string &msg) {set_error(ec, msg.c_str());};
@@ -445,7 +451,6 @@ child executor<Sequence>::invoke(boost::mpl::false_, boost::mpl::false_)
if (_ec)
{
//if an error occurred we need to reap the child process
::waitpid(this->pid, nullptr, WNOHANG);
boost::fusion::for_each(seq, call_on_error(*this, _ec));
return child();
}

View File

@@ -33,7 +33,7 @@ inline std::vector<native_handle_type> get_handles(std::error_code & ec)
else
ec.clear();
auto my_fd = dirfd(dir.get());
auto my_fd = ::dirfd(dir.get());
struct ::dirent * ent_p;
@@ -117,7 +117,7 @@ struct limit_handles_ : handler_base_ext
return;
}
auto my_fd = dirfd(dir);
auto my_fd = ::dirfd(dir);
struct ::dirent * ent_p;
while ((ent_p = readdir(dir)) != nullptr)

View File

@@ -14,25 +14,15 @@
#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, ::boost::process::detail::uses_handles
struct pipe_out : handler_base_ext
{
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>

View File

@@ -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 string_type();
return "";
else
throw process_error(std::error_code(err, std::system_category()),
"GetEnvironmentVariable() failed");

View File

@@ -84,32 +84,22 @@ struct basic_process_handle_win
template<typename Executor1>
basic_process_handle_win(basic_process_handle_win<Executor1> && other)
: pid_(other.pid_), handle_(std::move(other.handle_))
basic_process_handle_win(basic_process_handle_win<Executor1> && handle)
: pid_(handle.pid_), handle_(std::move(handle.handle_))
{
other.pid_ = static_cast<DWORD>(-1);
}
basic_process_handle_win(basic_process_handle_win && other)
: pid_(other.pid_), handle_(std::move(other.handle_))
basic_process_handle_win(basic_process_handle_win && handle)
: pid_(handle.id()), handle_(std::move(handle.handle_))
{
other.pid_ = static_cast<DWORD>(-1);
handle.pid_ = static_cast<DWORD>(-1);
}
basic_process_handle_win& operator=(basic_process_handle_win && other)
basic_process_handle_win& operator=(basic_process_handle_win && handle)
{
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);
pid_ = handle.pid_;
handle_ = std::move(handle.handle_);
handle.pid_ = static_cast<DWORD>(-1);
return *this;
}

View File

@@ -13,13 +13,10 @@
#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)

View File

@@ -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 = pro_->get_executor();
auto exec = proc.get_executor();
return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose<WaitHandler, void(error_code, int)>(
detail::execute_op<Executor>{std::move(pro_)}, handler, exec);
}

View File

@@ -72,11 +72,7 @@ typedef int native_exit_code_type;
namespace detail
{
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");
constexpr native_exit_code_type still_active = 0x7f;
}
inline bool process_is_running(int code)

View File

@@ -112,19 +112,13 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
#if (defined(__linux__) || defined(__ANDROID__))
return filesystem::canonical(
filesystem::path("/proc") / std::to_string(pid) / "cwd", ec
);
#elif defined(__sun)
return fileystem::canonical(
filesystem::path("/proc") / std::to_string(pid) / "path/cwd", ec
);
#endif
filesystem::path("/proc") / std::to_string(pid) / "cwd", ec);
}
#elif defined(__FreeBSD__)
// FIXME: Add error handling.
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
filesystem::path path;
@@ -138,7 +132,9 @@ 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);
}
@@ -157,6 +153,7 @@ 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;
@@ -181,8 +178,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
if (pclose(fp) == -1)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
pclose(fp);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)

View File

@@ -133,7 +133,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code
);
#elif defined(__sun)
return fileystem::canonical(
filesystem::path("/proc") / std::to_string(pid) / "path/a.out", ec
filesystem::path("/proc") / std::to_string(pid) / "path/a.out"
);
#endif
}

View File

@@ -9,8 +9,6 @@
#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)

View File

@@ -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 + 1];
const auto next = whitelist[idx];
if ((mine + 1) != next && (mine != next))
{
::close_range(mine + 1, next - 1, 0);
@@ -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 + 1];
const auto next = whitelist[idx];
if ((mine + 1) != next && (mine != next))
{
::close_range(mine + 1, next - 1, CLOSE_RANGE_UNSHARE);

View File

@@ -21,7 +21,7 @@ process_standalone_test(pipe)
function(process_sub_launch_test name )
add_executable(boost_process_${name} ${name}.cpp)
target_link_libraries(boost_process_${name} Boost::process Boost::system Boost::filesystem Boost::scope_exit Boost::thread Boost::unit_test_framework)
target_link_libraries(boost_process_${name} Boost::process Boost::system Boost::filesystem Boost::thread Boost::unit_test_framework)
add_test(NAME boost_process_${name} COMMAND $<TARGET_FILE:boost_process_${name}> $<TARGET_FILE:boost_process_sub_launch> )
endfunction()

View File

@@ -16,11 +16,6 @@
#include <boost/process/filesystem.hpp>
#if !defined(BOOST_PROCESS_USE_STD_FS)
#include <boost/filesystem/directory.hpp>
#endif
#include <system_error>

View File

@@ -625,7 +625,7 @@ BOOST_AUTO_TEST_CASE(async_request_exit)
#endif
);
asio::steady_timer tim{ctx, std::chrono::milliseconds(250)};
asio::steady_timer tim{ctx, std::chrono::milliseconds(50)};
asio::cancellation_signal sig;
bpv::async_execute(std::move(proc),