utils: rework running system commands

Use g_spawn and pass arguments, so we don't involve a shell that needs
escaping etc.

Improve error handling.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-18 19:10:08 +03:00
parent 5efd0a61aa
commit cf6c5a36d7
4 changed files with 56 additions and 30 deletions

View File

@ -115,24 +115,6 @@ Mu::allow_warnings()
{});
}
Result<int>
Mu::run_mu_command(const std::string& args)
{
auto cmdline{mu_format("/bin/sh -c '{} {}'", MU_PROGRAM, args)};
if (g_test_verbose())
mu_println("command-line: {}", cmdline);
GError *err{};
int wait_status{};
if (!g_spawn_command_line_sync(cmdline.c_str(), {}, {}, &wait_status, &err))
return Err(Error::Code::File, &err, "failed to execute command '{}", cmdline);
else
return Ok(WEXITSTATUS(wait_status));
}
Mu::TempDir::TempDir(bool autodelete): autodelete_{autodelete} {
if (auto res{make_temp_dir()}; !res)