mirror of
https://github.com/boostorg/process.git
synced 2026-01-20 04:42:24 +00:00
Compare commits
4 Commits
origin/xpr
...
cmd-empty-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
743f0cca35 | ||
|
|
81ad643b00 | ||
|
|
6fd1200ab7 | ||
|
|
c7bdccd57e |
@@ -155,13 +155,15 @@ 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.front());
|
||||
vec.push_back(exe.empty() ? empty_string : &exe.front());
|
||||
|
||||
if (!args.empty()) {
|
||||
for (auto & v : args)
|
||||
vec.push_back(&v.front());
|
||||
vec.push_back(v.empty() ? empty_string : &v.front());
|
||||
}
|
||||
|
||||
vec.push_back(nullptr);
|
||||
|
||||
@@ -92,13 +92,12 @@ 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 = &buffer[sizeof(int) * (res.argc_) + 1];
|
||||
auto p = &*res.buffer_.begin();
|
||||
|
||||
for (int i = 0; i < res.argc_; i++)
|
||||
{
|
||||
@@ -305,9 +304,8 @@ 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);
|
||||
procstat_freeargv(proc_stat.get());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -115,7 +115,7 @@ void shell::parse_()
|
||||
|
||||
shell::~shell()
|
||||
{
|
||||
if (argv_ != nullptr && free_argv_)
|
||||
if (argv_ != nullptr && free_argv_ != nullptr)
|
||||
free_argv_(argc_, argv_);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,3 +83,24 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user