From 9761be99bbc62776d5fbf2d311d5ab9de2e81dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Ferdinand=20Rivera=20Morell?= Date: Mon, 26 Aug 2024 07:05:48 -0500 Subject: [PATCH 01/28] Add support for modular build structure. (#389) * Make the library modular usable. * Switch to library requirements instead of source. As source puts extra source in install targets. * Add requires-b2 check to top-level build file. * Add missing test deps. * Bump B2 require to 5.2 * Fix duplicate def of boost.process.fs feature. * Add missing boost_test dependency. * Move inter-lib dependencies to a project variable and into the build targets. * Switch to /boost/test//included target for header only mode of Boost.Test. * Adjust doc build to avoid boost-root references. * Update build deps. * Fix link and build of deps. --- build.jam | 46 ++++++++++++++++++++++++++++++++++++++++++ build/Jamfile | 26 ++++++++++-------------- doc/Jamfile.jam | 8 ++++---- example/Jamfile.jam | 2 +- example/v2/Jamfile.jam | 8 +++----- test/v1/Jamfile.jam | 38 +++++++++++++++++----------------- test/v2/Jamfile.jam | 24 +++++++++------------- test/v2/process.cpp | 17 +++++++--------- test/v2/windows.cpp | 4 ---- 9 files changed, 100 insertions(+), 73 deletions(-) create mode 100644 build.jam diff --git a/build.jam b/build.jam new file mode 100644 index 000000000..969e2a1e7 --- /dev/null +++ b/build.jam @@ -0,0 +1,46 @@ +# Copyright René Ferdinand Rivera Morell 2024 +# 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) + +require-b2 5.2 ; + +import feature : feature ; + +feature boost.process.fs : boost std : optional propagated ; + +constant boost_dependencies : + /boost/algorithm//boost_algorithm + /boost/asio//boost_asio + /boost/assert//boost_assert + /boost/config//boost_config + /boost/core//boost_core + /boost/fusion//boost_fusion + /boost/io//boost_io + /boost/iterator//boost_iterator + /boost/move//boost_move + /boost/optional//boost_optional + /boost/system//boost_system + /boost/throw_exception//boost_throw_exception + /boost/tokenizer//boost_tokenizer + /boost/type_index//boost_type_index + /boost/type_traits//boost_type_traits + /boost/utility//boost_utility + /boost/winapi//boost_winapi ; + +project /boost/process + : common-requirements + include + : default-build + boost + ; + +explicit + [ alias boost_process : build//boost_process ] + [ alias all : boost_process example example/v2 test ] + ; + +call-if : boost-library process + : install boost_process + ; + diff --git a/build/Jamfile b/build/Jamfile index d5346eb8e..40192534c 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -5,7 +5,8 @@ import os ; import feature ; -import ../../config/checks/config : requires ; +import-search /boost/config/checks ; +import config : requires ; project : requirements BOOST_ASIO_NO_DEPRECATED @@ -15,11 +16,11 @@ project : requirements windows:WIN32_LEAN_AND_MEAN linux:-lpthread : source-location ../src + : common-requirements + $(boost_dependencies) + std:BOOST_PROCESS_USE_STD_FS=1 ; -feature.feature boost.process.fs : boost std : propagated composite ; -feature.compose std : BOOST_PROCESS_USE_STD_FS=1 ; - alias process_sources : detail/environment_posix.cpp detail/environment_win.cpp @@ -40,26 +41,21 @@ alias process_sources shell.cpp ; -if [ os.name ] = NT -{ - lib shell32 ; - lib advapi32 ; - lib ntdll ; - lib user32 ; - explicit shell32 advapi32 ntdll user32 ; -} +lib shell32 ; +lib advapi32 ; +lib ntdll ; +lib user32 ; lib boost_process : process_sources : requirements BOOST_PROCESS_SOURCE=1 shared:BOOST_PROCESS_DYN_LINK=1 - boost:/boost//filesystem + boost:/boost/filesystem//boost_filesystem windows:shell32 windows:user32 windows:ntdll windows:advapi32 : usage-requirements shared:BOOST_PROCESS_DYN_LINK=1 + boost:/boost/filesystem//boost_filesystem ; - -boost-install boost_process ; diff --git a/doc/Jamfile.jam b/doc/Jamfile.jam index ad9e3949c..5ed200775 100644 --- a/doc/Jamfile.jam +++ b/doc/Jamfile.jam @@ -19,12 +19,12 @@ install images_glob : $(images) : $(BOOST_ROOT)/doc/html/boost_process import type ; type.register XMLPROCESSWORKAROUND : : XML ; import generators ; -generators.register-standard common.copy : XML : XMLPROCESSWORKAROUND ; +generators.register-standard common.copy : XML : XMLPROCESSWORKAROUND ; xmlprocessworkaround posix_pseudocode : v1/posix_pseudocode.xml ; xmlprocessworkaround windows_pseudocode : v1/windows_pseudocode.xml ; -path-constant INCLUDES : ../../.. ; +path-constant INCLUDES : ../include ; doxygen reference_v1 : @@ -66,7 +66,7 @@ doxygen reference_v2 BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(x,y)=deduced \\ BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(X)=Token \\ BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(E)=DEFAULT_TYPE \\ - BOOST_ASIO_DEFAULT_COMPLETION_TOKEN=DEFAULT \\ + BOOST_ASIO_DEFAULT_COMPLETION_TOKEN=DEFAULT \\ BOOST_CONSTEXPR=constexpr \\ BOOST_CXX14_CONSTEXPR=constexpr \\ BOOST_PROCESS_V2_INLINE= \\ @@ -98,7 +98,7 @@ boostbook standalone ############################################################################### alias boostdoc : standalone/docbook - : + : : images_glob : ; explicit boostdoc ; diff --git a/example/Jamfile.jam b/example/Jamfile.jam index 4a9aa06f8..5ec31f042 100644 --- a/example/Jamfile.jam +++ b/example/Jamfile.jam @@ -8,7 +8,7 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) project : requirements - ../../.. + /boost/process//boost_process msvc:_SCL_SECURE_NO_WARNINGS windows:WIN32_LEAN_AND_MEAN ; diff --git a/example/v2/Jamfile.jam b/example/v2/Jamfile.jam index 26da639a2..450fdc21d 100644 --- a/example/v2/Jamfile.jam +++ b/example/v2/Jamfile.jam @@ -4,14 +4,12 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) project : requirements - ../../.. msvc:_SCL_SECURE_NO_WARNINGS windows:WIN32_LEAN_AND_MEAN + static ; import testing ; -alias filesystem : /boost//filesystem : static ; - -exe intro : intro.cpp filesystem ; -exe intro_popen : intro_popen.cpp filesystem ; +exe intro : intro.cpp ; +exe intro_popen : intro_popen.cpp : boost ; diff --git a/test/v1/Jamfile.jam b/test/v1/Jamfile.jam index dd8755147..c75860db2 100644 --- a/test/v1/Jamfile.jam +++ b/test/v1/Jamfile.jam @@ -9,17 +9,13 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -import os ; - -if [ os.name ] = NT -{ - lib ws2_32 ; - lib shell32 ; - lib Advapi32 ; - lib Ntdll ; -} +lib ws2_32 ; +lib shell32 ; +lib Advapi32 ; +lib Ntdll ; project : requirements + /boost/process//boost_process BOOST_ASIO_NO_DEPRECATED msvc:_SCL_SECURE_NO_WARNINGS msvc:_CRT_SECURE_NO_DEPRECATE @@ -28,6 +24,7 @@ project : requirements linux:-lpthread NT,cw:ws2_32 NT,gcc:ws2_32 + /boost/test//included ; @@ -35,16 +32,19 @@ project : requirements import testing ; -alias program_options : /boost//program_options : static ; -alias filesystem : /boost//filesystem ; -alias iostreams : /boost//iostreams ; -alias system : /boost//system ; -alias thread : /boost//thread ; -alias coroutine : /boost//coroutine : static ; +alias program_options : usage-requirements /boost/program_options//boost_program_options ; +alias filesystem : usage-requirements /boost/filesystem//boost_filesystem ; +alias iostreams : usage-requirements /boost/iostreams//boost_iostreams ; +alias system : usage-requirements /boost/system//boost_system ; +alias thread : usage-requirements /boost/thread//boost_thread ; +alias coroutine : usage-requirements /boost/coroutine//boost_coroutine ; +alias scope_exit : usage-requirements /boost/scope_exit//boost_scope_exit ; +alias lambda : usage-requirements /boost/lambda//boost_lambda ; +alias chrono : usage-requirements /boost/chrono//boost_chrono ; lib multi_ref : multi_ref1.cpp multi_ref2.cpp system : windows:shell32 ; -exe sparring_partner : sparring_partner.cpp program_options system filesystem iostreams : +exe sparring_partner : sparring_partner.cpp program_options system filesystem iostreams lambda : off windows:shell32 windows:Ntdll ; @@ -100,15 +100,15 @@ test-suite with-valgrind : [ run env.cpp program_options system filesystem : [ test-options env ] : sparring_partner ] [ run group.cpp system thread filesystem : [ test-options group ] : sub_launch ] [ run group.cpp system thread filesystem : [ test-options group ] : sub_launch : no windows:yes BOOST_USE_WINDOWS_H=1 : group-windows-h ] - [ run group_wait.cpp system thread filesystem : [ test-options group_wait ] : sparring_partner : darwin:no freebsd:no ] + [ run group_wait.cpp system thread filesystem scope_exit : [ test-options group_wait ] : sparring_partner : darwin:no freebsd:no ] [ run limit_fd.cpp program_options system filesystem : [ test-options limit_fd ] : sparring_partner : freebsd:no ] [ run run_exe.cpp filesystem : : sparring_partner ] [ run run_exe_path.cpp filesystem : [ test-options run_exe_path ] : sparring_partner ] [ run search_path.cpp filesystem system : [ test-options search_path ] : : windows:shell32 ] [ run shell.cpp filesystem system : [ test-options shell ] : sparring_partner : darwin:no ] [ run shell_path.cpp filesystem system : [ test-options shell_path ] ] - [ run system_test1.cpp filesystem system : [ test-options system_test1 ] : sparring_partner ] - [ run system_test2.cpp filesystem system : [ test-options system_test2 ] : sparring_partner ] + [ run system_test1.cpp filesystem system chrono : [ test-options system_test1 ] : sparring_partner ] + [ run system_test2.cpp filesystem system chrono : [ test-options system_test2 ] : sparring_partner ] [ run spawn.cpp filesystem system : [ test-options spawn ] : sparring_partner ] [ run start_dir.cpp filesystem system : [ test-options start_dir ] : sparring_partner ] [ run terminate.cpp system filesystem : [ test-options terminate ] : sparring_partner : freebsd:no ] diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 58baacf0f..3b7769601 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -4,19 +4,15 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -import os ; - -if [ os.name ] = NT -{ - lib ws2_32 ; - lib shell32 ; - lib Advapi32 ; - lib Ntdll ; - lib user32 ; - lib Bcrypt ; -} +lib ws2_32 ; +lib shell32 ; +lib Advapi32 ; +lib Ntdll ; +lib user32 ; +lib Bcrypt ; project : requirements + /boost/process//boost_process BOOST_ASIO_NO_DEPRECATED msvc:_SCL_SECURE_NO_WARNINGS msvc:_CRT_SECURE_NO_DEPRECATE @@ -32,21 +28,19 @@ project : requirements NT,gcc:ws2_32 NT,gcc:Bcrypt BOOST_PROCESS_V2_SEPARATE_COMPILATION=1 + /boost/test//included ; import testing ; -alias filesystem : /boost//filesystem : static ; - exe target : target.cpp : off windows:shell32 windows:Ntdll ; -lib test_impl : test_impl.cpp filesystem /boost//process : +lib test_impl : test_impl.cpp /boost/process//boost_process : BOOST_PROCESS_V2_SEPARATE_COMPILATION=1 BOOST_TEST_IGNORE_SIGCHLD=1 - static ; test-suite standalone : diff --git a/test/v2/process.cpp b/test/v2/process.cpp index 0a4009a18..895370dd9 100644 --- a/test/v2/process.cpp +++ b/test/v2/process.cpp @@ -9,9 +9,6 @@ #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) -#if defined(BOOST_FILESYSTEM_DYN_LINK) -#undef BOOST_FILESYSTEM_DYN_LINK -#endif #define BOOST_TEST_IGNORE_SIGCHLD 1 #if true //defined(BOOST_POSIX_API) @@ -55,9 +52,9 @@ BOOST_AUTO_TEST_CASE(exit_code_sync) { using boost::unit_test::framework::master_test_suite; const auto pth = master_test_suite().argv[1]; - + boost::asio::io_context ctx; - + BOOST_CHECK_EQUAL(bpv::process(ctx, pth, {"exit-code", "0"}).wait(), 0); BOOST_CHECK_EQUAL(bpv::execute(bpv::process(ctx, pth, {"exit-code", "1"})), 1); std::vector args = {"exit-code", "2"}; @@ -85,7 +82,7 @@ BOOST_AUTO_TEST_CASE(exit_code_async) int called = 0; printf("Setting up processes\n"); - + bpv::process proc1(ctx, pth, {"exit-code", "0"}); bpv::process proc3(ctx, pth, {"exit-code", "2"}); bpv::process proc4(ctx, pth, {"exit-code", "42"}); @@ -200,7 +197,7 @@ BOOST_AUTO_TEST_CASE(print_args_out) { using boost::unit_test::framework::master_test_suite; const auto pth = master_test_suite().argv[1]; - + asio::io_context ctx; asio::readable_pipe rp{ctx}; @@ -296,7 +293,7 @@ BOOST_AUTO_TEST_CASE(echo_file) { using boost::unit_test::framework::master_test_suite; const auto pth = master_test_suite().argv[1]; - + asio::io_context ctx; asio::readable_pipe rp{ctx}; @@ -476,7 +473,7 @@ BOOST_AUTO_TEST_CASE(environment) sub_env.push_back("FOOBAR=FOO-BAR"); BOOST_CHECK_EQUAL("FOO-BAR", read_env("FOOBAR", bpv::process_environment{sub_env})); - + sub_env.push_back("XYZ=ZYX"); auto itr = std::find_if(sub_env.begin(), sub_env.end(), [](const bpv::environment::key_value_pair & kv) {return kv.key() == bpv::environment::key("PATH");}); path += static_cast(bpv::environment::delimiter); @@ -511,7 +508,7 @@ BOOST_AUTO_TEST_CASE(exit_code_as_error) bpv::process proc3(ctx, pth, {"sleep", "2000"}); int called = 0; - + proc3.terminate(); diff --git a/test/v2/windows.cpp b/test/v2/windows.cpp index b58cb5983..254f1ad7d 100644 --- a/test/v2/windows.cpp +++ b/test/v2/windows.cpp @@ -9,10 +9,6 @@ #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) -#if defined(BOOST_FILESYSTEM_DYN_LINK) -#undef BOOST_FILESYSTEM_DYN_LINK -#endif - // Test that header file is self-contained. #include From 54479a737238f25a183971dff4e58df2298b5609 Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Mon, 30 Sep 2024 10:09:45 +0200 Subject: [PATCH 02/28] remove dllimport from utf8.hpp to fix MSVC build --- include/boost/process/v2/detail/utf8.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/boost/process/v2/detail/utf8.hpp b/include/boost/process/v2/detail/utf8.hpp index 86add628d..a31cdff4d 100644 --- a/include/boost/process/v2/detail/utf8.hpp +++ b/include/boost/process/v2/detail/utf8.hpp @@ -23,8 +23,7 @@ BOOST_PROCESS_V2_DECL std::size_t convert_to_wide(const char * in, std::size_ template, typename Allocator = std::allocator, typename CharIn, - typename = typename std::enable_if::value>::type> -BOOST_PROCESS_V2_DECL + typename = typename std::enable_if::value>::type> std::basic_string conv_string( const CharIn * data, std::size_t size, const Allocator allocator = Allocator{}) @@ -35,8 +34,7 @@ std::basic_string conv_string( template, typename Allocator = std::allocator, - typename = typename std::enable_if::value>::type> -BOOST_PROCESS_V2_DECL + typename = typename std::enable_if::value>::type> std::basic_string conv_string( const wchar_t * data, std::size_t size, const Allocator allocator = Allocator{}) @@ -59,8 +57,7 @@ std::basic_string conv_string( template, typename Allocator = std::allocator, - typename = typename std::enable_if::value>::type> -BOOST_PROCESS_V2_DECL + typename = typename std::enable_if::value>::type> std::basic_string conv_string( const char * data, std::size_t size, const Allocator allocator = Allocator{}) From 8df45b8f6861ed6bbc87f9b351942c0b239c7982 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 31 Aug 2024 09:33:20 +0200 Subject: [PATCH 03/28] Fix undefined reference to ws2_32 else it fails to link on mingw: ``` process_handle_windows.o:process_handle_windows.cpp:(.text+0x25): undefined reference to `_imp__WSACleanup@0' ``` --- build/Jamfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/Jamfile b/build/Jamfile index 40192534c..50db715c2 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -45,6 +45,7 @@ lib shell32 ; lib advapi32 ; lib ntdll ; lib user32 ; +lib ws2_32 ; lib boost_process : process_sources @@ -55,6 +56,7 @@ lib boost_process windows:user32 windows:ntdll windows:advapi32 + windows:ws2_32 : usage-requirements shared:BOOST_PROCESS_DYN_LINK=1 boost:/boost/filesystem//boost_filesystem From 642bd7cf5c3dd45391e7473dcb99762ccf740737 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 06:52:36 +0800 Subject: [PATCH 04/28] removed more faulty V2_DECLs --- doc/v2/introduction.qbk | 8 -------- include/boost/process/v2/ext/cmd.hpp | 4 ++-- include/boost/process/v2/ext/cwd.hpp | 4 ++-- include/boost/process/v2/ext/env.hpp | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/doc/v2/introduction.qbk b/doc/v2/introduction.qbk index 18029c3c0..f762296e5 100644 --- a/doc/v2/introduction.qbk +++ b/doc/v2/introduction.qbk @@ -73,14 +73,6 @@ Instead of using ascii-APIs on windows, process V2 just assumes UTF-8 everywhere [endsect] -[section:src Separate compilation] - -Boost.process v2 supports separate compilation similar to other boost libraries. -It can be achieved by defining `BOOST_PROCESS_V2_SEPARATE_COMPILATION` and including -`` in a single compile unit. - -[endsect] - [section:limit_fd Fd safe by default] While not a problem on windows (since HANDLEs get manually enabled for inheritance), diff --git a/include/boost/process/v2/ext/cmd.hpp b/include/boost/process/v2/ext/cmd.hpp index 494df858c..6308885eb 100644 --- a/include/boost/process/v2/ext/cmd.hpp +++ b/include/boost/process/v2/ext/cmd.hpp @@ -36,7 +36,7 @@ BOOST_PROCESS_V2_DECL shell cmd(HANDLE handle); #endif template -BOOST_PROCESS_V2_DECL shell cmd(basic_process_handle & handle, error_code & ec) +inline shell cmd(basic_process_handle & handle, error_code & ec) { #if defined(BOOST_PROCESS_V2_WINDOWS) return cmd(handle.native_handle(), ec); @@ -46,7 +46,7 @@ BOOST_PROCESS_V2_DECL shell cmd(basic_process_handle & handle, error_c } template -BOOST_PROCESS_V2_DECL shell cmd(basic_process_handle & handle) +inline shell cmd(basic_process_handle & handle) { #if defined(BOOST_PROCESS_V2_WINDOWS) return cmd(handle.native_handle()); diff --git a/include/boost/process/v2/ext/cwd.hpp b/include/boost/process/v2/ext/cwd.hpp index 703b1ac3b..07e76cf30 100644 --- a/include/boost/process/v2/ext/cwd.hpp +++ b/include/boost/process/v2/ext/cwd.hpp @@ -27,7 +27,7 @@ BOOST_PROCESS_V2_DECL filesystem::path cwd(pid_type pid, error_code & ec); BOOST_PROCESS_V2_DECL filesystem::path cwd(pid_type pid); template -BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle & handle, error_code & ec) +inline filesystem::path cwd(basic_process_handle & handle, error_code & ec) { #if defined(BOOST_PROCESS_V2_WINDOWS) return cwd(handle.native_handle(), ec); @@ -37,7 +37,7 @@ BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle & hand } template -BOOST_PROCESS_V2_DECL filesystem::path cwd(basic_process_handle & handle) +inline filesystem::path cwd(basic_process_handle & handle) { #if defined(BOOST_PROCESS_V2_WINDOWS) return cwd(handle.native_handle()); diff --git a/include/boost/process/v2/ext/env.hpp b/include/boost/process/v2/ext/env.hpp index 9a30a7fd0..8c634739a 100644 --- a/include/boost/process/v2/ext/env.hpp +++ b/include/boost/process/v2/ext/env.hpp @@ -120,7 +120,7 @@ BOOST_PROCESS_V2_DECL env_view env(pid_type pid, error_code & ec); BOOST_PROCESS_V2_DECL env_view env(pid_type pid); template -BOOST_PROCESS_V2_DECL env_view env(basic_process_handle & handle, error_code & ec) +inline env_view env(basic_process_handle & handle, error_code & ec) { #if defined(BOOST_PROCESS_V2_WINDOWS) return env(handle.native_handle(), ec); @@ -130,7 +130,7 @@ BOOST_PROCESS_V2_DECL env_view env(basic_process_handle & handle, erro } template -BOOST_PROCESS_V2_DECL env_view env(basic_process_handle & handle) +inline env_view env(basic_process_handle & handle) { #if defined(BOOST_PROCESS_V2_WINDOWS) return env(handle.native_handle()); From 211a3134b6867a98ee25a39e6b8bac396caffdfd Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 24 Aug 2024 03:41:27 -0400 Subject: [PATCH 05/28] Fix building on OpenBSD OpenBSD does not have close_range() nor does NetBSD. OpenBSD needs environ like the other *BSD's. The build was erroring on kp_pid, it looks like p_pid is appropriate. --- include/boost/process/v2/posix/default_launcher.hpp | 2 +- src/pid.cpp | 4 ++-- src/posix/close_handles.cpp | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index 9cfec4b2a..3645f9cba 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -29,7 +29,7 @@ #include -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__MACH__) +#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__MACH__) extern "C" { extern char **environ; } #endif diff --git a/src/pid.cpp b/src/pid.cpp index f32df9ecc..5f29ea36c 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -551,9 +551,9 @@ std::vector all_pids(boost::system::error_code & ec) vec.reserve(cntp); for (int i = cntp - 1; i >= 0; i--) { - if (proc_info[i].kp_pid >= 0) + if (proc_info[i].p_pid >= 0) { - vec.push_back(proc_info[i].kp_pid); + vec.push_back(proc_info[i].p_pid); } } } diff --git a/src/posix/close_handles.cpp b/src/posix/close_handles.cpp index 39d63e6dd..11ed214b9 100644 --- a/src/posix/close_handles.cpp +++ b/src/posix/close_handles.cpp @@ -17,10 +17,9 @@ // linux has close_range since 5.19 -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) // https://www.freebsd.org/cgi/man.cgi?query=close_range&apropos=0&sektion=0&manpath=FreeBSD+13.1-RELEASE+and+Ports&arch=default&format=html -// https://man.netbsd.org/closefrom.3 // __FreeBSD__ // // gives us @@ -219,4 +218,4 @@ void close_all(const std::vector & whitelist, error_code & ec) BOOST_PROCESS_V2_END_NAMESPACE -#endif \ No newline at end of file +#endif From f741b0d120e05d00d97bfbf228b89b45016ab913 Mon Sep 17 00:00:00 2001 From: Samuel Venable Date: Mon, 5 Aug 2024 19:53:05 -0400 Subject: [PATCH 06/28] [DragonFly BSD] Use Proper CWD From PID Code --- src/ext/cwd.cpp | 53 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index b88a4df26..3345d33b9 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -46,8 +46,10 @@ #endif #if defined(__DragonFly__) +#include #include -#include +#include +#include #endif #ifdef BOOST_PROCESS_USE_STD_FS @@ -152,53 +154,14 @@ 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) { - /* filesystem::path path; - // Official API (broken OS-level) - including code from DragonFly's fstat(1) - // command line interface utility currently requires way too much code FWIW. - std::size_t sz = 4, len = 0; + char buffer[PATH_MAX]; + std::size_t sz = 4, len = sizeof(buffer); int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_CWD, pid}; - if (sysctl(mib, sz, nullptr, &len, nullptr, 0) == 0) - { - std::vector vecbuff; - vecbuff.resize(len); - if (sysctl(mib, sz, &vecbuff[0], &len, nullptr, 0) == 0) - { - path = filesystem::canonical(&vecbuff[0], ec); - } - else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) - } - else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) - return path; - */ - - filesystem::path path; - /* Probably the hackiest thing ever we are doing here, because the official API is broken OS-level. */ - FILE *fp = popen(("pos=`ans=\\`/usr/bin/fstat -w -p " + std::to_string(pid) + " | /usr/bin/sed -n 1p\\`; " + - "/usr/bin/awk -v ans=\"$ans\" 'BEGIN{print index(ans, \"INUM\")}'`; str=`/usr/bin/fstat -w -p " + - std::to_string(pid) + " | /usr/bin/sed -n 3p`; /usr/bin/awk -v str=\"$str\" -v pos=\"$pos\" " + - "'BEGIN{print substr(str, 0, pos + 4)}' | /usr/bin/awk 'NF{NF--};1 {$1=$2=$3=$4=\"\"; print" + - " substr($0, 5)'}").c_str(), "r"); - if (fp) + if (sysctl(mib, sz, buffer, &len, nullptr, 0) == 0) { - char buffer[PATH_MAX]; - if (fgets(buffer, sizeof(buffer), fp)) - { - std::string str = buffer; - std::size_t pos = str.find("\n", strlen(buffer) - 1); - if (pos != std::string::npos) - { - str.replace(pos, 1, ""); - } - path = filesystem::canonical(str.c_str(), ec); - } - else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) - if (pclose(fp) == -1) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) - } + path = filesystem::canonical(buffer, ec); + } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return path; From 12192d35d3a32d3bda07d5d03f3dfe989165f70f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 07:21:51 +0800 Subject: [PATCH 07/28] Applying @sehe's patch. closes #317 --- include/boost/process/v1/pipe.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/process/v1/pipe.hpp b/include/boost/process/v1/pipe.hpp index 7607acbb7..a852b8117 100644 --- a/include/boost/process/v1/pipe.hpp +++ b/include/boost/process/v1/pipe.hpp @@ -257,7 +257,16 @@ struct basic_pipebuf : std::basic_streambuf { if (!is_open()) return nullptr; - overflow(Traits::eof()); + try { + overflow(Traits::eof()); + _pipe.close(); + return this; + } + catch(...) + { + _pipe.close(); + throw ; + } return this; } private: From c492c9306265bdf2d91df7ec4c678903bb51d272 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 07:39:16 +0800 Subject: [PATCH 08/28] Added BOOST_PROCESS_V2_POSIX_FORCE_DISABLE_CLOSE_RANGE Implements #378. --- build.jam | 1 + build/Jamfile | 1 + src/posix/close_handles.cpp | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.jam b/build.jam index 969e2a1e7..a33b5f0ae 100644 --- a/build.jam +++ b/build.jam @@ -8,6 +8,7 @@ require-b2 5.2 ; import feature : feature ; feature boost.process.fs : boost std : optional propagated ; +feature boost.process.disable-close-range : on off : optional ; constant boost_dependencies : /boost/algorithm//boost_algorithm diff --git a/build/Jamfile b/build/Jamfile index 50db715c2..db0ed8d39 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -52,6 +52,7 @@ lib boost_process : requirements BOOST_PROCESS_SOURCE=1 shared:BOOST_PROCESS_DYN_LINK=1 boost:/boost/filesystem//boost_filesystem + on:BOOST_PROCESS_V2_POSIX_FORCE_DISABLE_CLOSE_RANGE=1 windows:shell32 windows:user32 windows:ntdll diff --git a/src/posix/close_handles.cpp b/src/posix/close_handles.cpp index 11ed214b9..dc3fbe406 100644 --- a/src/posix/close_handles.cpp +++ b/src/posix/close_handles.cpp @@ -44,7 +44,8 @@ int fdwalk(int (*func)(void *, int), void *cd); #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) // kernel has close_range +// kernel has close_range +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0) && !defined(BOOST_PROCESS_V2_POSIX_FORCE_DISABLE_CLOSE_RANGE) // version is included by stdlib.h #include #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 34) // glibc is compiled with close_range support From 9f104634a9c106d80819212ced4f77a0094bcd45 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 07:49:56 +0800 Subject: [PATCH 09/28] Typo fix. Closes #365 --- include/boost/process/v2/environment.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/process/v2/environment.hpp b/include/boost/process/v2/environment.hpp index ec51f5248..dec87ac10 100644 --- a/include/boost/process/v2/environment.hpp +++ b/include/boost/process/v2/environment.hpp @@ -764,7 +764,7 @@ struct value value& operator=( const Source& source ) { value_ = BOOST_PROCESS_V2_NAMESPACE::detail::conv_string( - source.data(), source.size); + source.data(), source.size()); return *this; } From 46b71d5e96e7a82860841c6015cc487525124c3e Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 08:13:48 +0800 Subject: [PATCH 10/28] Switched #error to ENOTSUP for ext libs. Should help #413 Closes #358. --- src/ext/cmd.cpp | 6 +++++- src/ext/cwd.cpp | 6 +++++- src/ext/exe.cpp | 6 +++++- src/pid.cpp | 16 +++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index d74a06ef4..c526c1e88 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -394,7 +394,11 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } #else -#error "Platform not supported" +filesystem::path cmd(boost::process::v2::pid_type, boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + return ""; +} #endif shell cmd(boost::process::v2::pid_type pid) diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index 3345d33b9..6f13eb83c 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -197,7 +197,11 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code } #else -#error "Platform not supported" +filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + return ""; +} #endif filesystem::path cwd(boost::process::v2::pid_type pid) diff --git a/src/ext/exe.cpp b/src/ext/exe.cpp index 824826447..8a57d9826 100644 --- a/src/ext/exe.cpp +++ b/src/ext/exe.cpp @@ -175,7 +175,11 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code } #else -#error "Platform not supported" +filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + return ""; +} #endif filesystem::path exe(boost::process::v2::pid_type pid) diff --git a/src/pid.cpp b/src/pid.cpp index 5f29ea36c..ff5f1b1cc 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -727,7 +727,21 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } #else -#error "Platform not supported" +std::vector all_pids(boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); + return {}; +} +pid_type parent_pid(pid_type pid, boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); + return pid; +} +std::vector child_pids(pid_type, boost::system::error_code & ec) +{ + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); + return {}; +} #endif std::vector all_pids() From a96f7a04e0af195ea4ede80409a604bc6138696c Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 09:09:08 +0800 Subject: [PATCH 11/28] Wrapped proc_info.h functions with IOS check. Using the ext functions will yield a operation_not_supported at runtime. Closes #401. --- src/ext/cmd.cpp | 11 +++++++---- src/ext/cwd.cpp | 9 ++++++--- src/ext/env.cpp | 11 +++++++---- src/ext/exe.cpp | 9 ++++++--- src/ext/proc_info.cpp | 8 -------- src/pid.cpp | 9 ++++++--- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index c526c1e88..e3392d281 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -23,9 +23,12 @@ #endif #if (defined(__APPLE__) && defined(__MACH__)) -#include -#include -#include +#include +#if !TARGET_OS_IOS + #include + #include + #include +#endif #endif #if (defined(__linux__) || defined(__ANDROID__)) @@ -156,7 +159,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } -#elif (defined(__APPLE__) && defined(__MACH__)) +#elif (defined(__APPLE__) && defined(__MACH__)) && !TARGET_OS_IOS shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index 6f13eb83c..63a351c1b 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -24,8 +24,11 @@ #endif #if (defined(__APPLE__) && defined(__MACH__)) -#include -#include +#include +#if !TARGET_OS_IOS + #include + #include +#endif #endif #if (defined(BOOST_PROCESS_V2_WINDOWS) || defined(__linux__) || defined(__ANDROID__) || defined(__sun)) @@ -100,7 +103,7 @@ filesystem::path cwd(HANDLE proc) return res; } -#elif (defined(__APPLE__) && defined(__MACH__)) +#elif (defined(__APPLE__) && defined(__MACH__)) && !TARGET_OS_IOS filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { diff --git a/src/ext/env.cpp b/src/ext/env.cpp index 1a6ebd43d..bae3e68c3 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -21,9 +21,12 @@ #endif #if (defined(__APPLE__) && defined(__MACH__)) -#include -#include -#include +#include +#if !TARGET_OS_IOS + #include + #include + #include +#endif #endif #if (defined(__linux__) || defined(__ANDROID__)) @@ -229,7 +232,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) return {}; } -#elif (defined(__APPLE___) || defined(__MACH__)) +#elif (defined(__APPLE___) || defined(__MACH__)) && !TARGET_OS_IOS env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) { diff --git a/src/ext/exe.cpp b/src/ext/exe.cpp index 8a57d9826..ce1b273cf 100644 --- a/src/ext/exe.cpp +++ b/src/ext/exe.cpp @@ -25,8 +25,11 @@ #endif #if (defined(__APPLE__) && defined(__MACH__)) -#include -#include +#include +#if !TARGET_OS_IOS + #include + #include +#endif #endif #if (defined(BOOST_PROCESS_V2_WINDOWS) || defined(__linux__) || defined(__ANDROID__) || defined(__sun)) @@ -113,7 +116,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code return ""; } -#elif (defined(__APPLE__) && defined(__MACH__)) +#elif (defined(__APPLE__) && defined(__MACH__)) && !TARGET_OS_IOS filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code & ec) { diff --git a/src/ext/proc_info.cpp b/src/ext/proc_info.cpp index d4314433f..57ec6a08b 100644 --- a/src/ext/proc_info.cpp +++ b/src/ext/proc_info.cpp @@ -16,14 +16,6 @@ #include -#if (defined(__APPLE__) && defined(__MACH__)) -#include -#include -#include -#include -#include -#endif - BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail diff --git a/src/pid.cpp b/src/pid.cpp index ff5f1b1cc..d6ab609e9 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -17,8 +17,11 @@ #endif #if (defined(__APPLE__) && defined(__MACH__)) -#include -#include +#include +#if !TARGET_OS_IOS + #include + #include +#endif #endif #if (defined(__linux__) || defined(__ANDROID__)) @@ -140,7 +143,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) return vec; } -#elif (defined(__APPLE__) && defined(__MACH__)) +#elif (defined(__APPLE__) && defined(__MACH__)) && !TARGET_OS_IOS std::vector all_pids(boost::system::error_code & ec) { From 7ed164803202bbfbb015e98799f1470f637b6912 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 09:32:39 +0800 Subject: [PATCH 12/28] removed filesystem from the compiled lib. Shuold fix #390. --- include/boost/process/v2/detail/environment_posix.hpp | 9 ++++++++- include/boost/process/v2/detail/environment_win.hpp | 10 +++++++++- src/detail/environment_posix.cpp | 5 +++-- src/detail/environment_win.cpp | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/boost/process/v2/detail/environment_posix.hpp b/include/boost/process/v2/detail/environment_posix.hpp index e945a86c2..21b23428a 100644 --- a/include/boost/process/v2/detail/environment_posix.hpp +++ b/include/boost/process/v2/detail/environment_posix.hpp @@ -69,7 +69,14 @@ BOOST_PROCESS_V2_DECL native_iterator next(native_handle_type nh); BOOST_PROCESS_V2_DECL native_iterator find_end(native_handle_type nh); inline const char_type * dereference(native_iterator iterator) {return *iterator;} -BOOST_PROCESS_V2_DECL bool is_executable(const filesystem::path & pth, error_code & ec); +BOOST_PROCESS_V2_DECL bool has_x_access(const char * pth); + +inline bool is_executable(const filesystem::path & pth, error_code & ec) +{ + return filesystem::is_regular_file(pth, ec) && has_x_access(pth.c_str()); +} + +BOOST_PROCESS_V2_DECL } diff --git a/include/boost/process/v2/detail/environment_win.hpp b/include/boost/process/v2/detail/environment_win.hpp index c36dfd752..d01aad369 100644 --- a/include/boost/process/v2/detail/environment_win.hpp +++ b/include/boost/process/v2/detail/environment_win.hpp @@ -203,7 +203,15 @@ struct native_handle_deleter inline const char_type * dereference(native_iterator iterator) {return iterator;} BOOST_PROCESS_V2_DECL native_iterator next(native_iterator nh); BOOST_PROCESS_V2_DECL native_iterator find_end(native_handle_type nh); -BOOST_PROCESS_V2_DECL bool is_executable(const filesystem::path & pth, error_code & ec); + + +BOOST_PROCESS_V2_DECL bool is_exec_type(const wchar_t * pth); + +inline bool is_executable(const filesystem::path & pth, error_code & ec) +{ + return filesystem::is_regular_file(pth, ec) && is_exec_type(pth.c_str()); +} + } } diff --git a/src/detail/environment_posix.cpp b/src/detail/environment_posix.cpp index f910b776c..077e4fe6b 100644 --- a/src/detail/environment_posix.cpp +++ b/src/detail/environment_posix.cpp @@ -65,9 +65,10 @@ native_iterator find_end(native_handle_type nh) nh++; return nh; } -bool is_executable(const filesystem::path & p, error_code & ec) + +BOOST_PROCESS_V2_DECL bool has_x_access(const char * pth) { - return filesystem::is_regular_file(p, ec) && (::access(p.c_str(), X_OK) == 0); + return (::access(pth, X_OK) == 0); } } diff --git a/src/detail/environment_win.cpp b/src/detail/environment_win.cpp index 7de6aecdb..cbd64c6f6 100644 --- a/src/detail/environment_win.cpp +++ b/src/detail/environment_win.cpp @@ -125,9 +125,9 @@ native_iterator find_end(native_handle_type nh) return ++nh; } -bool is_executable(const filesystem::path & pth, error_code & ec) +bool is_exec_type(const wchar_t * pth) { - return filesystem::is_regular_file(pth, ec) && SHGetFileInfoW(pth.native().c_str(), 0,0,0, SHGFI_EXETYPE); + return SHGetFileInfoW(pth, 0,0,0, SHGFI_EXETYPE); } } From 894f3718988fd0ec1810f4255858a54b1f890460 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 09:46:31 +0800 Subject: [PATCH 13/28] typo fixes. --- include/boost/process/v2/detail/environment_posix.hpp | 2 -- src/detail/environment_posix.cpp | 2 +- src/ext/cmd.cpp | 2 +- src/ext/cwd.cpp | 2 +- src/ext/env.cpp | 2 +- src/ext/exe.cpp | 4 ++-- src/ext/proc_info.cpp | 2 +- src/shell.cpp | 2 +- 8 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/boost/process/v2/detail/environment_posix.hpp b/include/boost/process/v2/detail/environment_posix.hpp index 21b23428a..756432d66 100644 --- a/include/boost/process/v2/detail/environment_posix.hpp +++ b/include/boost/process/v2/detail/environment_posix.hpp @@ -76,8 +76,6 @@ inline bool is_executable(const filesystem::path & pth, error_code & ec) return filesystem::is_regular_file(pth, ec) && has_x_access(pth.c_str()); } -BOOST_PROCESS_V2_DECL - } } diff --git a/src/detail/environment_posix.cpp b/src/detail/environment_posix.cpp index 077e4fe6b..c3006ca15 100644 --- a/src/detail/environment_posix.cpp +++ b/src/detail/environment_posix.cpp @@ -66,7 +66,7 @@ native_iterator find_end(native_handle_type nh) return nh; } -BOOST_PROCESS_V2_DECL bool has_x_access(const char * pth) +bool has_x_access(const char * pth) { return (::access(pth, X_OK) == 0); } diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index e3392d281..3a5ea9e3a 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -399,7 +399,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) #else filesystem::path cmd(boost::process::v2::pid_type, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) return ""; } #endif diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index 63a351c1b..d9a0dc7aa 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -202,7 +202,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code #else filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) return ""; } #endif diff --git a/src/ext/env.cpp b/src/ext/env.cpp index bae3e68c3..bddd8cd71 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -174,7 +174,7 @@ env_view env(HANDLE proc, boost::system::error_code & ec) if (error) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, error, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()) return {}; } diff --git a/src/ext/exe.cpp b/src/ext/exe.cpp index ce1b273cf..5240d2516 100644 --- a/src/ext/exe.cpp +++ b/src/ext/exe.cpp @@ -173,14 +173,14 @@ 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) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) return ""; } #else filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) return ""; } #endif diff --git a/src/ext/proc_info.cpp b/src/ext/proc_info.cpp index 57ec6a08b..22bdfa0d8 100644 --- a/src/ext/proc_info.cpp +++ b/src/ext/proc_info.cpp @@ -43,7 +43,7 @@ std::wstring cwd_cmd_from_proc(HANDLE proc, int type, boost::system::error_code if (error) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, error, boost::system::system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()) return {}; } diff --git a/src/shell.cpp b/src/shell.cpp index 0fffc501a..b563819e6 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -38,7 +38,7 @@ struct shell_category_t final : public error_category const char* name() const noexcept { - return "process.v2.utf8"; + return "process.v2.shell"; } std::string message(int value) const { From 928674d2e3edd98f33f588f75a89bab5302d94fb Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 10:06:23 +0800 Subject: [PATCH 14/28] added test async_wait cancellation test. --- test/v2/process.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/v2/process.cpp b/test/v2/process.cpp index 895370dd9..4daa734c1 100644 --- a/test/v2/process.cpp +++ b/test/v2/process.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -639,6 +640,30 @@ BOOST_AUTO_TEST_CASE(async_request_exit) ctx.run(); } +BOOST_AUTO_TEST_CASE(async_cancel_wait) +{ + asio::io_context ctx; + using boost::unit_test::framework::master_test_suite; + const auto pth = bpv::filesystem::absolute(master_test_suite().argv[1]); + + bpv::process proc(ctx, pth, {"sleep", "1000"}); + + asio::steady_timer tim{ctx, std::chrono::milliseconds(250)}; + asio::cancellation_signal sig; + + // check that the async_wait gets properly cancelled + proc.async_wait(asio::cancel_after(std::chrono::milliseconds(100), + [&](boost::system::error_code ec, int) + { + BOOST_CHECK(ec == asio::error::operation_aborted); + BOOST_CHECK(proc.running()); + if (proc.running()) + proc.terminate(); + })); + + ctx.run(); +} + BOOST_AUTO_TEST_SUITE_END(); From eb6b49c090a4debd942ca7f646d144ed92ae574c Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 10:25:30 +0800 Subject: [PATCH 15/28] disabled /boost//coroutine dependent tests --- test/v1/Jamfile.jam | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/v1/Jamfile.jam b/test/v1/Jamfile.jam index c75860db2..51c73f19f 100644 --- a/test/v1/Jamfile.jam +++ b/test/v1/Jamfile.jam @@ -37,7 +37,6 @@ alias filesystem : usage-requirements /boost/filesystem//boost_fi alias iostreams : usage-requirements /boost/iostreams//boost_iostreams ; alias system : usage-requirements /boost/system//boost_system ; alias thread : usage-requirements /boost/thread//boost_thread ; -alias coroutine : usage-requirements /boost/coroutine//boost_coroutine ; alias scope_exit : usage-requirements /boost/scope_exit//boost_scope_exit ; alias lambda : usage-requirements /boost/lambda//boost_lambda ; alias chrono : usage-requirements /boost/chrono//boost_chrono ; @@ -123,13 +122,10 @@ test-suite with-valgrind : : bare ; test-suite without-valgrind : - [ run async_system_future.cpp filesystem system coroutine : [ test-options async_system_future ] : sparring_partner : static msvc:/bigobj ] - [ run async_system_stackful.cpp filesystem system coroutine : [ test-options async_system_stackful ] : sparring_partner : static msvc:/bigobj ] + [ run async_system_future.cpp filesystem system : [ test-options async_system_future ] : sparring_partner : static msvc:/bigobj ] +# [ run async_system_stackful.cpp filesystem system coroutine : [ test-options async_system_stackful ] : sparring_partner : static msvc:/bigobj ] # [ run async_system_stackful_error.cpp filesystem system coroutine : [ test-options async_system_stackful_error ] : sparring_partner : static msvc:/bigobj ] - [ run async_system_stackful_except.cpp filesystem system coroutine : [ test-options async_system_stackful_except ] : sparring_partner : static msvc:/bigobj ] - [ run async_system_stackless.cpp filesystem system coroutine : [ test-options async_system_stackless ] : sparring_partner : static msvc:/bigobj ] +# [ run async_system_stackful_except.cpp filesystem system coroutine : [ test-options async_system_stackful_except ] : sparring_partner : static msvc:/bigobj ] + [ run async_system_stackless.cpp filesystem system : [ test-options async_system_stackless ] : sparring_partner : static msvc:/bigobj ] [ run vfork.cpp system filesystem : [ test-options vfork ] : sparring_partner : no linux:yes ] ; - - -alias v2-tests : v2//standalone v2//with_target ; \ No newline at end of file From a44fd24523bce226b3ac6a72fcdb3e8f9282f7b6 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 11:46:58 +0800 Subject: [PATCH 16/28] unified cancellation on process.async_wait() --- .../boost/process/v2/detail/process_handle_fd.hpp | 1 + .../v2/detail/process_handle_fd_or_signal.hpp | 9 ++++++++- .../process/v2/detail/process_handle_signal.hpp | 1 + .../process/v2/detail/process_handle_windows.hpp | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/boost/process/v2/detail/process_handle_fd.hpp b/include/boost/process/v2/detail/process_handle_fd.hpp index ba12c7f73..7a94dd0d0 100644 --- a/include/boost/process/v2/detail/process_handle_fd.hpp +++ b/include/boost/process/v2/detail/process_handle_fd.hpp @@ -299,6 +299,7 @@ struct basic_process_handle_fd template void operator()(Self &&self) { + self.reset_cancellation_state(asio::enable_total_cancellation()); error_code ec; native_exit_code_type exit_code{}; int wait_res = -1; diff --git a/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp b/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp index 9dc6d93c4..97d9400a0 100644 --- a/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp +++ b/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp @@ -329,8 +329,15 @@ struct basic_process_handle_fd_or_signal pid_type pid_; bool needs_post = true; + template - void operator()(Self &&self, error_code ec = {}, int = 0) + void operator()(Self &&self, error_code ec, int = 0) { native_exit_code_type exit_code{}; int wait_res = -1; diff --git a/include/boost/process/v2/detail/process_handle_signal.hpp b/include/boost/process/v2/detail/process_handle_signal.hpp index 0c27a547a..ca486b343 100644 --- a/include/boost/process/v2/detail/process_handle_signal.hpp +++ b/include/boost/process/v2/detail/process_handle_signal.hpp @@ -292,6 +292,7 @@ struct basic_process_handle_signal template void operator()(Self &&self) { + self.reset_cancellation_state(asio::enable_total_cancellation()); handle.async_wait(std::move(self)); handle.cancel(); // we cancel so we end up on the signal-sets executor diff --git a/include/boost/process/v2/detail/process_handle_windows.hpp b/include/boost/process/v2/detail/process_handle_windows.hpp index 274caf7b3..e92b86539 100644 --- a/include/boost/process/v2/detail/process_handle_windows.hpp +++ b/include/boost/process/v2/detail/process_handle_windows.hpp @@ -288,6 +288,17 @@ struct basic_process_handle_win template void operator()(Self &&self) { + + self.reset_cancellation_state(asio::enable_total_cancellation()); + auto sl = self.get_cancellation_state().slot(); + auto & h = handle; + if (sl.is_connected()) + sl.assign( + [&h](asio::cancellation_type ct) + { + boost::system::error_code ec; + h.cancel(ec); + }); handle.async_wait(std::move(self)); } @@ -295,6 +306,9 @@ struct basic_process_handle_win void operator()(Self &&self, error_code ec) { native_exit_code_type exit_code{}; + if (ec == asio::error::operation_aborted && !self.get_cancellation_state().cancelled()) + return handle.async_wait(std::move(self)); + if (!ec) detail::get_exit_code_(handle.native_handle(), exit_code, ec); std::move(self).complete(ec, exit_code); From 36954338d870faeaad634f8755c89e37a2b158ce Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 12:04:52 +0800 Subject: [PATCH 17/28] remove test_impl lib --- test/v2/Jamfile.jam | 22 ++++++++++------------ test/v2/test_impl.cpp | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 3b7769601..01b93e502 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -36,24 +36,22 @@ import testing ; exe target : target.cpp : off windows:shell32 windows:Ntdll + ; -lib test_impl : test_impl.cpp /boost/process//boost_process : - BOOST_PROCESS_V2_SEPARATE_COMPILATION=1 - BOOST_TEST_IGNORE_SIGCHLD=1 - ; +local test_impl = test_impl.cpp /boost/process//boost_process /boost/test//boost_unit_test_framework ; test-suite standalone : - [ run utf8.cpp test_impl ] - [ run cstring_ref.cpp test_impl ] - [ run environment.cpp test_impl ] - [ run shell.cpp test_impl ] + [ run utf8.cpp $(test_impl) ] + [ run cstring_ref.cpp $(test_impl) ] + [ run environment.cpp $(test_impl) ] + [ run shell.cpp $(test_impl) ] ; test-suite with_target : - [ run pid.cpp test_impl : --log_level=all --catch_system_errors=no -- : 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 : no windows:yes windows:Advapi32 ] - [ run ext.cpp test_impl : --log_level=all --catch_system_errors=no -- : target : darwin:no ] + [ run pid.cpp $(test_impl) : --log_level=all --catch_system_errors=no -- : 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 : no windows:yes windows:Advapi32 ] + [ run ext.cpp $(test_impl) : --log_level=all --catch_system_errors=no -- : target : darwin:no ] ; diff --git a/test/v2/test_impl.cpp b/test/v2/test_impl.cpp index 6df708548..189f39fae 100644 --- a/test/v2/test_impl.cpp +++ b/test/v2/test_impl.cpp @@ -5,4 +5,4 @@ #define BOOST_TEST_IGNORE_SIGCHLD #define BOOST_TEST_MODULE process_v2_test -#include +#include From e46a5146299805e813c1109284a859e44a1d529f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 15:53:51 +0800 Subject: [PATCH 18/28] replaced deadline_timer with steady_timer. --- test/v1/async.cpp | 22 +++++++++++----------- test/v1/exit_code.cpp | 2 +- test/v1/system_test2.cpp | 2 +- test/v1/wait.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/v1/async.cpp b/test/v1/async.cpp index bf5c10cd1..0adac13a8 100644 --- a/test/v1/async.cpp +++ b/test/v1/async.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include using namespace std; @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(async_wait, *boost::unit_test::timeout(5)) bool exit_called_for_c1 = false; int exit_code_c1 = 0; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bp::child c1(master_test_suite().argv[1], @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(async_wait_sync_wait, *boost::unit_test::timeout(5)) int exit_code = 0; std::error_code ec; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(3)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(3)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bp::child c1( @@ -140,10 +140,10 @@ BOOST_AUTO_TEST_CASE(async_wait_different_contexts, *boost::unit_test::timeout(1 boost::asio::io_context io_context1; boost::asio::io_context io_context2; - boost::asio::deadline_timer timeout1{io_context1, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout1{io_context1, std::chrono::seconds(2)}; timeout1.async_wait([&](boost::system::error_code ec){if (!ec) io_context1.stop();}); - boost::asio::deadline_timer timeout2{io_context2, boost::posix_time::seconds(7)}; + boost::asio::steady_timer timeout2{io_context2, std::chrono::seconds(7)}; timeout2.async_wait([&](boost::system::error_code ec){if (!ec) io_context2.stop();}); std::error_code ec; @@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(async_wait_abort, *boost::unit_test::timeout(5)) std::error_code ec; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(5)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(5)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bool exit_called = false; @@ -245,7 +245,7 @@ BOOST_AUTO_TEST_CASE(async_future, *boost::unit_test::timeout(3)) boost::asio::io_context io_context; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); std::error_code ec; @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(async_out_stream, *boost::unit_test::timeout(5)) boost::asio::streambuf buf; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bp::child c(master_test_suite().argv[1], @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(async_in_stream, *boost::unit_test::timeout(5)) std::ostream ostr(&in_buf); ostr << "-string" << endl ; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bp::child c( @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(async_error, *boost::unit_test::timeout(3)) boost::asio::io_context io_context; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bool exit_called = false; @@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(mixed_async, *boost::unit_test::timeout(5)) boost::asio::io_context io_context; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(2)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(2)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); bool exit_called = false; diff --git a/test/v1/exit_code.cpp b/test/v1/exit_code.cpp index 69365ad16..2eb8d8dc5 100644 --- a/test/v1/exit_code.cpp +++ b/test/v1/exit_code.cpp @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(async_wait, *boost::unit_test::timeout(10)) boost::asio::io_context io_context; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(3)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(3)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); diff --git a/test/v1/system_test2.cpp b/test/v1/system_test2.cpp index 161176e82..c4bb7ab56 100644 --- a/test/v1/system_test2.cpp +++ b/test/v1/system_test2.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/v1/wait.cpp b/test/v1/wait.cpp index b931f5747..b703f2e1d 100644 --- a/test/v1/wait.cpp +++ b/test/v1/wait.cpp @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(async_wait, *boost::unit_test::timeout(4)) std::error_code ec; bool called = false; - boost::asio::deadline_timer timeout{io_context, boost::posix_time::seconds(3)}; + boost::asio::steady_timer timeout{io_context, std::chrono::seconds(3)}; timeout.async_wait([&](boost::system::error_code ec){if (!ec) io_context.stop();}); From fdfb5043cb7b74f7e882e9746d5e2194cabc8b76 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 15:59:17 +0800 Subject: [PATCH 19/28] add kvm to process target on bsd --- build/Jamfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/Jamfile b/build/Jamfile index db0ed8d39..b5336ade9 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -47,6 +47,9 @@ lib ntdll ; lib user32 ; lib ws2_32 ; +lib kvm ; +lib procstat ; + lib boost_process : process_sources : requirements BOOST_PROCESS_SOURCE=1 @@ -58,6 +61,12 @@ lib boost_process windows:ntdll windows:advapi32 windows:ws2_32 + bsd:kvm + freebsd:kvm + freebsd:procstat + netbsd:kvm + openbsd:kvm + solaris:kvm : usage-requirements shared:BOOST_PROCESS_DYN_LINK=1 boost:/boost/filesystem//boost_filesystem From 11a0d0d7c1e2b890e8187c4e5caa3f7470aa37ec Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 16:46:00 +0800 Subject: [PATCH 20/28] added pthread to test linking for freebsd --- test/v2/Jamfile.jam | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 01b93e502..7c6715a14 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -21,9 +21,7 @@ project : requirements windows:_WIN32_WINNT=0x0601 linux:-lpthread freebsd:-lutil - freebsd:-lkvm - freebsd:-lprocstat - bsd:-lkvm + freebsd:-lpthread NT,cw:ws2_32 NT,gcc:ws2_32 NT,gcc:Bcrypt From f218a6a6c1cc94f09739696a2c4ded2b4eceec7f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 25 Oct 2024 17:01:59 +0800 Subject: [PATCH 21/28] added pthread to test linking for freebsd on v1 as well. --- test/v1/Jamfile.jam | 1 + 1 file changed, 1 insertion(+) diff --git a/test/v1/Jamfile.jam b/test/v1/Jamfile.jam index 51c73f19f..0540a8372 100644 --- a/test/v1/Jamfile.jam +++ b/test/v1/Jamfile.jam @@ -22,6 +22,7 @@ project : requirements msvc:/bigobj windows:WIN32_LEAN_AND_MEAN linux:-lpthread + freebsd:-lpthread NT,cw:ws2_32 NT,gcc:ws2_32 /boost/test//included From e827d145424ede0f912b10d4e2800e1da9a2867d Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sun, 27 Oct 2024 11:07:12 +0800 Subject: [PATCH 22/28] reduced asio related macro usage. --- include/boost/process/v2/bind_launcher.hpp | 24 +++++----- include/boost/process/v2/detail/config.hpp | 21 ++++----- .../process/v2/detail/process_handle_fd.hpp | 37 +++++++-------- .../v2/detail/process_handle_fd_or_signal.hpp | 45 ++++++++++--------- .../v2/detail/process_handle_signal.hpp | 37 +++++++-------- .../v2/detail/process_handle_windows.hpp | 26 ++++++----- include/boost/process/v2/execute.hpp | 23 +++++----- include/boost/process/v2/popen.hpp | 41 ++++++++--------- .../process/v2/posix/default_launcher.hpp | 24 +++++----- .../v2/posix/fork_and_forget_launcher.hpp | 24 +++++----- .../process/v2/posix/pdfork_launcher.hpp | 24 +++++----- .../boost/process/v2/posix/vfork_launcher.hpp | 22 ++++----- include/boost/process/v2/process.hpp | 36 ++++++++------- include/boost/process/v2/process_handle.hpp | 16 +++---- include/boost/process/v2/stdio.hpp | 24 +++++----- .../process/v2/windows/as_user_launcher.hpp | 12 ++--- .../process/v2/windows/default_launcher.hpp | 12 ++--- .../v2/windows/with_logon_launcher.hpp | 12 ++--- .../v2/windows/with_token_launcher.hpp | 12 ++--- 19 files changed, 238 insertions(+), 234 deletions(-) diff --git a/include/boost/process/v2/bind_launcher.hpp b/include/boost/process/v2/bind_launcher.hpp index 158244816..e63260c51 100644 --- a/include/boost/process/v2/bind_launcher.hpp +++ b/include/boost/process/v2/bind_launcher.hpp @@ -71,7 +71,7 @@ struct bound_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits) -> basic_process @@ -88,7 +88,7 @@ struct bound_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -103,8 +103,8 @@ struct bound_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -120,8 +120,8 @@ struct bound_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -138,7 +138,7 @@ struct bound_launcher auto invoke(detail::index_sequence, ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits) -> basic_process @@ -156,7 +156,7 @@ struct bound_launcher ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -172,8 +172,8 @@ struct bound_launcher auto invoke(detail::index_sequence, Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -190,8 +190,8 @@ struct bound_launcher Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process diff --git a/include/boost/process/v2/detail/config.hpp b/include/boost/process/v2/detail/config.hpp index 40fe2e087..0dbf5a993 100644 --- a/include/boost/process/v2/detail/config.hpp +++ b/include/boost/process/v2/detail/config.hpp @@ -7,12 +7,8 @@ #if defined(BOOST_PROCESS_V2_STANDALONE) -#define BOOST_PROCESS_V2_ASIO_NAMESPACE asio + #define BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(Sig) ASIO_COMPLETION_TOKEN_FOR(Sig) -#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) -#define BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(Token, Signature) ASIO_INITFN_AUTO_RESULT_TYPE(Token, Signature) -#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN(Executor) ASIO_DEFAULT_COMPLETION_TOKEN(Executor) -#define BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(x,y,z) ASIO_INITFN_DEDUCED_RESULT_TYPE(x,y,z) #include #include @@ -38,14 +34,14 @@ #define BOOST_PROCESS_V2_END_NAMESPACE } #define BOOST_PROCESS_V2_NAMESPACE process_v2 +namespace asio {} +BOOST_PROCESS_V2_BEGIN_NAMESPACE +namespace net = ::asio; +BOOST_PROCESS_V2_END_NAMESPACE + #else -#define BOOST_PROCESS_V2_ASIO_NAMESPACE boost::asio #define BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(Sig) BOOST_ASIO_COMPLETION_TOKEN_FOR(Sig) -#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) -#define BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(Token, Signature) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(Token, Signature) -#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN(Executor) BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor) -#define BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(x,y,z) BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(x,y,z) #include #include @@ -94,6 +90,11 @@ #define BOOST_PROCESS_V2_END_NAMESPACE } } } #define BOOST_PROCESS_V2_NAMESPACE boost::process::v2 +namespace boost { namespace asio {} } +BOOST_PROCESS_V2_BEGIN_NAMESPACE +namespace net = ::boost::asio; +BOOST_PROCESS_V2_END_NAMESPACE + #endif BOOST_PROCESS_V2_BEGIN_NAMESPACE diff --git a/include/boost/process/v2/detail/process_handle_fd.hpp b/include/boost/process/v2/detail/process_handle_fd.hpp index 7a94dd0d0..9a0363355 100644 --- a/include/boost/process/v2/detail/process_handle_fd.hpp +++ b/include/boost/process/v2/detail/process_handle_fd.hpp @@ -34,7 +34,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { -template +template struct basic_process_handle_fd { using native_handle_type = int; @@ -56,7 +56,7 @@ struct basic_process_handle_fd basic_process_handle_fd(ExecutionContext &context, typename std::enable_if< std::is_convertible::value>::type * = nullptr) + net::execution_context &>::value>::type * = nullptr) : pid_(-1), descriptor_(context) { } @@ -275,25 +275,16 @@ struct basic_process_handle_fd return pid_ != -1; } - template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type)) - async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) - { - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( - async_wait_op_{descriptor_, pid_}, handler, descriptor_); - } - private: template friend struct basic_process_handle_fd; pid_type pid_ = -1; - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_stream_descriptor descriptor_; + net::posix::basic_stream_descriptor descriptor_; struct async_wait_op_ { - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_descriptor &descriptor; + net::posix::basic_descriptor &descriptor; pid_type pid_; template @@ -304,7 +295,7 @@ struct basic_process_handle_fd native_exit_code_type exit_code{}; int wait_res = -1; if (pid_ <= 0) // error, complete early - ec = BOOST_PROCESS_V2_ASIO_NAMESPACE::error::bad_descriptor; + ec = net::error::bad_descriptor; else { wait_res = ::waitpid(pid_, &exit_code, WNOHANG); @@ -315,8 +306,7 @@ struct basic_process_handle_fd if (!ec && (wait_res == 0)) { - descriptor.async_wait( - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::descriptor_base::wait_read, std::move(self)); + descriptor.async_wait(net::posix::descriptor_base::wait_read, std::move(self)); return; } @@ -331,8 +321,7 @@ struct basic_process_handle_fd self.complete(ec, code); } }; - BOOST_PROCESS_V2_ASIO_NAMESPACE::post(descriptor.get_executor(), - completer{ec, exit_code, std::move(self)}); + net::post(descriptor.get_executor(), completer{ec, exit_code, std::move(self)}); } @@ -346,6 +335,18 @@ struct basic_process_handle_fd std::move(self).complete(ec, exit_code); } }; + public: + + template> + auto async_wait(WaitHandler &&handler = net::default_completion_token_t()) + -> decltype(net::async_compose( + async_wait_op_{descriptor_, pid_}, handler, descriptor_)) + { + return net::async_compose( + async_wait_op_{descriptor_, pid_}, handler, descriptor_); + } + }; } diff --git a/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp b/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp index 97d9400a0..5c2416765 100644 --- a/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp +++ b/include/boost/process/v2/detail/process_handle_fd_or_signal.hpp @@ -37,7 +37,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { -template +template struct basic_process_handle_fd_or_signal { using native_handle_type = int; @@ -59,7 +59,7 @@ struct basic_process_handle_fd_or_signal basic_process_handle_fd_or_signal(ExecutionContext &context, typename std::enable_if< std::is_convertible::value + net::execution_context &>::value >::type * = nullptr) : pid_(-1), descriptor_(context) { @@ -70,7 +70,7 @@ struct basic_process_handle_fd_or_signal pid_type pid, typename std::enable_if< std::is_convertible::value + net::execution_context &>::value >::type * = nullptr) : pid_(pid), descriptor_(context) { @@ -81,7 +81,7 @@ struct basic_process_handle_fd_or_signal pid_type pid, native_handle_type process_handle, typename std::enable_if< std::is_convertible::value + net::execution_context &>::value >::type * = nullptr) : pid_(pid), descriptor_(context, process_handle) { @@ -305,31 +305,22 @@ struct basic_process_handle_fd_or_signal return pid_ != -1; } - template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type)) - async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) - { - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( - async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_); - } - private: template friend struct basic_process_handle_fd_or_signal; pid_type pid_ = -1; - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_stream_descriptor descriptor_; - BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set signal_set_{descriptor_.get_executor(), SIGCHLD}; + net::posix::basic_stream_descriptor descriptor_; + net::basic_signal_set signal_set_{descriptor_.get_executor(), SIGCHLD}; struct async_wait_op_ { - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_descriptor &descriptor; - BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set &handle; + net::posix::basic_descriptor &descriptor; + net::basic_signal_set &handle; pid_type pid_; bool needs_post = true; - template void operator()(Self && self) { self.reset_cancellation_state(asio::enable_total_cancellation()); @@ -342,7 +333,7 @@ struct basic_process_handle_fd_or_signal native_exit_code_type exit_code{}; int wait_res = -1; if (pid_ <= 0) // error, complete early - ec = BOOST_PROCESS_V2_ASIO_NAMESPACE::error::bad_descriptor; + ec = net::error::bad_descriptor; else { wait_res = ::waitpid(pid_, &exit_code, WNOHANG); @@ -355,7 +346,7 @@ struct basic_process_handle_fd_or_signal needs_post = false; if (descriptor.is_open()) descriptor.async_wait( - BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::descriptor_base::wait_read, + net::posix::descriptor_base::wait_read, std::move(self)); else handle.async_wait(std::move(self)); @@ -377,12 +368,22 @@ struct basic_process_handle_fd_or_signal const auto exec = self.get_executor(); completer cpl{ec, exit_code, std::move(self)}; if (needs_post) - BOOST_PROCESS_V2_ASIO_NAMESPACE::post(exec, std::move(cpl)); + net::post(exec, std::move(cpl)); else - BOOST_PROCESS_V2_ASIO_NAMESPACE::dispatch(exec, std::move(cpl)); + net::dispatch(exec, std::move(cpl)); } }; + public: + template> + auto async_wait(WaitHandler &&handler = net::default_completion_token_t()) + -> decltype(net::async_compose( + async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_)) + { + return net::async_compose( + async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_); + } }; } diff --git a/include/boost/process/v2/detail/process_handle_signal.hpp b/include/boost/process/v2/detail/process_handle_signal.hpp index ca486b343..6cf5ec893 100644 --- a/include/boost/process/v2/detail/process_handle_signal.hpp +++ b/include/boost/process/v2/detail/process_handle_signal.hpp @@ -34,7 +34,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { -template +template struct basic_process_handle_signal { struct native_handle_type @@ -61,7 +61,7 @@ struct basic_process_handle_signal basic_process_handle_signal(ExecutionContext &context, typename std::enable_if< std::is_convertible::value + net::execution_context &>::value >::type * = nullptr) : pid_(-1), signal_set_(context, SIGCHLD) { @@ -87,7 +87,7 @@ struct basic_process_handle_signal { pid_ = handle.id(); signal_set_.~basic_signal_set(); - using ss = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set; + using ss = net::basic_signal_set; new (&signal_set_) ss(handle.get_executor(), SIGCHLD); handle.pid_ = -1; return *this; @@ -269,24 +269,15 @@ struct basic_process_handle_signal return pid_ != -1; } - template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type)) - async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) - { - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( - async_wait_op_{signal_set_, pid_}, handler, signal_set_); - } - private: template friend struct basic_process_handle_signal; pid_type pid_ = -1; - BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set signal_set_; + net::basic_signal_set signal_set_; struct async_wait_op_ { - BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set &handle; + net::basic_signal_set &handle; pid_type pid_; template @@ -301,16 +292,16 @@ struct basic_process_handle_signal template void operator()(Self &&self, error_code ec, int sig) { - if (ec == BOOST_PROCESS_V2_ASIO_NAMESPACE::error::operation_aborted && + if (ec == net::error::operation_aborted && self.get_cancellation_state().cancelled() - == BOOST_PROCESS_V2_ASIO_NAMESPACE::cancellation_type::none) + == net::cancellation_type::none) ec.clear(); native_exit_code_type exit_code = -1; int wait_res = -1; if (pid_ <= 0) // error, complete early - ec = BOOST_PROCESS_V2_ASIO_NAMESPACE::error::bad_descriptor; + ec = net::error::bad_descriptor; else if (!ec) { wait_res = ::waitpid(pid_, &exit_code, WNOHANG); @@ -337,9 +328,19 @@ struct basic_process_handle_signal }; const auto exec = self.get_executor(); - BOOST_PROCESS_V2_ASIO_NAMESPACE::dispatch(exec, completer{ec, exit_code, std::move(self)}); + net::dispatch(exec, completer{ec, exit_code, std::move(self)}); } }; + public: + template> + auto async_wait(WaitHandler &&handler = net::default_completion_token_t()) + -> decltype(net::async_compose( + async_wait_op_{signal_set_, pid_}, handler, signal_set_)) + { + return net::async_compose( + async_wait_op_{signal_set_, pid_}, handler, signal_set_); + } }; } diff --git a/include/boost/process/v2/detail/process_handle_windows.hpp b/include/boost/process/v2/detail/process_handle_windows.hpp index e92b86539..662d249f1 100644 --- a/include/boost/process/v2/detail/process_handle_windows.hpp +++ b/include/boost/process/v2/detail/process_handle_windows.hpp @@ -38,10 +38,10 @@ BOOST_PROCESS_V2_DECL void terminate_(void * handle, error_code & ec, native_exi BOOST_PROCESS_V2_DECL void request_exit_(pid_type pid_, error_code & ec); BOOST_PROCESS_V2_DECL void check_running_(void* handle, error_code & ec, native_exit_code_type & exit_status); -template +template struct basic_process_handle_win { - typedef BOOST_PROCESS_V2_ASIO_NAMESPACE::windows::basic_object_handle handle_type; + typedef net::windows::basic_object_handle handle_type; typedef typename handle_type::native_handle_type native_handle_type; typedef Executor executor_type; @@ -61,7 +61,7 @@ struct basic_process_handle_win basic_process_handle_win(ExecutionContext &context, typename std::enable_if< std::is_convertible::value + net::execution_context &>::value >::type = 0) : pid_(0), handle_(context) { @@ -266,15 +266,6 @@ struct basic_process_handle_win return handle_.is_open(); } - template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type)) - async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) - { - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( - async_wait_op_{handle_}, handler, handle_ - ); - } template friend struct basic_process_handle_win; private: @@ -314,6 +305,17 @@ struct basic_process_handle_win std::move(self).complete(ec, exit_code); } }; + public: + template> + auto async_wait(WaitHandler &&handler = default_completion_token_t()) + -> decltype(net::async_compose( + async_wait_op_{handle_}, handler, handle_)) + { + return net::async_compose( + async_wait_op_{handle_}, handler, handle_ + ); + } }; extern template struct basic_process_handle_win<>; diff --git a/include/boost/process/v2/execute.hpp b/include/boost/process/v2/execute.hpp index f910eef31..2ce2c1af5 100644 --- a/include/boost/process/v2/execute.hpp +++ b/include/boost/process/v2/execute.hpp @@ -47,7 +47,7 @@ struct execute_op struct cancel { - using cancellation_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::cancellation_type; + using cancellation_type = net::cancellation_type; basic_process * proc; cancel(basic_process * proc) : proc(proc) {} @@ -66,15 +66,15 @@ struct execute_op template void operator()(Self && self) { - self.reset_cancellation_state(BOOST_PROCESS_V2_ASIO_NAMESPACE::enable_total_cancellation()); - BOOST_PROCESS_V2_ASIO_NAMESPACE::cancellation_slot s = self.get_cancellation_state().slot(); + self.reset_cancellation_state(net::enable_total_cancellation()); + net::cancellation_slot s = self.get_cancellation_state().slot(); if (s.is_connected()) s.emplace(proc.get()); auto pro_ = proc.get(); pro_->async_wait( - BOOST_PROCESS_V2_ASIO_NAMESPACE::bind_cancellation_slot( - BOOST_PROCESS_V2_ASIO_NAMESPACE::cancellation_slot(), + net::bind_cancellation_slot( + net::cancellation_slot(), std::move(self))); } @@ -101,17 +101,18 @@ struct execute_op * It is to note that `async_execute` will us the lowest selected cancellation * type. A subprocess might ignore anything not terminal. */ -template + WaitHandler = net::default_completion_token_t> inline -BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, int)) -async_execute(basic_process proc, - WaitHandler && handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)) +auto async_execute(basic_process proc, + WaitHandler && handler = net::default_completion_token_t()) + -> decltype(net::async_compose( + detail::execute_op{nullptr}, handler, std::declval())) { std::unique_ptr> pro_(new basic_process(std::move(proc))); auto exec = pro_->get_executor(); - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( + return net::async_compose( detail::execute_op{std::move(pro_)}, handler, exec); } diff --git a/include/boost/process/v2/popen.hpp b/include/boost/process/v2/popen.hpp index 7696eb718..4358520a3 100644 --- a/include/boost/process/v2/popen.hpp +++ b/include/boost/process/v2/popen.hpp @@ -34,7 +34,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE * * Popen can be used as a stream object in other protocols. */ -template +template struct basic_popen : basic_process { /// The executor of the process @@ -69,7 +69,7 @@ struct basic_popen : basic_process explicit basic_popen(ExecutionContext & context, typename std::enable_if< is_convertible::value, void *>::type = nullptr) + net::execution_context&>::value, void *>::type = nullptr) : basic_process{context} { } @@ -148,7 +148,7 @@ struct basic_popen : basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, std::initializer_list args, Inits&&... inits) @@ -169,7 +169,7 @@ struct basic_popen : basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, std::initializer_list args, Inits&&... inits) @@ -189,7 +189,7 @@ struct basic_popen : basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, Args&& args, Inits&&... inits) : basic_process(context) @@ -209,7 +209,7 @@ struct basic_popen : basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, Args&& args, Inits&&... inits) : basic_process(context) @@ -224,9 +224,9 @@ struct basic_popen : basic_process /// The type used for stdin on the parent process side. - using stdin_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_writable_pipe; + using stdin_type = net::basic_writable_pipe; /// The type used for stdout on the parent process side. - using stdout_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_readable_pipe; + using stdout_type = net::basic_readable_pipe; /// Get the stdin pipe. stdin_type & get_stdin() {return stdin_; } @@ -336,14 +336,11 @@ struct basic_popen : basic_process * std::vector. */ template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WriteToken, - void (boost::system::error_code, std::size_t)) - async_write_some(const ConstBufferSequence& buffers, - BOOST_ASIO_MOVE_ARG(WriteToken) token - BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) + BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) + WriteToken = net::default_completion_token_t> + auto async_write_some(const ConstBufferSequence& buffers, + WriteToken && token = net::default_completion_token_t()) + -> decltype(std::declval().async_write_some(buffers, std::forward(token))) { return stdin_.async_write_some(buffers, std::forward(token)); } @@ -451,14 +448,12 @@ struct basic_popen : basic_process * std::vector. */ template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(ReadToken, - void (boost::system::error_code, std::size_t)) - async_read_some(const MutableBufferSequence& buffers, + BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) + ReadToken = net::default_completion_token_t> + auto async_read_some(const MutableBufferSequence& buffers, BOOST_ASIO_MOVE_ARG(ReadToken) token - BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) + = net::default_completion_token_t()) + -> decltype(std::declval().async_read_some(buffers, std::forward(token))) { return stdout_.async_read_some(buffers, std::forward(token)); } diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index 3645f9cba..8a856d285 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -305,7 +305,7 @@ struct default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -324,7 +324,7 @@ struct default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -335,8 +335,8 @@ struct default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -354,8 +354,8 @@ struct default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -381,13 +381,13 @@ struct default_launcher } fd_whitelist.push_back(pg.p[1]); - auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query( - exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context); - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_prepare); + auto & ctx = net::query( + exec, net::execution::context); + ctx.notify_fork(net::execution_context::fork_prepare); pid = ::fork(); if (pid == -1) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); @@ -397,7 +397,7 @@ struct default_launcher else if (pid == 0) { ::close(pg.p[0]); - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_child); + ctx.notify_fork(net::execution_context::fork_child); ec = detail::on_exec_setup(*this, executable, argv, inits...); if (!ec) { @@ -413,7 +413,7 @@ struct default_launcher return basic_process{exec}; } - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); ::close(pg.p[1]); pg.p[1] = -1; int child_error{0}; 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 08e81c9c1..6cf68b52a 100644 --- a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp +++ b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp @@ -20,7 +20,7 @@ struct fork_and_forget_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -39,7 +39,7 @@ struct fork_and_forget_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -50,8 +50,8 @@ struct fork_and_forget_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -69,8 +69,8 @@ struct fork_and_forget_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -84,13 +84,13 @@ struct fork_and_forget_launcher : default_launcher return basic_process(exec); } - auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query( - exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context); - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_prepare); + auto & ctx = net::query( + exec, net::execution::context); + ctx.notify_fork(net::execution_context::fork_prepare); pid = ::fork(); if (pid == -1) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); @@ -99,7 +99,7 @@ struct fork_and_forget_launcher : default_launcher } else if (pid == 0) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_child); + ctx.notify_fork(net::execution_context::fork_child); ec = detail::on_exec_setup(*this, executable, argv, inits...); if (!ec) @@ -112,7 +112,7 @@ struct fork_and_forget_launcher : default_launcher ::exit(EXIT_FAILURE); return basic_process{exec}; } - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); if (ec) { detail::on_error(*this, executable, argv, ec, inits...); diff --git a/include/boost/process/v2/posix/pdfork_launcher.hpp b/include/boost/process/v2/posix/pdfork_launcher.hpp index 0df0b4100..016182734 100644 --- a/include/boost/process/v2/posix/pdfork_launcher.hpp +++ b/include/boost/process/v2/posix/pdfork_launcher.hpp @@ -25,7 +25,7 @@ struct pdfork_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -44,7 +44,7 @@ struct pdfork_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -55,8 +55,8 @@ struct pdfork_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -74,8 +74,8 @@ struct pdfork_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -101,13 +101,13 @@ struct pdfork_launcher : default_launcher } fd_whitelist.push_back(pg.p[1]); - auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query( - exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context); - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_prepare); + auto & ctx = net::query( + exec, net::execution::context); + ctx.notify_fork(net::execution_context::fork_prepare); pid = ::pdfork(&fd, PD_DAEMON | PD_CLOEXEC); if (pid == -1) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); @@ -116,7 +116,7 @@ struct pdfork_launcher : default_launcher } else if (pid == 0) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_child); + ctx.notify_fork(net::execution_context::fork_child); ::close(pg.p[0]); ec = detail::on_exec_setup(*this, executable, argv, inits...); @@ -133,7 +133,7 @@ struct pdfork_launcher : default_launcher ::exit(EXIT_FAILURE); return basic_process{exec}; } - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); ::close(pg.p[1]); pg.p[1] = -1; int child_error{0}; diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index ed59ae724..b9b8b6578 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -22,7 +22,7 @@ struct vfork_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -41,7 +41,7 @@ struct vfork_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -52,8 +52,8 @@ struct vfork_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -71,8 +71,8 @@ struct vfork_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -86,13 +86,13 @@ struct vfork_launcher : default_launcher return basic_process(exec); } - auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query( - exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context); - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_prepare); + auto & ctx = net::query( + exec, net::execution::context); + ctx.notify_fork(net::execution_context::fork_prepare); pid = ::vfork(); if (pid == -1) { - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); @@ -112,7 +112,7 @@ struct vfork_launcher : default_launcher ::_exit(EXIT_FAILURE); return basic_process{exec}; } - ctx.notify_fork(BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context::fork_parent); + ctx.notify_fork(net::execution_context::fork_parent); if (ec) { diff --git a/include/boost/process/v2/process.hpp b/include/boost/process/v2/process.hpp index a624297bb..9c96d23b7 100644 --- a/include/boost/process/v2/process.hpp +++ b/include/boost/process/v2/process.hpp @@ -34,7 +34,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE /* A `basic_process` object manages a subprocess; it tracks the status and exit-code, * and will terminate the process on destruction if `detach` was not called. */ -template +template struct basic_process { /// The executor of the process @@ -111,7 +111,7 @@ struct basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, std::initializer_list args, Inits&&... inits) @@ -125,7 +125,7 @@ struct basic_process ExecutionContext & context, typename std::enable_if< std::is_convertible::value, + net::execution_context&>::value, const filesystem::path&>::type exe, Args&& args, Inits&&... inits) : basic_process(default_process_launcher()(executor_type(context.get_executor()), @@ -148,7 +148,7 @@ struct basic_process explicit basic_process(ExecutionContext & context, pid_type pid, typename std::enable_if< std::is_convertible::value, void *>::type = nullptr) + net::execution_context&>::value, void *>::type = nullptr) : process_handle_(context, pid) {} /// Attach to an existing process and the internal handle @@ -156,7 +156,7 @@ struct basic_process explicit basic_process(ExecutionContext & context, pid_type pid, native_handle_type native_handle, typename std::enable_if< std::is_convertible::value, void *>::type = nullptr) + net::execution_context&>::value, void *>::type = nullptr) : process_handle_(context.get_executor(), pid, native_handle) {} /// Create an invalid handle @@ -164,7 +164,7 @@ struct basic_process explicit basic_process(ExecutionContext & context, typename std::enable_if< is_convertible::value, void *>::type = nullptr) + net::execution_context&>::value, void *>::type = nullptr) : process_handle_(context.get_executor()) {} @@ -325,15 +325,7 @@ struct basic_process /** Note that this might be a process that already exited.*/ bool is_open() const { return process_handle_.is_open(); } - /// Asynchronously wait for the process to exit and deliver the native exit-code in the completion handler. - template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, int)) - async_wait(WaitHandler && handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) - { - return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose( - async_wait_op_{process_handle_, exit_status_}, handler, process_handle_); - } + private: template @@ -363,7 +355,7 @@ struct basic_process } }; - BOOST_PROCESS_V2_ASIO_NAMESPACE::post(handle.get_executor(), + net::post(handle.get_executor(), completer{static_cast(res), std::move(self)}); } else @@ -383,6 +375,18 @@ struct basic_process } } }; + + public: + /// Asynchronously wait for the process to exit and deliver the native exit-code in the completion handler. + template > + auto async_wait(WaitHandler && handler = net::default_completion_token_t()) + -> decltype(net::async_compose( + async_wait_op_{process_handle_, exit_status_}, handler, process_handle_)) + { + return net::async_compose( + async_wait_op_{process_handle_, exit_status_}, handler, process_handle_); + } }; /// Process with the default executor. diff --git a/include/boost/process/v2/process_handle.hpp b/include/boost/process/v2/process_handle.hpp index 9e50f7a7c..e0894e338 100644 --- a/include/boost/process/v2/process_handle.hpp +++ b/include/boost/process/v2/process_handle.hpp @@ -32,7 +32,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE * Note that the exit code might be discovered early, during a call to `running`. * Thus it can only be discovered that process has exited already. */ -template +template struct basic_process_handle { /// The native handle of the process. @@ -123,28 +123,26 @@ struct basic_process_handle /// Asynchronously wait for the process to exit and deliver the native exit-code in the completion handler. template - BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type)) - async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)); - + WaitHandler = net::default_completion_token_t> + auto async_wait(WaitHandler &&handler = net::default_completion_token_t()); }; #else #if defined(BOOST_PROCESS_V2_WINDOWS) -template +template using basic_process_handle = detail::basic_process_handle_win; #else #if defined(BOOST_PROCESS_V2_PIDFD_OPEN) -template +template using basic_process_handle = detail::basic_process_handle_fd; #elif defined(BOOST_PROCESS_V2_PDFORK) -template +template using basic_process_handle = detail::basic_process_handle_fd_or_signal; #else -template +template using basic_process_handle = detail::basic_process_handle_signal; #endif diff --git a/include/boost/process/v2/stdio.hpp b/include/boost/process/v2/stdio.hpp index b2ae021c5..4dc92b838 100644 --- a/include/boost/process/v2/stdio.hpp +++ b/include/boost/process/v2/stdio.hpp @@ -103,7 +103,7 @@ struct process_io_binding template - process_io_binding(BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_readable_pipe & pipe) + process_io_binding(net::basic_readable_pipe & pipe) { if (Target == STD_INPUT_HANDLE) { @@ -112,9 +112,9 @@ struct process_io_binding return ; } - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::native_pipe_handle p[2]; + net::detail::native_pipe_handle p[2]; error_code ec; - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::create_pipe(p, ec); + net::detail::create_pipe(p, ec); if (ec) detail::throw_error(ec, "create_pipe"); @@ -124,7 +124,7 @@ struct process_io_binding template - process_io_binding(BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_writable_pipe & pipe) + process_io_binding(net::basic_writable_pipe & pipe) { if (Target != STD_INPUT_HANDLE) { @@ -132,9 +132,9 @@ struct process_io_binding h = std::unique_ptr{h_, get_flags(h_)}; return ; } - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::native_pipe_handle p[2]; + net::detail::native_pipe_handle p[2]; error_code ec; - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::create_pipe(p, ec); + net::detail::create_pipe(p, ec); if (ec) detail::throw_error(ec, "create_pipe"); @@ -181,7 +181,7 @@ struct process_io_binding } template - process_io_binding(BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_readable_pipe & readable_pipe) + process_io_binding(net::basic_readable_pipe & readable_pipe) { if (Target == STDIN_FILENO) { @@ -189,8 +189,8 @@ struct process_io_binding return ; } - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::native_pipe_handle p[2]; - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::create_pipe(p, ec); + net::detail::native_pipe_handle p[2]; + net::detail::create_pipe(p, ec); if (ec) detail::throw_error(ec, "create_pipe"); @@ -206,7 +206,7 @@ struct process_io_binding template - process_io_binding(BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_writable_pipe & writable_pipe) + process_io_binding(net::basic_writable_pipe & writable_pipe) { if (Target != STDIN_FILENO) @@ -214,9 +214,9 @@ struct process_io_binding fd = writable_pipe.native_handle(); return ; } - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::native_pipe_handle p[2]; + net::detail::native_pipe_handle p[2]; error_code ec; - BOOST_PROCESS_V2_ASIO_NAMESPACE::detail::create_pipe(p, ec); + net::detail::create_pipe(p, ec); if (ec) detail::throw_error(ec, "create_pipe"); diff --git a/include/boost/process/v2/windows/as_user_launcher.hpp b/include/boost/process/v2/windows/as_user_launcher.hpp index 1f12d9f99..88f9c2a29 100644 --- a/include/boost/process/v2/windows/as_user_launcher.hpp +++ b/include/boost/process/v2/windows/as_user_launcher.hpp @@ -28,7 +28,7 @@ struct as_user_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -47,7 +47,7 @@ struct as_user_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -58,8 +58,8 @@ struct as_user_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -77,8 +77,8 @@ struct as_user_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index f10eee5a3..78cbd0cde 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -236,7 +236,7 @@ struct default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> enable_init @@ -255,7 +255,7 @@ struct default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> enable_init @@ -266,8 +266,8 @@ struct default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value - || BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value + || net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> enable_init @@ -285,8 +285,8 @@ struct default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> enable_init diff --git a/include/boost/process/v2/windows/with_logon_launcher.hpp b/include/boost/process/v2/windows/with_logon_launcher.hpp index 29c0e1270..e88722145 100644 --- a/include/boost/process/v2/windows/with_logon_launcher.hpp +++ b/include/boost/process/v2/windows/with_logon_launcher.hpp @@ -39,7 +39,7 @@ struct with_logon_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -51,7 +51,7 @@ struct with_logon_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -62,8 +62,8 @@ struct with_logon_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -81,8 +81,8 @@ struct with_logon_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process diff --git a/include/boost/process/v2/windows/with_token_launcher.hpp b/include/boost/process/v2/windows/with_token_launcher.hpp index e9f0dbfb2..a0b23bc41 100644 --- a/include/boost/process/v2/windows/with_token_launcher.hpp +++ b/include/boost/process/v2/windows/with_token_launcher.hpp @@ -29,7 +29,7 @@ struct with_token_launcher : default_launcher template auto operator()(ExecutionContext & context, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -48,7 +48,7 @@ struct with_token_launcher : default_launcher auto operator()(ExecutionContext & context, error_code & ec, const typename std::enable_if::value, + ExecutionContext&, net::execution_context&>::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -59,8 +59,8 @@ struct with_token_launcher : default_launcher template auto operator()(Executor exec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process @@ -78,8 +78,8 @@ struct with_token_launcher : default_launcher auto operator()(Executor exec, error_code & ec, const typename std::enable_if< - BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor::value || - BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor::value, + net::execution::is_executor::value || + net::is_executor::value, filesystem::path >::type & executable, Args && args, Inits && ... inits ) -> basic_process From 941e93b5878ae4683d1812e457aaa5470352fc88 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sun, 27 Oct 2024 11:12:46 +0800 Subject: [PATCH 23/28] removed definition of NOMINMAX --- include/boost/process/v2/detail/config.hpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/boost/process/v2/detail/config.hpp b/include/boost/process/v2/detail/config.hpp index 0dbf5a993..5337cf8d4 100644 --- a/include/boost/process/v2/detail/config.hpp +++ b/include/boost/process/v2/detail/config.hpp @@ -7,7 +7,6 @@ #if defined(BOOST_PROCESS_V2_STANDALONE) - #define BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(Sig) ASIO_COMPLETION_TOKEN_FOR(Sig) #include @@ -20,10 +19,6 @@ #if defined(ASIO_WINDOWS) #define BOOST_PROCESS_V2_WINDOWS 1 -// Windows: suppress definition of "min" and "max" macros. -#if !defined(NOMINMAX) -# define NOMINMAX 1 -#endif #endif #if defined(ASIO_HAS_UNISTD_H) @@ -53,10 +48,6 @@ BOOST_PROCESS_V2_END_NAMESPACE #if defined(BOOST_WINDOWS_API) #define BOOST_PROCESS_V2_WINDOWS 1 -// Windows: suppress definition of "min" and "max" macros. -#if !defined(NOMINMAX) -# define NOMINMAX 1 -#endif #endif From 817128108ae35441c8f205c28ba9169f322cb49d Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sun, 27 Oct 2024 12:54:16 +0800 Subject: [PATCH 24/28] changed error macros to require a ; at the end. --- include/boost/process/v2/detail/config.hpp | 17 ++--- .../process/v2/posix/default_launcher.hpp | 12 +-- .../v2/posix/fork_and_forget_launcher.hpp | 4 +- .../process/v2/posix/pdfork_launcher.hpp | 12 +-- .../boost/process/v2/posix/vfork_launcher.hpp | 4 +- include/boost/process/v2/stdio.hpp | 4 +- .../process/v2/windows/as_user_launcher.hpp | 2 +- .../process/v2/windows/default_launcher.hpp | 2 +- .../v2/windows/with_logon_launcher.hpp | 2 +- .../v2/windows/with_token_launcher.hpp | 2 +- src/detail/environment_posix.cpp | 6 +- src/detail/environment_win.cpp | 12 +-- src/detail/process_handle_windows.cpp | 26 +++---- src/detail/utf8.cpp | 20 ++--- src/ext/cmd.cpp | 30 ++++---- src/ext/cwd.cpp | 18 ++--- src/ext/env.cpp | 22 +++--- src/ext/exe.cpp | 12 +-- src/ext/proc_info.cpp | 10 +-- src/pid.cpp | 74 +++++++++---------- 20 files changed, 143 insertions(+), 148 deletions(-) diff --git a/include/boost/process/v2/detail/config.hpp b/include/boost/process/v2/detail/config.hpp index 5337cf8d4..a38c89ed9 100644 --- a/include/boost/process/v2/detail/config.hpp +++ b/include/boost/process/v2/detail/config.hpp @@ -100,9 +100,6 @@ 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()); \ @@ -123,23 +120,21 @@ 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, ...) \ +do \ { \ static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \ ec.assign(__VA_ARGS__, &loc##__LINE__); \ -} +} \ +while (false) #define BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) \ +do \ { \ static constexpr auto loc##__LINE__((BOOST_CURRENT_LOCATION)); \ ec.assign(::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(), &loc##__LINE__); \ -} +} \ +while (false) #endif diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index 8a856d285..625be154a 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -365,12 +365,12 @@ struct default_launcher pipe_guard pg; if (::pipe(pg.p)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } ec = detail::on_setup(*this, executable, argv, inits ...); @@ -391,7 +391,7 @@ struct default_launcher detail::on_fork_error(*this, executable, argv, ec, inits...); detail::on_error(*this, executable, argv, ec, inits...); - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } else if (pid == 0) @@ -407,7 +407,7 @@ struct default_launcher ::execve(executable.c_str(), const_cast(argv), const_cast(env)); ignore_unused(::write(pg.p[1], &errno, sizeof(int))); - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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{exec}; @@ -423,12 +423,12 @@ struct default_launcher int err = errno; if ((err != EAGAIN) && (err != EINTR)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()); break; } } if (count != 0) - BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()); if (ec) { 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 6cf68b52a..ff28eef93 100644 --- a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp +++ b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp @@ -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...); - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } else if (pid == 0) @@ -107,7 +107,7 @@ struct fork_and_forget_launcher : default_launcher if (!ec) ::execve(executable.c_str(), const_cast(argv), const_cast(env)); - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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{exec}; diff --git a/include/boost/process/v2/posix/pdfork_launcher.hpp b/include/boost/process/v2/posix/pdfork_launcher.hpp index 016182734..a00baf4c1 100644 --- a/include/boost/process/v2/posix/pdfork_launcher.hpp +++ b/include/boost/process/v2/posix/pdfork_launcher.hpp @@ -85,12 +85,12 @@ struct pdfork_launcher : default_launcher pipe_guard pg; if (::pipe(pg.p)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } if (::fcntl(pg.p[1], F_SETFD, FD_CLOEXEC)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{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...); - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } else if (pid == 0) @@ -128,7 +128,7 @@ struct pdfork_launcher : default_launcher ::execve(executable.c_str(), const_cast(argv), const_cast(env)); default_launcher::ignore_unused(::write(pg.p[1], &errno, sizeof(int))); - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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{exec}; @@ -143,12 +143,12 @@ struct pdfork_launcher : default_launcher int err = errno; if ((err != EAGAIN) && (err != EINTR)) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()); break; } } if (count != 0) - BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, child_error, system_category()); if (ec) { diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index b9b8b6578..81c0db832 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -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...); - BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, errno, system_category()); return basic_process{exec}; } else if (pid == 0) @@ -107,7 +107,7 @@ struct vfork_launcher : default_launcher if (!ec) ::execve(executable.c_str(), const_cast(argv), const_cast(env)); - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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{exec}; diff --git a/include/boost/process/v2/stdio.hpp b/include/boost/process/v2/stdio.hpp index 4dc92b838..fdc348ca2 100644 --- a/include/boost/process/v2/stdio.hpp +++ b/include/boost/process/v2/stdio.hpp @@ -197,7 +197,7 @@ struct process_io_binding fd = p[1]; if (::fcntl(p[0], F_SETFD, FD_CLOEXEC) == -1) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ; } fd_needs_closing = true; @@ -223,7 +223,7 @@ struct process_io_binding fd = p[0]; if (::fcntl(p[1], F_SETFD, FD_CLOEXEC) == -1) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ; } fd_needs_closing = true; diff --git a/include/boost/process/v2/windows/as_user_launcher.hpp b/include/boost/process/v2/windows/as_user_launcher.hpp index 88f9c2a29..3829a120d 100644 --- a/include/boost/process/v2/windows/as_user_launcher.hpp +++ b/include/boost/process/v2/windows/as_user_launcher.hpp @@ -107,7 +107,7 @@ struct as_user_launcher : default_launcher if (ok == 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index 78cbd0cde..7ea8c8472 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -314,7 +314,7 @@ struct default_launcher if (ok == 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/with_logon_launcher.hpp b/include/boost/process/v2/windows/with_logon_launcher.hpp index e88722145..a71540cac 100644 --- a/include/boost/process/v2/windows/with_logon_launcher.hpp +++ b/include/boost/process/v2/windows/with_logon_launcher.hpp @@ -111,7 +111,7 @@ struct with_logon_launcher : default_launcher if (ok == 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/include/boost/process/v2/windows/with_token_launcher.hpp b/include/boost/process/v2/windows/with_token_launcher.hpp index a0b23bc41..48efab698 100644 --- a/include/boost/process/v2/windows/with_token_launcher.hpp +++ b/include/boost/process/v2/windows/with_token_launcher.hpp @@ -106,7 +106,7 @@ struct with_token_launcher : default_launcher if (ok == 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); detail::on_error(*this, executable, command_line, ec, inits...); if (process_information.hProcess != INVALID_HANDLE_VALUE) diff --git a/src/detail/environment_posix.cpp b/src/detail/environment_posix.cpp index c3006ca15..7a7913671 100644 --- a/src/detail/environment_posix.cpp +++ b/src/detail/environment_posix.cpp @@ -30,7 +30,7 @@ basic_cstring_ref> get( auto res = ::getenv(key.c_str()); if (res == nullptr) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category()); return {}; } return res; @@ -41,13 +41,13 @@ void set(basic_cstring_ref> key, error_code & ec) { if (::setenv(key.c_str(), value.c_str(), true)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void unset(basic_cstring_ref> key, error_code & ec) { if (::unsetenv(key.c_str())) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } diff --git a/src/detail/environment_win.cpp b/src/detail/environment_win.cpp index cbd64c6f6..27065192d 100644 --- a/src/detail/environment_win.cpp +++ b/src/detail/environment_win.cpp @@ -45,7 +45,7 @@ std::basic_string> get( buf.resize(size); if (buf.size() == 0) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return buf; } @@ -55,14 +55,14 @@ void set(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableW(key.c_str(), value.c_str())) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void unset(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableW(key.c_str(), nullptr)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } @@ -83,7 +83,7 @@ std::basic_string> get( buf.resize(size); if (buf.size() == 0) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return buf; } @@ -93,14 +93,14 @@ void set(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableA(key.c_str(), value.c_str())) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void unset(basic_cstring_ref> key, error_code & ec) { if (!::SetEnvironmentVariableA(key.c_str(), nullptr)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } diff --git a/src/detail/process_handle_windows.cpp b/src/detail/process_handle_windows.cpp index fa77e492a..afe821cd8 100644 --- a/src/detail/process_handle_windows.cpp +++ b/src/detail/process_handle_windows.cpp @@ -35,7 +35,7 @@ void get_exit_code_( error_code & ec) { if (!::GetExitCodeProcess(handle, &exit_code)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } @@ -45,7 +45,7 @@ HANDLE open_process_(DWORD pid) if (proc == nullptr) { error_code ec; - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); throw system_error(ec, "open_process()"); } @@ -67,7 +67,7 @@ bool check_handle_(HANDLE handle, error_code & ec) { if (handle == INVALID_HANDLE_VALUE) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()); return false; } return true; @@ -77,7 +77,7 @@ bool check_pid_(pid_type pid_, error_code & ec) { if (pid_ == 0) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_INVALID_HANDLE_STATE, system_category()); return false; } return true; @@ -100,7 +100,7 @@ static BOOL CALLBACK enum_window(HWND hwnd, LPARAM param) LRESULT res = ::SendMessageW(hwnd, WM_CLOSE, 0, 0); if (res) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(data->ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(data->ec); return res == 0; } @@ -109,25 +109,25 @@ void request_exit_(pid_type pid_, error_code & ec) enum_windows_data_t data{ec, pid_}; if (!::EnumWindows(enum_window, reinterpret_cast(&data))) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void interrupt_(pid_type pid_, error_code & ec) { if (!::GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid_)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void terminate_(HANDLE handle, error_code & ec, DWORD & exit_status) { if (!::TerminateProcess(handle, 260)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void check_running_(HANDLE handle, error_code & ec, DWORD & exit_status) { if (!::GetExitCodeProcess(handle, &exit_status)) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } #if !defined(BOOST_PROCESS_V2_DISABLE_UNDOCUMENTED_API) @@ -136,7 +136,7 @@ void suspend_(HANDLE handle, error_code & ec) auto nt_err = NtSuspendProcess(handle); ULONG dos_err = RtlNtStatusToDosError(nt_err); if (dos_err) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } void resume_(HANDLE handle, error_code & ec) @@ -144,17 +144,17 @@ void resume_(HANDLE handle, error_code & ec) auto nt_err = NtResumeProcess(handle); ULONG dos_err = RtlNtStatusToDosError(nt_err); if (dos_err) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } #else void suspend_(HANDLE, error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_CALL_NOT_IMPLEMENTED, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ERROR_CALL_NOT_IMPLEMENTED, system_category()); } #endif diff --git a/src/detail/utf8.cpp b/src/detail/utf8.cpp index f13a0b6d1..531683e86 100644 --- a/src/detail/utf8.cpp +++ b/src/detail/utf8.cpp @@ -25,13 +25,13 @@ inline void handle_error(error_code & ec) switch (err) { case ERROR_INSUFFICIENT_BUFFER: - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::utf8_category) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::utf8_category); break; case ERROR_NO_UNICODE_TRANSLATION: - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::utf8_category) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::utf8_category); break; default: - BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, err, system_category()); } } @@ -240,7 +240,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; - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()); return 0u; } @@ -268,7 +268,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); - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()); return 0u; } ++from; @@ -278,7 +278,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) - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()); return to_next - out; } @@ -313,7 +313,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; - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()); return 0u; } @@ -337,7 +337,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; - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::invalid_character, error::get_utf8_category()); return 0u; } @@ -354,7 +354,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; - BOOST_PROCESS_V2_ASSIGN_EC(ec, 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; @@ -363,7 +363,7 @@ std::size_t convert_to_wide(const char * in, std::size_t size, to_next = to; if (from != from_end) - BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error::insufficient_buffer, error::get_utf8_category()); return to_next - out; } diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index 3a5ea9e3a..a96fd4bbf 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -168,7 +168,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) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -181,7 +181,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (sysctl(mib, 3, &*procargs.begin(), &size, nullptr, 0) != 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -198,7 +198,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 { - BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()); return {}; } argv[n] = &*itr; @@ -223,7 +223,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) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); ::close(f); return {}; } @@ -254,7 +254,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 { - BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, EINVAL, system_category()); return {}; } argv[n] = &*itr; @@ -290,10 +290,10 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (cmd) return make_cmd_shell_::clone(cmd); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -322,10 +322,10 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (cmd) return make_cmd_shell_::clone(cmd); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -353,10 +353,10 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (cmd) return make_cmd_shell_::clone(cmd); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); kvm_close(kd); return {}; } @@ -384,13 +384,13 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) +[](int, char ** argv) {::free(argv);}) } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); kvm_close(kd); return {}; @@ -399,7 +399,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) #else filesystem::path cmd(boost::process::v2::pid_type, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); return ""; } #endif diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index d9a0dc7aa..2bbc4dc82 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -73,7 +73,7 @@ filesystem::path cwd(HANDLE proc, boost::system::error_code & ec) if (!buffer.empty()) return filesystem::canonical(buffer, ec); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ""; } @@ -88,7 +88,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); else return cwd(proc.get(), ec); return {}; @@ -111,7 +111,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code if (proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi)) > 0) return filesystem::canonical(vpi.pvi_cdir.vip_path, ec); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ""; } @@ -146,10 +146,10 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code path = filesystem::canonical(kif.kf_path, ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return path; } @@ -166,7 +166,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code path = filesystem::canonical(buffer, ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return path; } @@ -192,17 +192,17 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code path = filesystem::canonical(&vecbuff[0], ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return path; } #else filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); return ""; } #endif diff --git a/src/ext/env.cpp b/src/ext/env.cpp index bddd8cd71..e7861c6d7 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -174,19 +174,19 @@ env_view env(HANDLE proc, boost::system::error_code & ec) if (error) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()); return {}; } if (!ReadProcessMemory(proc, pbi.PebBaseAddress, &peb, sizeof(peb), &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } if (!ReadProcessMemory(proc, peb.ProcessParameters, &upp, sizeof(upp), &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -197,7 +197,7 @@ env_view env(HANDLE proc, boost::system::error_code & ec) if (!ReadProcessMemory(proc, buf, ev.handle_.get(), len, &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -225,7 +225,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); else return env(proc.get(), ec); @@ -241,7 +241,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) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -254,7 +254,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) if (sysctl(mib, 3, &*procargs.begin(), &size, nullptr, 0) != 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } std::uint32_t nargs; @@ -312,7 +312,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) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); ::close(f); return {}; } @@ -379,18 +379,18 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) ev.handle_.reset(eeo); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); } procstat_freeprocs(proc_stat, proc_info); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); procstat_close(proc_stat); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ev; } diff --git a/src/ext/exe.cpp b/src/ext/exe.cpp index 5240d2516..9e6e78eae 100644 --- a/src/ext/exe.cpp +++ b/src/ext/exe.cpp @@ -83,7 +83,7 @@ filesystem::path exe(HANDLE proc, boost::system::error_code & ec) return filesystem::canonical(buffer, ec); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ""; } @@ -109,7 +109,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code }; std::unique_ptr proc{detail::ext::open_process_with_debug_privilege(pid, ec)}; if (proc == nullptr) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); else return exe(proc.get(), ec); } @@ -125,7 +125,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code { return filesystem::canonical(buffer, ec); } - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ""; } @@ -165,7 +165,7 @@ filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code } } - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ""; } @@ -173,14 +173,14 @@ 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) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); return ""; } #else filesystem::path exe(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); return ""; } #endif diff --git a/src/ext/proc_info.cpp b/src/ext/proc_info.cpp index 22bdfa0d8..aef9d1b75 100644 --- a/src/ext/proc_info.cpp +++ b/src/ext/proc_info.cpp @@ -43,19 +43,19 @@ std::wstring cwd_cmd_from_proc(HANDLE proc, int type, boost::system::error_code if (error) { - BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, error, system_category()); return {}; } if (!ReadProcessMemory(proc, pbi.PebBaseAddress, &peb, sizeof(peb), &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } if (!ReadProcessMemory(proc, peb.ProcessParameters, &upp, sizeof(upp), &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -74,7 +74,7 @@ std::wstring cwd_cmd_from_proc(HANDLE proc, int type, boost::system::error_code if (!ReadProcessMemory(proc, buf, &buffer[0], len, &nRead)) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } @@ -107,7 +107,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) - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return proc; } #endif diff --git a/src/pid.cpp b/src/pid.cpp index d6ab609e9..7713b8221 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -74,7 +74,7 @@ std::vector all_pids(boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } PROCESSENTRY32 pe; @@ -96,7 +96,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } PROCESSENTRY32 pe; @@ -123,7 +123,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (!hp) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } PROCESSENTRY32 pe; @@ -152,7 +152,7 @@ std::vector all_pids(boost::system::error_code & ec) const auto sz = proc_listpids(PROC_ALL_PIDS, 0, &vec[0], sizeof(pid_type) * vec.size()); if (sz < 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } vec.resize(sz); @@ -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) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } else @@ -180,7 +180,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) const auto sz = proc_listpids(PROC_PPID_ONLY, (uint32_t)pid, &vec[0], sizeof(pid_type) * vec.size()); if (sz < 0) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {}; } vec.resize(sz); @@ -195,7 +195,7 @@ std::vector all_pids(boost::system::error_code & ec) DIR *proc = opendir("/proc"); if (!proc) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } struct dirent *ent = nullptr; @@ -218,9 +218,9 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) if (!stat) { if (errno == ENOENT) - BOOST_PROCESS_V2_ASSIGN_EC(ec, ESRCH, system_category()) + BOOST_PROCESS_V2_ASSIGN_EC(ec, ESRCH, system_category()); else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } else @@ -245,7 +245,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) if (!token) { fclose(stat); - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } } @@ -286,7 +286,7 @@ std::vector all_pids(boost::system::error_code & ec) free(proc_info); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -300,7 +300,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) free(proc_info); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } @@ -322,7 +322,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) free(proc_info); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -346,7 +346,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) @@ -357,7 +357,7 @@ std::vector all_pids(boost::system::error_code & ec) vec.push_back(proc_info[i].kp_pid); } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -379,7 +379,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) @@ -390,7 +390,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } @@ -412,7 +412,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) @@ -427,7 +427,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -449,7 +449,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -461,7 +461,7 @@ std::vector all_pids(boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -481,7 +481,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -489,7 +489,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } @@ -509,7 +509,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -524,7 +524,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -546,7 +546,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -561,7 +561,7 @@ std::vector all_pids(boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -581,7 +581,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -589,7 +589,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } @@ -609,7 +609,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + 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))) @@ -624,7 +624,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } @@ -647,7 +647,7 @@ std::vector all_pids(boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } while ((proc_info = kvm_nextproc(kd))) @@ -658,7 +658,7 @@ std::vector all_pids(boost::system::error_code & ec) } else { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); break; } } @@ -680,7 +680,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } if ((proc_info = kvm_getproc(kd, pid))) @@ -688,7 +688,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) ppid = proc_info->p_ppid; } else - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ppid; } @@ -708,7 +708,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); if (!kd) { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return vec; } while ((proc_info = kvm_nextproc(kd))) @@ -721,7 +721,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) } else { - BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); break; } } From 8a8ca8b7ab3270dcd22addba7523a336fbda76a1 Mon Sep 17 00:00:00 2001 From: Samuel Venable Date: Sun, 27 Oct 2024 17:49:44 +0800 Subject: [PATCH 25/28] OpenBSD fix & Solaris fixes [DragonFly BSD] Use Proper CWD From PID Code --- .../process/v2/posix/default_launcher.hpp | 2 +- src/ext/cmd.cpp | 7 +-- src/ext/cwd.cpp | 2 +- src/ext/env.cpp | 50 ++++++++++++++++++- src/shell.cpp | 29 +++++++++-- test/v2/Jamfile.jam | 12 ++++- 6 files changed, 92 insertions(+), 10 deletions(-) diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index 625be154a..42a9d6f87 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -29,7 +29,7 @@ #include -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__MACH__) +#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) extern "C" { extern char **environ; } #endif diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index a96fd4bbf..fca5d1b5c 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -357,7 +357,6 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - kvm_close(kd); return {}; } @@ -368,7 +367,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) char **cmd = nullptr; proc *proc_info = nullptr; user *proc_user = nullptr; - kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); + kvm_t *kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} if ((proc_info = kvm_getproc(kd, pid))) { @@ -379,9 +378,11 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) int argc = 0; for (int i = 0; cmd[i] != nullptr; i++) argc ++; - return make_cmd_shell_::make( + shell res = make_cmd_shell_::make( {}, argc, cmd, +[](int, char ** argv) {::free(argv);}) + kvm_close(kd); + return res; } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index 2bbc4dc82..6aee83de1 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -187,7 +187,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code { std::vector vecbuff; vecbuff.resize(len); - if (sysctl(mib, 4, &vecbuff[0], &len, nullptr, 0) == 0) + if (sysctl(mib, sz, &vecbuff[0], &len, nullptr, 0) == 0) { path = filesystem::canonical(&vecbuff[0], ec); } diff --git a/src/ext/env.cpp b/src/ext/env.cpp index e7861c6d7..ee7978803 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -42,6 +42,13 @@ #include #endif +#if defined(__OpenBSD__) +#include +#include +#include +#include +#endif + BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { @@ -98,7 +105,7 @@ const environment::char_type * dereference(native_env_iterator iterator) return iterator; } -#elif (defined(__APPLE___) || defined(__MACH__)) +#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__OpenBSD__) void native_env_handle_deleter::operator()(native_env_handle_type h) const { @@ -393,7 +400,48 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ev; } +#elif defined(__OpenBSD__) +env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + + std::vector vec; + int cntp = 0; + kinfo_proc *proc_info = nullptr; + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; + if (!kd.get()) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp))) + { + char **env = kvm_getenvv(kd.get(), proc_info, 0); + if (env) + { + for (int i = 0; env[i] != nullptr; i++) + { + for (int j = 0; j < strlen(env[i]); j++) + vec.push_back(env[i][j]); + vec.push_back('\0'); + } + vec.push_back('\0'); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + + env_view ev; + ev.handle_.reset(new char[vec.size()]()); + std::copy(vec.begin(), vec.end(), ev.handle_.get()); + return ev; +} #endif env_view env(boost::process::v2::pid_type pid) diff --git a/src/shell.cpp b/src/shell.cpp index b563819e6..ec0548d01 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -19,7 +19,7 @@ #if defined(BOOST_PROCESS_V2_WINDOWS) #include #include -#else +#elif !defined(__OpenBSD__) #include #endif @@ -30,7 +30,7 @@ BOOST_PROCESS_V2_DECL const error_category& get_shell_category() { return system_category(); } -#else +#elif !defined(__OpenBSD__) struct shell_category_t final : public error_category { @@ -66,6 +66,13 @@ BOOST_PROCESS_V2_DECL const error_category& get_shell_category() return instance; } +#else + +const error_category& get_shell_category() +{ + return system_category(); +} + #endif #if defined (BOOST_PROCESS_V2_WINDOWS) @@ -92,7 +99,7 @@ auto shell::args() const-> args_type return input_.c_str(); } -#else +#elif !defined(__OpenBSD__) void shell::parse_() { @@ -135,6 +142,22 @@ auto shell::args() const -> args_type return const_cast(argv()); } +#else + +void shell::parse_() +{ + error_code ec; + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); + throw system_error(ec, "shell::parse"); +} + +shell::~shell() = default; + +auto shell::args() const -> args_type +{ + return nullptr; +} + #endif BOOST_PROCESS_V2_END_NAMESPACE diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 7c6715a14..86774c6af 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -20,8 +20,18 @@ project : requirements windows:WIN32_LEAN_AND_MEAN windows:_WIN32_WINNT=0x0601 linux:-lpthread - freebsd:-lutil freebsd:-lpthread + freebsd:-lutil + freebsd:-lkvm + freebsd:-lprocstat + bsd:-lpthread + bsd:-lkvm + netbsd:-lpthread + netbsd:-lkvm + openbsd:-lpthread + openbsd:-lkvm + solaris:-lpthread + solaris:-lkvm NT,cw:ws2_32 NT,gcc:ws2_32 NT,gcc:Bcrypt From 3ad68a3f2a23d0d63053789702187288fc4c7982 Mon Sep 17 00:00:00 2001 From: Samuel Venable Date: Mon, 28 Oct 2024 18:33:06 -0600 Subject: [PATCH 26/28] [OpenBSD] Add Missing Semicolons (#414) * [OpenBSD] Add Missing Semicolons --- src/ext/cmd.cpp | 13 +++++-------- src/ext/env.cpp | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index fca5d1b5c..de1e06ccc 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -283,7 +283,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; - if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) 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); @@ -301,8 +301,6 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - - std::vector vec; int cntp = 0; kinfo_proc2 *proc_info = nullptr; struct closer @@ -315,7 +313,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; - if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} 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); @@ -326,14 +324,13 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - return vec; + return {}; } #elif defined(__OpenBSD__) shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - std::vector vec; int cntp = 0; kinfo_proc *proc_info = nullptr; @@ -346,7 +343,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; - if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} 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); @@ -368,7 +365,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) proc *proc_info = nullptr; user *proc_user = nullptr; kvm_t *kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); - if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) 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))) diff --git a/src/ext/env.cpp b/src/ext/env.cpp index ee7978803..44dc5d5f8 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -417,7 +417,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) }; std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; - if (!kd.get()) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp))) { char **env = kvm_getenvv(kd.get(), proc_info, 0); From 7e5dd4075f3d29d7f8cc50c1c8a670eb8164d8a7 Mon Sep 17 00:00:00 2001 From: Samuel Venable Date: Tue, 29 Oct 2024 15:06:15 +0000 Subject: [PATCH 27/28] bp2::ext::env() Fixes (#415) * Implement OpenBSD Executable PatH * Static Cast Device and iNode * Add Name Spaces to Exe Checker * Strings to File System Paths --------- Co-authored-by: freebsd --- include/boost/process/v2/ext/cmd.hpp | 1 + include/boost/process/v2/ext/env.hpp | 4 +- include/boost/process/v2/pid.hpp | 1 + src/ext/cmd.cpp | 28 ++-- src/ext/env.cpp | 224 ++++++++++++++++++--------- src/ext/exe.cpp | 2 +- src/pid.cpp | 90 +++++++++-- test/v2/Jamfile.jam | 2 - 8 files changed, 246 insertions(+), 106 deletions(-) diff --git a/include/boost/process/v2/ext/cmd.hpp b/include/boost/process/v2/ext/cmd.hpp index 6308885eb..b429465bf 100644 --- a/include/boost/process/v2/ext/cmd.hpp +++ b/include/boost/process/v2/ext/cmd.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include diff --git a/include/boost/process/v2/ext/env.hpp b/include/boost/process/v2/ext/env.hpp index 8c634739a..4e2a92ca7 100644 --- a/include/boost/process/v2/ext/env.hpp +++ b/include/boost/process/v2/ext/env.hpp @@ -8,6 +8,7 @@ #define BOOST_PROCESS_V2_ENV_HPP #include #include +#include #include #include @@ -26,9 +27,6 @@ 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 *; diff --git a/include/boost/process/v2/pid.hpp b/include/boost/process/v2/pid.hpp index 8c6779b2b..e705b949e 100644 --- a/include/boost/process/v2/pid.hpp +++ b/include/boost/process/v2/pid.hpp @@ -10,6 +10,7 @@ #include #include +#include BOOST_PROCESS_V2_BEGIN_NAMESPACE diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index de1e06ccc..519a1bc98 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -52,6 +52,7 @@ #endif #if defined(__sun) +#include #include #include #include @@ -274,6 +275,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) kinfo_proc *proc_info = nullptr; const char *nlistf, *memf; nlistf = memf = "/dev/null"; + struct closer { void operator()(kvm_t * kd) @@ -303,6 +305,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) { int cntp = 0; kinfo_proc2 *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -364,22 +367,29 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) char **cmd = nullptr; proc *proc_info = nullptr; user *proc_user = nullptr; - kvm_t *kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} - if ((proc_info = kvm_getproc(kd, pid))) + if ((proc_info = kvm_getproc(kd.get(), pid))) { - if ((proc_user = kvm_getu(kd, proc_info))) + if ((proc_user = kvm_getu(kd.get(), proc_info))) { - if (!kvm_getcmd(kd, proc_info, proc_user, &cmd, nullptr)) + if (!kvm_getcmd(kd.get(), proc_info, proc_user, &cmd, nullptr)) { int argc = 0; for (int i = 0; cmd[i] != nullptr; i++) - argc ++; - shell res = make_cmd_shell_::make( + argc++; + return make_cmd_shell_::make( {}, argc, cmd, +[](int, char ** argv) {::free(argv);}) - kvm_close(kd); - return res; } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); @@ -389,8 +399,6 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - - kvm_close(kd); return {}; } diff --git a/src/ext/env.cpp b/src/ext/env.cpp index 44dc5d5f8..35af73a05 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -23,6 +23,7 @@ #if (defined(__APPLE__) && defined(__MACH__)) #include #if !TARGET_OS_IOS + #include #include #include #include @@ -34,21 +35,52 @@ #endif #if defined(__FreeBSD__) -#include -#include +#include +#include +#include +#include #include -#include +#include #include -#include +#endif + +#if defined(__DragonFly__) +#include +#include +#include +#include +#endif + +#if defined(__NetBSD__) +#include +#include +#include +#include +#include +#include #endif #if defined(__OpenBSD__) +#include +#include #include #include #include #include #endif +#if defined(__sun) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { @@ -105,7 +137,7 @@ const environment::char_type * dereference(native_env_iterator iterator) return iterator; } -#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__OpenBSD__) +#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) void native_env_handle_deleter::operator()(native_env_handle_type h) const { @@ -130,31 +162,6 @@ 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 } @@ -338,72 +345,90 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) return ev; } -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - env_view ev; + std::vector vec; + int cntp = 0; + kinfo_proc *proc_info = nullptr; + const char *nlistf, *memf; + nlistf = memf = "/dev/null"; - unsigned cntp = 0; - procstat *proc_stat = procstat_open_sysctl(); - if (proc_stat != nullptr) + struct closer { - kinfo_proc *proc_info = procstat_getprocs(proc_stat, KERN_PROC_PID, pid, &cntp); - if (proc_info != nullptr) + void operator()(kvm_t * kd) { - char **env = procstat_getenvv(proc_stat, proc_info, 0); - if (env != nullptr) + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) { + char **env = kvm_getenvv(kd.get(), proc_info, 0); + if (env) { + for (int i = 0; env[i] != nullptr; i++) { - 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; + for (int j = 0; j < strlen(env[i]); j++) + vec.push_back(env[i][j]); + vec.push_back('\0'); + } + vec.push_back('\0'); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - char * out = new (std::nothrow) char[mem_needed]; - if (out != nullptr) - { - auto eno = reinterpret_cast(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); + env_view ev; + ev.handle_.reset(new char[vec.size()]()); + std::copy(vec.begin(), vec.end(), ev.handle_.get()); + return ev; +} - } - procstat_freeprocs(proc_stat, proc_info); +#elif defined(__NetBSD__) +env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + std::vector vec; + int cntp = 0; + kinfo_proc2 *proc_info = nullptr; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} + if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &cntp))) { + char **env = kvm_getenvv2(kd.get(), proc_info, 0); + if (env) { + for (int i = 0; env[i] != nullptr; i++) + { + for (int j = 0; j < strlen(env[i]); j++) + vec.push_back(env[i][j]); + vec.push_back('\0'); + } + vec.push_back('\0'); } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - procstat_close(proc_stat); } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + + env_view ev; + ev.handle_.reset(new char[vec.size()]()); + std::copy(vec.begin(), vec.end(), ev.handle_.get()); return ev; } #elif defined(__OpenBSD__) env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) { - std::vector vec; int cntp = 0; kinfo_proc *proc_info = nullptr; @@ -442,6 +467,53 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) std::copy(vec.begin(), vec.end(), ev.handle_.get()); return ev; } +#elif defined(__sun) +env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + std::vector vec; + char **env = nullptr; + proc *proc_info = nullptr; + user *proc_user = nullptr; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)}; + if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};} + if ((proc_info = kvm_getproc(kd.get(), pid))) + { + if ((proc_user = kvm_getu(kd.get(), proc_info))) + { + if (!kvm_getcmd(kd.get(), proc_info, proc_user, nullptr, &env)) + { + for (int i = 0; env[i] != nullptr; i++) + { + for (int j = 0; j < strlen(env[i]); j++) + vec.push_back(env[i][j]); + vec.push_back('\0'); + } + vec.push_back('\0'); + free(env); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + + env_view ev; + ev.handle_.reset(new char[vec.size()]()); + std::copy(vec.begin(), vec.end(), ev.handle_.get()); + return ev; +} #endif env_view env(boost::process::v2::pid_type pid) diff --git a/src/ext/exe.cpp b/src/ext/exe.cpp index 9e6e78eae..0f05f8ab0 100644 --- a/src/ext/exe.cpp +++ b/src/ext/exe.cpp @@ -39,7 +39,7 @@ #if (defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)) #include #include -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) #include #endif #endif diff --git a/src/pid.cpp b/src/pid.cpp index 7713b8221..950ed9467 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -29,10 +29,11 @@ #endif #if defined(__FreeBSD__) -#include +#include +#include +#include +#include #include -#include -#include #endif #if (defined(__DragonFly__) || defined(__OpenBSD__)) @@ -277,13 +278,29 @@ std::vector all_pids(boost::system::error_code & ec) { std::vector vec; int cntp = 0; - kinfo_proc *proc_info = kinfo_getallproc(&cntp); - if (proc_info) + kinfo_proc *proc_info = nullptr; + const char *nlistf, *memf; + nlistf = memf = "/dev/null"; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; + if (!kd) + { + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + return vec; + } + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) { vec.reserve(cntp); - for (int i = 0; i < cntp; i++) + for (int i = 0; i < cntp; i++) vec.push_back(proc_info[i].ki_pid); - free(proc_info); } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); @@ -293,11 +310,28 @@ std::vector all_pids(boost::system::error_code & ec) pid_type parent_pid(pid_type pid, boost::system::error_code & ec) { pid_type ppid = static_cast(-1); - kinfo_proc *proc_info = kinfo_getproc(pid); - if (proc_info) + int cntp = 0; + kinfo_proc *proc_info = nullptr; + const char *nlistf, *memf; + nlistf = memf = "/dev/null"; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; + if (!kd) + { + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + return ppid; + } + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) { ppid = proc_info->ki_ppid; - free(proc_info); } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); @@ -307,9 +341,26 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) std::vector child_pids(pid_type pid, boost::system::error_code & ec) { std::vector vec; - int cntp = 0; - kinfo_proc *proc_info = kinfo_getallproc(&cntp); - if (proc_info) + int cntp = 0; + kinfo_proc *proc_info = nullptr; + const char *nlistf, *memf; + nlistf = memf = "/dev/null"; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)}; + if (!kd) + { + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + return vec; + } + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp))) { vec.reserve(cntp); for (int i = 0; i < cntp; i++) @@ -319,7 +370,6 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) vec.push_back(proc_info[i].ki_pid); } } - free(proc_info); } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); @@ -335,6 +385,7 @@ std::vector all_pids(boost::system::error_code & ec) kinfo_proc *proc_info = nullptr; const char *nlistf, *memf; nlistf = memf = "/dev/null"; + struct closer { void operator()(kvm_t * kd) @@ -368,6 +419,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) kinfo_proc *proc_info = nullptr; const char *nlistf, *memf; nlistf = memf = "/dev/null"; + struct closer { void operator()(kvm_t * kd) @@ -401,6 +453,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) kinfo_proc *proc_info = nullptr; const char *nlistf, *memf; nlistf = memf = "/dev/null"; + struct closer { void operator()(kvm_t * kd) @@ -438,6 +491,7 @@ std::vector all_pids(boost::system::error_code & ec) std::vector vec; int cntp = 0; kinfo_proc2 *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -470,6 +524,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) pid_type ppid = static_cast(-1); int cntp = 0; kinfo_proc2 *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -498,6 +553,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::vector vec; int cntp = 0; kinfo_proc2 *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -535,6 +591,7 @@ std::vector all_pids(boost::system::error_code & ec) std::vector vec; int cntp = 0; kinfo_proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -570,6 +627,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) pid_type ppid = static_cast(-1); int cntp = 0; kinfo_proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -598,6 +656,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::vector vec; int cntp = 0; kinfo_proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -636,6 +695,7 @@ std::vector all_pids(boost::system::error_code & ec) std::vector vec; struct pid cur_pid; proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -669,6 +729,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec) { pid_type ppid = static_cast(-1); proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) @@ -697,6 +758,7 @@ std::vector child_pids(pid_type pid, boost::system::error_code & ec) std::vector vec; struct pid cur_pid; proc *proc_info = nullptr; + struct closer { void operator()(kvm_t * kd) diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 86774c6af..20aaf06fd 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -21,9 +21,7 @@ project : requirements windows:_WIN32_WINNT=0x0601 linux:-lpthread freebsd:-lpthread - freebsd:-lutil freebsd:-lkvm - freebsd:-lprocstat bsd:-lpthread bsd:-lkvm netbsd:-lpthread From 58586e420cf181ca865945837f6c33a46b973fd8 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Tue, 29 Oct 2024 23:36:40 +0800 Subject: [PATCH 28/28] added deprecation notice for v1. --- doc/process.qbk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/process.qbk b/doc/process.qbk index bf3b3b802..43cb6031d 100644 --- a/doc/process.qbk +++ b/doc/process.qbk @@ -11,7 +11,7 @@ ] ] -[note Process v1 will be deprecated in the future. Use v2 for new projects.] +[note Process v1 will be deprecated in the next release (1.88). Use v2 for new projects.] [include v1.qbk] [include v2.qbk]