From b294710e60e4fc4e36ba2cbd2cadbbb072137510 Mon Sep 17 00:00:00 2001 From: Klemens David Morgenstern Date: Sat, 6 Apr 2019 14:42:08 +0800 Subject: [PATCH] fixed self-pipe issue --- include/boost/process/detail/posix/executor.hpp | 11 ++++++++--- test/Jamfile.jam | 5 ++--- test/pipe.cpp | 4 +++- test/pipe_fwd.cpp | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/boost/process/detail/posix/executor.hpp b/include/boost/process/detail/posix/executor.hpp index 01640205..2335247a 100644 --- a/include/boost/process/detail/posix/executor.hpp +++ b/include/boost/process/detail/posix/executor.hpp @@ -372,11 +372,14 @@ child executor::invoke(boost::mpl::false_, boost::mpl::false_) struct pipe_guard { int p[2]; + pipe_guard() : p{-1,-1} {} ~pipe_guard() { - ::close(p[0]); - ::close(p[1]); + if (p[0] != -1) + ::close(p[0]); + if (p[1] != -1) + ::close(p[1]); } } p{}; @@ -430,8 +433,10 @@ child executor::invoke(boost::mpl::false_, boost::mpl::false_) return child(); } - + ::close(p.p[1]); + p.p[1] = -1; _read_error(p.p[0]); + } if (_ec) { diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 9defea7d..a2940f3d 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -55,7 +55,8 @@ exe sub_launch : sub_launcher.cpp program_options iostreams system filesystem : rule test-options ( name ) { - return --log_sink=log_$(name).xml --log_format=XML --log_level=error --report_sink=report_$(name).xml --report_format=XML --report_level=detailed -- ; + # return --log_sink=log_$(name).xml --log_format=XML --log_level=error --report_sink=report_$(name).xml --report_format=XML --report_level=detailed -- ; + return --log_level=error --report_level=detailed -- ; } @@ -68,8 +69,6 @@ test-suite bare : [ compile-fail async_system_fail.cpp ] ; -echo [ test-options foo ] ; - test-suite with-valgrind : [ run async.cpp system thread filesystem : [ test-options async ] : sparring_partner ] [ run async_fut.cpp system thread filesystem : [ test-options async_fut ] : sparring_partner ] diff --git a/test/pipe.cpp b/test/pipe.cpp index bbdef592..7ee1cc9c 100644 --- a/test/pipe.cpp +++ b/test/pipe.cpp @@ -11,6 +11,7 @@ #include #include +#include using namespace std; namespace bp = boost::process; @@ -38,7 +39,8 @@ BOOST_AUTO_TEST_CASE(named, *boost::unit_test::timeout(2)) #if defined( BOOST_WINDOWS_API ) bp::pipe pipe("\\\\.\\pipe\\pipe_name"); #elif defined( BOOST_POSIX_API ) - bp::pipe pipe("./test_pipe"); + const auto home_path = boost::this_process::environment()["HOME"].to_string(); + bp::pipe pipe(home_path + "/.boost_process_test_pipe"); #endif std::string in = "xyz"; diff --git a/test/pipe_fwd.cpp b/test/pipe_fwd.cpp index ba245e3d..9cdc7394 100644 --- a/test/pipe_fwd.cpp +++ b/test/pipe_fwd.cpp @@ -51,6 +51,8 @@ BOOST_AUTO_TEST_CASE(sync_io, *boost::unit_test::timeout(5)) ); BOOST_REQUIRE(!ec); + BOOST_TEST_INFO("Launching child 2"); + bp::child c2( master_test_suite().argv[1], bp::args={"test", "--prefix-once", "hello "},