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

Compare commits

..

4 Commits

Author SHA1 Message Date
Klemens
c4ba43e970 FreeBSD fix 2023-02-07 19:30:35 +08:00
Klemens Morgenstern
19212708e5 ec use locations. 2023-02-07 17:48:54 +08:00
Klemens Morgenstern
42ba48f744 xproc fixes 2023-02-07 17:48:54 +08:00
Samuel Venable
1e60fcd830 extern process management. 2023-02-06 20:43:32 +08:00
5 changed files with 9 additions and 30 deletions

View File

@@ -155,15 +155,13 @@ private:
std::vector<char*> exe_cmd_init<char>::make_cmd()
{
// any string must be writable.
static char empty_string[1] = "";
std::vector<char*> vec;
if (!exe.empty())
vec.push_back(exe.empty() ? empty_string : &exe.front());
vec.push_back(&exe.front());
if (!args.empty()) {
for (auto & v : args)
vec.push_back(v.empty() ? empty_string : &v.front());
vec.push_back(&v.front());
}
vec.push_back(nullptr);

View File

@@ -92,12 +92,13 @@ struct make_cmd_shell_
str_lengths += (std::strlen(*c) + 1);
}
// yes, not the greatest solution.
std::string buffer;
res.buffer_.resize(str_lengths);
res.argv_ = new char*[res.argc_ + 1];
res.free_argv_ = +[](int argc, char ** argv) {delete[] argv;};
res.argv_[res.argc_] = nullptr;
auto p = &*res.buffer_.begin();
auto p = &buffer[sizeof(int) * (res.argc_) + 1];
for (int i = 0; i < res.argc_; i++)
{
@@ -304,8 +305,9 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
return {};
}
auto res = make_cmd_shell_::clone(cmd);
procstat_freeargv(proc_stat.get());
procstat_freeargv(proc_stat);
return res;
}

View File

@@ -342,7 +342,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
auto eno = reinterpret_cast<char**>(out);
auto eeo = eno;
auto str = out + (n * sizeof(char*)) + sizeof(char*);
auto str = out + (n * sizeof(char*)) + sizeof(char*);
e = env;
while (*e != nullptr)
{
@@ -351,11 +351,11 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
*eno = str;
str += len;
eno ++;
e++;
}
*eno = nullptr;
ev.handle_.reset(eeo);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)

View File

@@ -115,7 +115,7 @@ void shell::parse_()
shell::~shell()
{
if (argv_ != nullptr && free_argv_ != nullptr)
if (argv_ != nullptr && free_argv_)
free_argv_(argc_, argv_);
}

View File

@@ -83,24 +83,3 @@ BOOST_AUTO_TEST_CASE(implicit)
BOOST_TEST_MESSAGE(ec.message());
BOOST_CHECK_EQUAL(ret, 21);
}
BOOST_AUTO_TEST_CASE(empty_cmd)
{
using boost::unit_test::framework::master_test_suite;
std::error_code ec;
fs::path pth = master_test_suite().argv[1];
auto env = boost::this_process::environment();
auto itr = std::find_if(env.begin(), env.end(),
[](const bp::native_environment::entry_type & e){return boost::to_upper_copy(e.get_name()) == "PATH";});
BOOST_REQUIRE(itr != env.end());
(*itr) += fs::canonical(fs::absolute(pth.parent_path())).string();
BOOST_REQUIRE(itr != env.end());
bp::system("sparring_partner \"\" ", ec);
}