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

Compare commits

...

3 Commits

Author SHA1 Message Date
Klemens Morgenstern
7cb7af6c8b Closes #267 2022-08-31 15:40:57 +08:00
Klemens
df33c1ad7b Fixed unsafe post-fork allocs for fd_whitelist. 2022-08-31 15:35:41 +08:00
Klemens
bbabea30dd Added reaping child for execve error, closes #265. 2022-08-31 15:35:41 +08:00
7 changed files with 25 additions and 10 deletions

View File

@@ -444,6 +444,8 @@ child executor<Sequence>::invoke(boost::mpl::false_, boost::mpl::false_)
}
if (_ec)
{
//if an error occured we need to reap the child process
::waitpid(this->pid, nullptr, WNOHANG);
boost::fusion::for_each(seq, call_on_error(*this, _ec));
return child();
}
@@ -537,6 +539,7 @@ child executor<Sequence>::invoke(boost::mpl::false_, boost::mpl::true_)
if (_ec)
{
::waitpid(this->pid, nullptr, WNOHANG);
boost::fusion::for_each(seq, call_on_error(*this, _ec));
return child();
}

View File

@@ -263,7 +263,7 @@ public:
auto st1 = key + ::boost::process::detail::equal_sign<Char>();
while (*p != nullptr)
{
const int len = std::char_traits<Char>::length(*p);
const auto len = std::char_traits<Char>::length(*p);
if ((std::distance(st1.begin(), st1.end()) < len)
&& std::equal(st1.begin(), st1.end(), *p))
break;

View File

@@ -91,13 +91,16 @@ struct bind_fd
{
}
error_code on_setup(posix::default_launcher & launcher, const filesystem::path &, const char * const *)
{
launcher.fd_whitelist.push_back(target);
}
/// Implementation of the initialization function.
error_code on_exec_setup(posix::default_launcher & launcher, const filesystem::path &, const char * const *)
{
if (::dup2(fd, target) == -1)
return error_code(errno, system_category());
launcher.fd_whitelist.push_back(target);
return error_code ();
}
};

View File

@@ -378,6 +378,7 @@ struct default_launcher
detail::on_error(*this, executable, argv, ec, inits...);
return basic_process<Executor>(exec);
}
fd_whitelist.push_back(pg.p[1]);
auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query(
exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context);
@@ -399,7 +400,6 @@ struct default_launcher
ec = detail::on_exec_setup(*this, executable, argv, inits...);
if (!ec)
{
fd_whitelist.push_back(pg.p[1]);
close_all_fds(ec);
}
if (!ec)

View File

@@ -99,6 +99,7 @@ struct pdfork_launcher : default_launcher
detail::on_error(*this, executable, argv, ec, inits...);
return basic_process<Executor>(exec);
}
fd_whitelist.push_back(pg.p[1]);
auto & ctx = BOOST_PROCESS_V2_ASIO_NAMESPACE::query(
exec, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::context);
@@ -121,7 +122,6 @@ struct pdfork_launcher : default_launcher
ec = detail::on_exec_setup(*this, executable, argv, inits...);
if (!ec)
{
fd_whitelist.push_back(pg.p[1]);
close_all_fds(ec);
}
if (!ec)

View File

@@ -289,11 +289,6 @@ struct process_stdio
if (::dup2(err.fd, err.target) == -1)
return error_code(errno, system_category());
launcher.fd_whitelist.push_back(STDIN_FILENO);
launcher.fd_whitelist.push_back(STDOUT_FILENO);
launcher.fd_whitelist.push_back(STDERR_FILENO);
return error_code {};
};
#endif

View File

@@ -113,3 +113,17 @@ BOOST_AUTO_TEST_CASE(ignore_error)
BOOST_CHECK_NO_THROW(bp::child c("doesnt-exit", bp::ignore_error));
}
}
BOOST_AUTO_TEST_CASE(not_found)
{
try
{
bp::child c("doesnt-exit");
BOOST_CHECK_MESSAGE(false, "Should throw");
}
catch( bp::process_error & se)
{
BOOST_CHECK(se.code());
}
}