2
0
mirror of https://github.com/boostorg/process.git synced 2026-01-19 16:32:15 +00:00

Compare commits

...

15 Commits

Author SHA1 Message Date
Christian Eggers
406cd3ecf3 v2: sync initial value for exit code with v1
The initial value for the exit_code (0x7f) in v2 doesn't work with musl libc.
Here WIFSIGNALED(0x7f) expands to a non-zero value:

http://git.musl-libc.org/cgit/musl/tree/include/sys/wait.h#n54
2024-04-01 06:40:48 +08:00
Devon Morris
c6951ff773 fix call on moved variable in execute 2024-04-01 06:38:00 +08:00
mknaleczb
f2330c195a Changed return value from "" to string_type() 2024-04-01 06:36:48 +08:00
Samuel Venable
2ae279bd15 Add more error handling to bp2::ext cwd.ipp. (#354)
* Add more error handling to bp2::ext cwd.ipp.

* Remove redundant errno checks

these functions don't fail...
2024-04-01 06:35:17 +08:00
Christian Eggers
7a17af0f5c v2: fix closing of file descriptors
Fix off-by-one error. Currently, no handles are actually closed.
2024-03-28 21:57:13 +08:00
Christian Eggers
768944672f posix: pipe_out: fix merge conflict
In commit cbaa913e3d ("Merge branch 'develop' into limit_fd"), there
have been merge conflicts in two files. In pipe_out.hpp, a previous
commit from the "limit_fd" branch f8c0dd4da5 ("prototype for
limit_fd") had been eliminated during wrong conflict resolution.

The final result was, that file descriptors for stdout pipes were not
preserved when using limit_handles.

Example:

boost::asio::io_context io_context;
bp::async_pipe my_stdin(io_context);
bp::async_pipe my_stdout(io_context);
bp::child my_child("/usr/bin/echo", "Hello world",
    bp::std_in  < my_stdin,  // preserved by limit_handles
    bp::std_out > my_stdout, // closed by limit_handles
    bp::std_err > stderr,    // preserved by limit_handles
    bp::limit_handles)

Fixes: cbaa913e3d ("Merge branch 'develop' into limit_fd")
2024-03-28 21:56:58 +08:00
Klemens Morgenstern
46acb247f5 test include fix. 2024-03-28 11:05:33 +08:00
Klemens Morgenstern
08e3549713 #include vector fixes. 2024-03-28 08:30:08 +08:00
Klemens Morgenstern
029ad735fe added missing rename of variable. 2023-10-25 19:29:41 +08:00
Klemens Morgenstern
03a348ebdd Merge branch 'develop' of https://github.com/boostorg/process into develop 2023-10-25 19:06:26 +08:00
Klemens Morgenstern
f289f26c87 minor windows cleanup 2023-10-25 15:38:49 +08:00
Klemens Morgenstern
8d9aa1e31d incresed request_exit delay in windows process test. 2023-10-13 14:25:04 +08:00
Samuel Venable
1873f34435 Fix V2::EXT::CWD [SunOS] (#310)
* Fix V2::EXT::CWD [SunOS]

filesystem::canonical is basically the same thing as realpath on Unix-likes, which only resolves one symbolic link. If one symbolic link points to yet another symbolic link and so on and so forth, it will not resolve all symbolic links. It will only do one link for each call to canonical. On SunOS, unlike Linux, /proc/${pid}/cwd does not directly point to the literal current working directory of the given ${pid}. Instead, it will point to yet another symlink - /proc/${pid}/path/cwd which once you have followed that second link only then will you have the literal cwd path for the process id.
2023-10-12 21:43:59 +08:00
Ilia
5f795d9e62 Fix compilation for macOS 14 SDK
Fixes #342
2023-10-09 10:46:25 +08:00
Daniel Richard G
f17be678f2 fix group_wait test in cmake build. 2023-10-09 10:46:03 +08:00
14 changed files with 64 additions and 26 deletions

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

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

View File

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

View File

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

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

View File

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

View File

@@ -112,13 +112,19 @@ 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);
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
}
#elif defined(__FreeBSD__)
// FIXME: Add error handling.
filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
filesystem::path path;
@@ -132,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);
}
@@ -153,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;
@@ -178,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)

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"
filesystem::path("/proc") / std::to_string(pid) / "path/a.out", ec
);
#endif
}

View File

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

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];
const auto next = whitelist[idx + 1];
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];
const auto next = whitelist[idx + 1];
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::thread Boost::unit_test_framework)
target_link_libraries(boost_process_${name} Boost::process Boost::system Boost::filesystem Boost::scope_exit 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,6 +16,11 @@
#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(50)};
asio::steady_timer tim{ctx, std::chrono::milliseconds(250)};
asio::cancellation_signal sig;
bpv::async_execute(std::move(proc),