From 7f91f8df974e45597c7e525984ef80985eb926e7 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 13 Jun 2023 20:36:34 +0800 Subject: [PATCH 01/20] include fix for v2/environment.hpp. --- include/boost/process/v2/environment.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/process/v2/environment.hpp b/include/boost/process/v2/environment.hpp index ae081d162..69bacb663 100644 --- a/include/boost/process/v2/environment.hpp +++ b/include/boost/process/v2/environment.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include From 604760f7d25fc56e1060267a4c1f46dcbe81019a Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 13 Jun 2023 20:50:06 +0800 Subject: [PATCH 02/20] pipe_* includes error_code closes #316 --- include/boost/process/detail/windows/pipe_in.hpp | 2 ++ include/boost/process/detail/windows/pipe_out.hpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/boost/process/detail/windows/pipe_in.hpp b/include/boost/process/detail/windows/pipe_in.hpp index 39546eae6..1ef215279 100644 --- a/include/boost/process/detail/windows/pipe_in.hpp +++ b/include/boost/process/detail/windows/pipe_in.hpp @@ -14,6 +14,8 @@ #include #include #include +#include + namespace boost { namespace process { namespace detail { namespace windows { diff --git a/include/boost/process/detail/windows/pipe_out.hpp b/include/boost/process/detail/windows/pipe_out.hpp index 125a34862..24cd6a82a 100644 --- a/include/boost/process/detail/windows/pipe_out.hpp +++ b/include/boost/process/detail/windows/pipe_out.hpp @@ -15,10 +15,10 @@ #include #include #include - -namespace boost { namespace process { namespace detail { namespace windows { +#include +namespace boost { namespace process { namespace detail { namespace windows { template struct pipe_out : public ::boost::process::detail::handler_base, ::boost::process::detail::uses_handles From 9f516f9240985988fc3f5f86a91ac437c4203312 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 13 Jun 2023 21:03:39 +0800 Subject: [PATCH 03/20] process uses v2::detail::throw_error closes #318 --- include/boost/process/v2/posix/default_launcher.hpp | 5 +++-- include/boost/process/v2/posix/fork_and_forget_launcher.hpp | 4 ++-- include/boost/process/v2/posix/pdfork_launcher.hpp | 4 ++-- include/boost/process/v2/posix/vfork_launcher.hpp | 4 ++-- include/boost/process/v2/windows/as_user_launcher.hpp | 4 ++-- include/boost/process/v2/windows/default_launcher.hpp | 5 +++-- include/boost/process/v2/windows/with_logon_launcher.hpp | 2 +- include/boost/process/v2/windows/with_token_launcher.hpp | 4 ++-- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index f07d64fd8..d04e85cd9 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #if defined(BOOST_PROCESS_V2_STANDALONE) @@ -313,7 +314,7 @@ struct default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + v2::detail::throw_error(ec, "default_launcher"); return proc; } @@ -344,7 +345,7 @@ struct default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + v2::detail::throw_error(ec, "default_launcher"); return proc; } diff --git a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp index d97557f18..c79f3845b 100644 --- a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp +++ b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp @@ -29,7 +29,7 @@ struct fork_and_forget_launcher : default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "fork_and_forget_launcher"); + v2::detail::throw_error(ec, "fork_and_forget_launcher"); return proc; } @@ -60,7 +60,7 @@ struct fork_and_forget_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "fork_and_forget_launcher"); + v2::detail::throw_error(ec, "fork_and_forget_launcher"); return proc; } diff --git a/include/boost/process/v2/posix/pdfork_launcher.hpp b/include/boost/process/v2/posix/pdfork_launcher.hpp index 1f6d7ffce..858ce09b0 100644 --- a/include/boost/process/v2/posix/pdfork_launcher.hpp +++ b/include/boost/process/v2/posix/pdfork_launcher.hpp @@ -34,7 +34,7 @@ struct pdfork_launcher : default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "pdfork_launcher"); + v2::detail::throw_error(ec, "pdfork_launcher"); return proc; } @@ -65,7 +65,7 @@ struct pdfork_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "pdfork_launcher"); + v2::detail::throw_error(ec, "pdfork_launcher"); return proc; } diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index d156aad3e..14239f3f3 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -31,7 +31,7 @@ struct vfork_launcher : default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + v2::detail::throw_error(ec, "default_launcher"); return proc; } @@ -62,7 +62,7 @@ struct vfork_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + v2::detail::throw_error(ec, "default_launcher"); return proc; } diff --git a/include/boost/process/v2/windows/as_user_launcher.hpp b/include/boost/process/v2/windows/as_user_launcher.hpp index c1b1e30b0..0c47da092 100644 --- a/include/boost/process/v2/windows/as_user_launcher.hpp +++ b/include/boost/process/v2/windows/as_user_launcher.hpp @@ -37,7 +37,7 @@ struct as_user_launcher : default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "as_user_launcher"); + v2::detail::throw_error(ec, "as_user_launcher"); return proc; } @@ -68,7 +68,7 @@ struct as_user_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "as_user_launcher"); + detail::throw_error(ec, "as_user_launcher"); return proc; } diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index 1ce0fe0e1..358c79b8a 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -244,7 +245,7 @@ struct default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + v2::detail::throw_error(ec, "default_launcher"); return proc; } @@ -275,7 +276,7 @@ struct default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "default_launcher"); + detail::throw_error(ec, "default_launcher"); return proc; } diff --git a/include/boost/process/v2/windows/with_logon_launcher.hpp b/include/boost/process/v2/windows/with_logon_launcher.hpp index df8e82287..064d3b16c 100644 --- a/include/boost/process/v2/windows/with_logon_launcher.hpp +++ b/include/boost/process/v2/windows/with_logon_launcher.hpp @@ -72,7 +72,7 @@ struct with_logon_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "with_logon_launcher"); + v2::detail::throw_error(ec, "with_logon_launcher"); return proc; } diff --git a/include/boost/process/v2/windows/with_token_launcher.hpp b/include/boost/process/v2/windows/with_token_launcher.hpp index 2775f7774..e9f0dbfb2 100644 --- a/include/boost/process/v2/windows/with_token_launcher.hpp +++ b/include/boost/process/v2/windows/with_token_launcher.hpp @@ -38,7 +38,7 @@ struct with_token_launcher : default_launcher auto proc = (*this)(context, ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "with_token_launcher"); + v2::detail::throw_error(ec, "with_token_launcher"); return proc; } @@ -69,7 +69,7 @@ struct with_token_launcher : default_launcher auto proc = (*this)(std::move(exec), ec, executable, std::forward(args), std::forward(inits)...); if (ec) - asio::detail::throw_error(ec, "with_token_launcher"); + detail::throw_error(ec, "with_token_launcher"); return proc; } From c108d76089d1e908b2c753238999db2fd6b91a22 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 13 Jun 2023 22:03:05 +0800 Subject: [PATCH 04/20] Remove initializer_list constructors. They are causing ambiguity and are not that useful. Closes #313 --- include/boost/process/v2/popen.hpp | 36 ---------------------------- include/boost/process/v2/process.hpp | 12 +--------- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/include/boost/process/v2/popen.hpp b/include/boost/process/v2/popen.hpp index c1ca58052..7696eb718 100644 --- a/include/boost/process/v2/popen.hpp +++ b/include/boost/process/v2/popen.hpp @@ -109,42 +109,6 @@ struct basic_popen : basic_process )); } - /// Construct a child from a property list and launch it using the default process launcher. - template - explicit basic_popen( - executor_type executor, - const filesystem::path& exe, - std::initializer_list args, - Inits&&... inits) - : basic_process(executor) - { - this->basic_process::operator=( - default_process_launcher()( - this->get_executor(), exe, args, - std::forward(inits)..., - process_stdio{stdin_, stdout_} - )); - } - - - /// Construct a child from a property list and launch it using the default process launcher. - template - explicit basic_popen( - Launcher && launcher, - executor_type executor, - const filesystem::path& exe, - std::initializer_list args, - Inits&&... inits) - : basic_process(executor) - { - this->basic_process::operator=( - std::forward(launcher)( - this->get_executor(), exe, args, - std::forward(inits)..., - process_stdio{stdin_, stdout_} - )); - } - /// Construct a child from a property list and launch it using the default process launcher. template explicit basic_popen( diff --git a/include/boost/process/v2/process.hpp b/include/boost/process/v2/process.hpp index 75d046885..eae505e57 100644 --- a/include/boost/process/v2/process.hpp +++ b/include/boost/process/v2/process.hpp @@ -93,17 +93,7 @@ struct basic_process : basic_process(default_process_launcher()(std::move(executor), exe, args, std::forward(inits)...)) { } - /// Construct a child from a property list and launch it using the default launcher.. - template - explicit basic_process( - executor_type executor, - const filesystem::path& exe, - std::initializer_list args, - Inits&&... inits) - : basic_process(default_process_launcher()(std::move(executor), exe, args, std::forward(inits)...)) - { - } - + /// Construct a child from a property list and launch it using the default launcher.. template explicit basic_process( From bf0861de5a4a46b49d399a64f50cf3907f6a6c87 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 13 Jun 2023 22:05:56 +0800 Subject: [PATCH 05/20] vfork launcher fixes closes #314 --- include/boost/process/v2/posix/vfork_launcher.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index 14239f3f3..89947e0ec 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -101,7 +101,6 @@ struct vfork_launcher : default_launcher } else if (pid == 0) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_child); ec = detail::on_exec_setup(*this, executable, argv, inits...); if (!ec) close_all_fds(ec); @@ -110,7 +109,7 @@ struct vfork_launcher : default_launcher BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) detail::on_exec_error(*this, executable, argv, ec, inits...); - ::exit(EXIT_FAILURE); + ::_exit(EXIT_FAILURE); return basic_process{exec}; } ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); From 17530dc2e00027ccfe5a2a6ef450c51b60217186 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 00:07:12 +0800 Subject: [PATCH 06/20] ~pipe_buf catches exceptions from overflow Closes #111 --- include/boost/process/pipe.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/boost/process/pipe.hpp b/include/boost/process/pipe.hpp index 24b261514..11040717d 100644 --- a/include/boost/process/pipe.hpp +++ b/include/boost/process/pipe.hpp @@ -122,10 +122,14 @@ struct basic_pipebuf : std::basic_streambuf ///Destructor -> writes the frest of the data ~basic_pipebuf() + try { if (basic_pipebuf::is_open()) basic_pipebuf::overflow(Traits::eof()); } + catch (process_error & ) + { + } ///Move construct from a pipe. basic_pipebuf(pipe_type && p) : _pipe(std::move(p)), From 126ee8291082a5bd868a40a008c7d03492cdd7fe Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 00:09:44 +0800 Subject: [PATCH 07/20] doc typo fixes --- doc/concepts.qbk | 2 +- doc/v2/introduction.qbk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/concepts.qbk b/doc/concepts.qbk index f9f27d493..3b028cddd 100644 --- a/doc/concepts.qbk +++ b/doc/concepts.qbk @@ -35,7 +35,7 @@ In this library the following functions are used for the creation of unnamed pip As the name suggests, named pipes have a string identifier. This means that a handle to them can be obtained with the identifier, too. -The implementation on posix uses [@(http://pubs.opengroup.org/onlinepubs/009695399/functions/mkfifo.html fifos], +The implementation on posix uses [@http://pubs.opengroup.org/onlinepubs/009695399/functions/mkfifo.html fifos], which means, that the named pipe behaves like a file. Windows does provide a facility called [@https://msdn.microsoft.com/en-us/library/windows/desktop/aa365150(v=vs.85).aspx named pipes], diff --git a/doc/v2/introduction.qbk b/doc/v2/introduction.qbk index e97f60b17..18029c3c0 100644 --- a/doc/v2/introduction.qbk +++ b/doc/v2/introduction.qbk @@ -57,7 +57,7 @@ file-handles for the subprocess. Certain parts of boost.process were not as reliable as they should've been. -This concerns especially the `wait_for`` and `wait_until` functions on the process. +This concerns especially the `wait_for` and `wait_until` functions on the process. The latter are easy to do on windows, but posix does not provide an API for this. Thus the wait_for used signals or fork, which was all but safe. Since process v2 is based on asio and thus supports cancellation, From 30be793b21ced90f79d668bd319bbeee9b12f444 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 00:23:41 +0800 Subject: [PATCH 08/20] fixed unsigned & signed warnings closes #301 --- include/boost/process/detail/posix/basic_pipe.hpp | 13 +++++-------- include/boost/process/environment.hpp | 9 +++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/boost/process/detail/posix/basic_pipe.hpp b/include/boost/process/detail/posix/basic_pipe.hpp index 965db6370..50fd4de39 100644 --- a/include/boost/process/detail/posix/basic_pipe.hpp +++ b/include/boost/process/detail/posix/basic_pipe.hpp @@ -77,12 +77,9 @@ class basic_pipe void assign_source(native_handle_type h) { _source = h;} void assign_sink (native_handle_type h) { _sink = h;} - - - int_type write(const char_type * data, int_type count) { - int_type write_len; + ssize_t write_len; while ((write_len = ::write(_sink, data, count * sizeof(char_type))) == -1) { //Try again if interrupted @@ -90,19 +87,19 @@ class basic_pipe if (err != EINTR) ::boost::process::detail::throw_last_error(); } - return write_len; + return static_cast(write_len); } int_type read(char_type * data, int_type count) { - int_type read_len; - while ((read_len = static_cast(::read(_source, data, count * sizeof(char_type)))) == -1) + ssize_t read_len; + while ((read_len = ::read(_source, data, count * sizeof(char_type))) == -1) { //Try again if interrupted auto err = errno; if (err != EINTR) ::boost::process::detail::throw_last_error(); } - return read_len; + return static_cast(read_len); } bool is_open() const diff --git a/include/boost/process/environment.hpp b/include/boost/process/environment.hpp index 3aa4c9160..0d276cdac 100644 --- a/include/boost/process/environment.hpp +++ b/include/boost/process/environment.hpp @@ -263,7 +263,7 @@ class basic_environment_impl : public Implementation auto st1 = key + ::boost::process::detail::equal_sign(); while (*p != nullptr) { - const int len = std::char_traits::length(*p); + const std::size_t len = std::char_traits::length(*p); if ((std::distance(st1.begin(), st1.end()) < len) && std::equal(st1.begin(), st1.end(), *p)) break; @@ -277,7 +277,7 @@ class basic_environment_impl : public Implementation auto st1 = key + ::boost::process::detail::equal_sign(); while (*p != nullptr) { - const int len = std::char_traits::length(*p); + const std::size_t len = std::char_traits::length(*p); if ((std::distance(st1.begin(), st1.end()) < len) && std::equal(st1.begin(), st1.end(), *p)) break; @@ -292,8 +292,9 @@ class basic_environment_impl : public Implementation auto st1 = st + ::boost::process::detail::equal_sign(); while (*p != nullptr) { - const int len = std::char_traits::length(*p); - if ((std::distance(st1.begin(), st1.end()) < len) + const std::size_t len = std::char_traits::length(*p); + if ((std::distance(st1.begin(), st1.end()) < + static_cast(len)) && std::equal(st1.begin(), st1.end(), *p)) return 1u; p++; From ad413de1d65d731261bb81764e1ddfbfde670e75 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 01:04:16 +0800 Subject: [PATCH 09/20] posix::basic_cmd handles empty cmd closes #304. --- include/boost/process/detail/posix/basic_cmd.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/boost/process/detail/posix/basic_cmd.hpp b/include/boost/process/detail/posix/basic_cmd.hpp index d648e4909..f310f1276 100644 --- a/include/boost/process/detail/posix/basic_cmd.hpp +++ b/include/boost/process/detail/posix/basic_cmd.hpp @@ -112,7 +112,10 @@ struct exe_cmd_init : boost::process::detail::api::handler_base_ext { if (exe.empty()) //cmd style { - exec.exe = args.front().c_str(); + if (args.empty()) + exec.exe = ""; + else + exec.exe = args.front().c_str(); exec.cmd_style = true; } else From 3bb1d10b1fe3a4bca21d6c3d0f7405b33b8f75fb Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 08:48:58 +0800 Subject: [PATCH 10/20] removed posix-cmake-subdir from github actions. --- .github/workflows/ci.yml | 49 ---------------------------------------- 1 file changed, 49 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14776a89d..688abf222 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,52 +199,3 @@ jobs: run: | cd ../boost-root b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker - - posix-cmake-subdir: - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-18.04 - - os: ubuntu-20.04 - - os: ubuntu-22.04 - - os: macos-11 - - runs-on: ${{matrix.os}} - - steps: - - uses: actions/checkout@v2 - - - name: Install packages - if: matrix.install - run: sudo apt install ${{matrix.install}} - - - name: Setup Boost - run: | - echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY - LIBRARY=${GITHUB_REPOSITORY#*/} - echo LIBRARY: $LIBRARY - echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV - echo GITHUB_BASE_REF: $GITHUB_BASE_REF - echo GITHUB_REF: $GITHUB_REF - REF=${GITHUB_BASE_REF:-$GITHUB_REF} - REF=${REF#refs/heads/} - echo REF: $REF - BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true - echo BOOST_BRANCH: $BOOST_BRANCH - cd .. - git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root - cd boost-root - cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY - git submodule update --init tools/boostdep - python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY - - - name: Use library with add_subdirectory - run: | - cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test - mkdir __build__ && cd __build__ - cmake .. - cmake --build . - ctest --output-on-failure --no-tests=error - - From 6ebbbd6fe8980ac234b242aec98ede6353bbdbd7 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 14 Jun 2023 14:38:22 +0800 Subject: [PATCH 11/20] terminate test logs ec. --- test/terminate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/terminate.cpp b/test/terminate.cpp index 0e9ce722b..d99f82e17 100644 --- a/test/terminate.cpp +++ b/test/terminate.cpp @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5)) BOOST_CHECK(c.valid()); BOOST_CHECK(c.running(ec)); - BOOST_CHECK(!c.wait_for(std::chrono::milliseconds(100), ec)); - BOOST_CHECK(c.running(ec)); + BOOST_CHECK_MESSAGE(!c.wait_for(std::chrono::milliseconds(100), ec), ec.message()); + BOOST_CHECK_MESSAGE(c.running(ec), ec.message()); BOOST_CHECK(c.valid()); c.terminate(ec); From 6311bf00c7c812a6f8de677c6840341ed58b5cdd Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 20 Jun 2023 09:09:44 +0800 Subject: [PATCH 12/20] ext/*.hpp order fix --- include/boost/process/v2/ext/cmd.hpp | 5 +++++ include/boost/process/v2/ext/cwd.hpp | 11 +++++------ include/boost/process/v2/ext/env.hpp | 9 +++++---- include/boost/process/v2/ext/exe.hpp | 10 +++++----- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/boost/process/v2/ext/cmd.hpp b/include/boost/process/v2/ext/cmd.hpp index a92c9c0ae..0e5b3427a 100644 --- a/include/boost/process/v2/ext/cmd.hpp +++ b/include/boost/process/v2/ext/cmd.hpp @@ -20,6 +20,11 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace ext { +#if defined(BOOST_PROCESS_V2_WINDOWS) +BOOST_PROCESS_V2_DECL shell cmd(HANDLE handle, error_code & ec); +BOOST_PROCESS_V2_DECL shell cmd(HANDLE handle); +#endif + /// @{ /// Get the argument vector of another process BOOST_PROCESS_V2_DECL shell cmd(pid_type pid, error_code & ec); diff --git a/include/boost/process/v2/ext/cwd.hpp b/include/boost/process/v2/ext/cwd.hpp index 3af8358e7..e255d3dd5 100644 --- a/include/boost/process/v2/ext/cwd.hpp +++ b/include/boost/process/v2/ext/cwd.hpp @@ -15,6 +15,11 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace ext { +#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 + /// @{ /// Obtain the current path of another process BOOST_PROCESS_V2_DECL filesystem::path cwd(pid_type pid, error_code & ec); @@ -42,12 +47,6 @@ BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle & hand /// @} -#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 - - } // namespace ext BOOST_PROCESS_V2_END_NAMESPACE diff --git a/include/boost/process/v2/ext/env.hpp b/include/boost/process/v2/ext/env.hpp index 7adc84002..33ca2345f 100644 --- a/include/boost/process/v2/ext/env.hpp +++ b/include/boost/process/v2/ext/env.hpp @@ -109,6 +109,11 @@ struct env_view detail::ext::native_env_handle_deleter> handle_; }; +#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 + /// @{ /// Get the environment of another process. BOOST_PROCESS_V2_DECL env_view env(pid_type pid, error_code & ec); @@ -136,10 +141,6 @@ BOOST_PROCESS_V2_DECL env_view env(basic_process_handle & handle) /// @} -#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 } // namespace ext diff --git a/include/boost/process/v2/ext/exe.hpp b/include/boost/process/v2/ext/exe.hpp index 0629eb96a..a809f9503 100644 --- a/include/boost/process/v2/ext/exe.hpp +++ b/include/boost/process/v2/ext/exe.hpp @@ -16,6 +16,11 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace ext { +#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 + /// @{ /// Return the executable of another process by pid or handle. BOOST_PROCESS_V2_DECL filesystem::path exe(pid_type pid, error_code & ec); @@ -45,11 +50,6 @@ filesystem::path exe(basic_process_handle & handle) ///@} -#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 From de34d2d58a19099964e27150e665a021e373d5c4 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 20 Jun 2023 09:38:13 +0800 Subject: [PATCH 13/20] simplified terminate test. --- test/sparring_partner.cpp | 4 +++- test/terminate.cpp | 39 +++------------------------------------ 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/test/sparring_partner.cpp b/test/sparring_partner.cpp index fe28c3cea..80a70c474 100644 --- a/test/sparring_partner.cpp +++ b/test/sparring_partner.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #if defined(BOOST_POSIX_API) # include # include @@ -148,7 +149,8 @@ int main(int argc, char *argv[]) } else if (vm["loop"].as()) { - while (true); + while (true) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } else if (vm["abort"].as()) { diff --git a/test/terminate.cpp b/test/terminate.cpp index d99f82e17..fa3f2987f 100644 --- a/test/terminate.cpp +++ b/test/terminate.cpp @@ -24,15 +24,6 @@ namespace bp = boost::process; BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5)) { - std::atomic done{false}; - std::thread thr{ - [&] - { - for (int i = 0; i < 50 && !done.load(); i++) - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - BOOST_REQUIRE(done.load()); - }}; - using boost::unit_test::framework::master_test_suite; std::error_code ec; bp::child c( @@ -44,31 +35,14 @@ BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5)) BOOST_CHECK(c.valid()); BOOST_CHECK(c.running(ec)); - - BOOST_CHECK_MESSAGE(!c.wait_for(std::chrono::milliseconds(100), ec), ec.message()); - BOOST_CHECK_MESSAGE(c.running(ec), ec.message()); - BOOST_CHECK(c.valid()); - c.terminate(ec); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); BOOST_CHECK(!c.running(ec)); BOOST_CHECK(!ec); - - done.store(true); - thr.join(); } BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5)) { - std::atomic done{false}; - std::thread thr{ - [&] - { - for (int i = 0; i < 50 && !done.load(); i++) - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - BOOST_REQUIRE(done.load()); - }}; - using boost::unit_test::framework::master_test_suite; std::error_code ec; @@ -79,17 +53,10 @@ BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5)) ec ); BOOST_REQUIRE(!ec); - BOOST_CHECK(c.valid()); - BOOST_CHECK(c.running()); - BOOST_CHECK(!c.wait_for(std::chrono::milliseconds(100), ec)); - BOOST_CHECK(c.running(ec)); BOOST_CHECK(c.valid()); - + BOOST_CHECK(c.running()); c.terminate(); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); BOOST_CHECK(!c.running()); - - done.store(true); - thr.join(); } From 5cf7dbeba6e2c5c4093b60fce1c750919f4f51f4 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 20 Jun 2023 22:00:04 +0800 Subject: [PATCH 14/20] test updates for CI --- include/boost/process/v2/windows/default_launcher.hpp | 1 - include/boost/process/v2/windows/impl/default_launcher.ipp | 2 +- test/v2/environment.cpp | 6 +++++- test/v2/process.cpp | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index 358c79b8a..2e44b33e4 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -312,7 +312,6 @@ struct default_launcher &startup_info.StartupInfo, &process_information); - auto ec__ = detail::get_last_error(); if (ok == 0) { BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) diff --git a/include/boost/process/v2/windows/impl/default_launcher.ipp b/include/boost/process/v2/windows/impl/default_launcher.ipp index fa6947562..5c90a65fa 100644 --- a/include/boost/process/v2/windows/impl/default_launcher.ipp +++ b/include/boost/process/v2/windows/impl/default_launcher.ipp @@ -66,7 +66,7 @@ namespace windows { if (wc == L'"') *(itr++) = L'\\'; - *(itr++) = wc; + *(itr++) = wc; } *(itr ++) = L'"'; diff --git a/test/v2/environment.cpp b/test/v2/environment.cpp index 58765f054..379e1f709 100644 --- a/test/v2/environment.cpp +++ b/test/v2/environment.cpp @@ -150,7 +150,11 @@ BOOST_AUTO_TEST_CASE(wenvironment) BOOST_CHECK(ec); for (const auto ke : bpe::current()) - BOOST_CHECK_EQUAL(bpe::get(std::get<0>(ke)), std::get<1>(ke)); + { + std::string key = std::get<0>(ke).string(); + printf("Getting env '%s'\n", key.c_str()); + BOOST_CHECK_EQUAL(bpe::get(std::get<0>(ke)), std::get<1>(ke)); + } #if defined(BOOST_PROCESS_V2_WINDOWS) BOOST_CHECK_EQUAL(bpe::key(L"FOO"), bpe::key_view(L"Foo")); diff --git a/test/v2/process.cpp b/test/v2/process.cpp index e786bba80..8999b4320 100644 --- a/test/v2/process.cpp +++ b/test/v2/process.cpp @@ -386,7 +386,10 @@ BOOST_AUTO_TEST_CASE(popen) 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_CHECK_MESSAGE(ec == asio::error::eof + || ec == asio::error::broken_pipe + || ec == asio::error::bad_descriptor, + ec.message()); BOOST_REQUIRE_GE(n, 1u); // remove EOF res.pop_back(); From 15783cb5b07cfd3fb960b86550dffd68e4bc17cf Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 21 Jun 2023 13:23:51 +0800 Subject: [PATCH 15/20] popen test adjustements. --- include/boost/process/v2/windows/with_logon_launcher.hpp | 2 +- test/v2/process.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/boost/process/v2/windows/with_logon_launcher.hpp b/include/boost/process/v2/windows/with_logon_launcher.hpp index 064d3b16c..29c0e1270 100644 --- a/include/boost/process/v2/windows/with_logon_launcher.hpp +++ b/include/boost/process/v2/windows/with_logon_launcher.hpp @@ -20,7 +20,7 @@ namespace windows /// A windows launcher using CreateProcessWithLogon instead of CreateProcess struct with_logon_launcher : default_launcher { - std::wstring username, domain, password; + std::wstring username, password, domain; DWORD logon_flags{0u}; with_logon_launcher(std::wstring username = L"", diff --git a/test/v2/process.cpp b/test/v2/process.cpp index 8999b4320..ba95d5e18 100644 --- a/test/v2/process.cpp +++ b/test/v2/process.cpp @@ -377,7 +377,7 @@ BOOST_AUTO_TEST_CASE(popen) // default CWD bpv::popen proc(/*bpv::default_process_launcher(), */ctx, pth, {"echo"}); - asio::write(proc, asio::buffer("FOOBAR")); + BOOST_CHECK_EQUAL(asio::write(proc, asio::buffer("FOOBAR", 6)), 6); proc.get_stdin().close(); std::string res; @@ -391,10 +391,8 @@ BOOST_AUTO_TEST_CASE(popen) || ec == asio::error::bad_descriptor, ec.message()); BOOST_REQUIRE_GE(n, 1u); - // remove EOF - res.pop_back(); BOOST_CHECK_EQUAL(res, "FOOBAR"); - + proc.get_stdin().close(); proc.wait(); BOOST_CHECK_MESSAGE(proc.exit_code() == 0, proc.exit_code()); } From 799a48c390441cb1c75838af18167e2a34840d7f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Wed, 21 Jun 2023 14:41:50 +0800 Subject: [PATCH 16/20] removed code_as_error. --- include/boost/process/v2/exit_code.hpp | 154 +++--------------------- include/boost/process/v2/impl/error.ipp | 2 +- include/boost/process/v2/process.hpp | 7 +- test/v2/pid.cpp | 8 +- test/v2/process.cpp | 29 ++++- 5 files changed, 51 insertions(+), 149 deletions(-) diff --git a/include/boost/process/v2/exit_code.hpp b/include/boost/process/v2/exit_code.hpp index 3835d9f94..3ee580063 100644 --- a/include/boost/process/v2/exit_code.hpp +++ b/include/boost/process/v2/exit_code.hpp @@ -94,12 +94,19 @@ inline int evaluate_exit_code(int code) #endif - -/** Convert the exit-code in a completion into an error if the actual error isn't set. +/// @{ +/** Helper to subsume an exit-code into an error_code if there's no actual error isn't set. * @code {.cpp} * process proc{ctx, "exit", {"1"}}; * - * proc.async_wait(code_as_error( + * proc.async_wait( + * asio::deferred( + * [&proc](error_code ec, int) + * { + * return asio::deferred.values( + * check_exit_code(ec, proc.native_exit_code()) + * ); + * * [](error_code ec) * { * assert(ec.value() == 10); @@ -107,144 +114,19 @@ inline int evaluate_exit_code(int code) * })); * * @endcode - */ -template -struct code_as_error_t -{ - CompletionToken token_; - const error_category & category; - - template - code_as_error_t(Token_ && token, const error_category & category) - : token_(std::forward(token)), category(category) - { - } -}; - -/// Deduction function for code_as_error_t. -template -code_as_error_t code_as_error( - CompletionToken && token, - const error_category & category = error::get_exit_code_category()) -{ - return code_as_error_t::type>( - std::forward(token), category); -}; - -namespace detail -{ + */ -template -struct code_as_error_handler +inline error_code check_exit_code( + error_code &ec, native_exit_code_type native_code, + const error_category & category = error::get_exit_code_category()) { - typedef void result_type; - - template - code_as_error_handler(H && h, const error_category & category) - : handler_(std::forward(h)), category(category) - { - } - - void operator()(error_code ec, native_exit_code_type code) - { - if (!ec) - BOOST_PROCESS_V2_ASSIGN_EC(ec, code, category) - std::move(handler_)(ec); - } - - - Handler handler_; - const error_category & category; -}; - + if (!ec) + BOOST_PROCESS_V2_ASSIGN_EC(ec, native_code, category); + return ec; } +/// @} BOOST_PROCESS_V2_END_NAMESPACE - -#if !defined(BOOST_PROCESS_V2_STANDALONE) -namespace boost -{ -#endif -namespace asio -{ - -template -struct async_result< - BOOST_PROCESS_V2_NAMESPACE::code_as_error_t, - void(BOOST_PROCESS_V2_NAMESPACE::error_code, - BOOST_PROCESS_V2_NAMESPACE::native_exit_code_type)> -{ - using signature = void(BOOST_PROCESS_V2_NAMESPACE::error_code); - using return_type = typename async_result::return_type; - - - template - struct init_wrapper - { - init_wrapper(Initiation init) - : initiation_(std::move(init)) - { - } - - template - void operator()( - Handler && handler, - const BOOST_PROCESS_V2_NAMESPACE::error_category & cat, - Args && ... args) - { - std::move(initiation_)( - BOOST_PROCESS_V2_NAMESPACE::detail::code_as_error_handler::type>( - std::forward(handler), cat), - std::forward(args)...); - } - - Initiation initiation_; - - }; - - template - static BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(CompletionToken, signature, - (async_initiate( - declval::type> >(), - declval(), - declval()...))) - initiate( - Initiation && initiation, - RawCompletionToken && token, - Args &&... args) - { - return async_initiate( - init_wrapper::type>( - std::forward(initiation)), - token.token_, - token.category, - std::forward(args)...); - } -}; - - - - -template