feat: add support to specifying start_dir to processes

This commit is contained in:
Felipe Cavalcanti 2021-08-24 15:23:47 -03:00
parent 7a920da06d
commit f38bbf90bb
3 changed files with 35 additions and 8 deletions

View File

@ -150,6 +150,22 @@
that sleeps indefinitely
</div>
</div>
<!--starting dir-->
<div class="mb-3">
<label for="appStartingDir" class="form-label">Starting Dir</label>
<input
type="text"
class="form-control monospace"
id="appStartindDir"
aria-describedby="appStartindDirHelp"
v-model="editForm.startingDir"
/>
<div id="appStartindDirHelp" class="form-text">
The starting dir that should be passed to the process.
Some apps needs this set to find configuration files for example.
If not set, will default to the parent directory of the command
</div>
</div>
<!--buttons-->
<div class="d-flex">
<button @click="showEditForm = false" class="btn btn-secondary m-2">

View File

@ -11,6 +11,7 @@
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/filesystem.hpp>
#include "main.h"
#include "utility.h"
@ -109,14 +110,17 @@ int proc_t::execute(int app_id) {
if(proc.cmd.empty()) {
BOOST_LOG(debug) << "Executing [Desktop]"sv;
placebo = true;
}
else if(proc.output.empty() || proc.output == "null"sv) {
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
_process = bp::child(_process_handle, proc.cmd, _env, bp::std_out > bp::null, bp::std_err > bp::null, ec);
}
else {
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
_process = bp::child(_process_handle, proc.cmd, _env, bp::std_out > _pipe.get(), bp::std_err > _pipe.get(), ec);
} else {
boost::filesystem::path start_dir = proc.starting_dir.empty() ?
boost::filesystem::path(proc.cmd).parent_path() : boost::filesystem::path(proc.starting_dir);
if(proc.output.empty() || proc.output == "null"sv) {
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
_process = bp::child(_process_handle, proc.cmd, _env, bp::start_dir(start_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
}
else {
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
_process = bp::child(_process_handle, proc.cmd, _env, bp::start_dir(start_dir), bp::std_out > _pipe.get(), bp::std_err > _pipe.get(), ec);
}
}
if(ec) {
@ -275,6 +279,7 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
auto output = app_node.get_optional<std::string>("output"s);
auto name = parse_env_val(this_env, app_node.get<std::string>("name"s));
auto cmd = app_node.get_optional<std::string>("cmd"s);
auto starting_dir = app_node.get_optional<std::string>("startingDir"s);
std::vector<proc::cmd_t> prep_cmds;
if(prep_nodes_opt) {
@ -312,6 +317,10 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
ctx.cmd = parse_env_val(this_env, *cmd);
}
if(starting_dir) {
ctx.starting_dir = parse_env_val(this_env, *starting_dir);
}
ctx.name = std::move(name);
ctx.prep_cmds = std::move(prep_cmds);
ctx.detached = std::move(detached);

View File

@ -34,6 +34,7 @@ struct cmd_t {
* cmd -- Runs indefinitely until:
* No session is running and a different set of commands it to be executed
* Command exits
* starting_dir -- the process starting dir. This is required for some games to run properly.
* cmd_output --
* empty -- The output of the commands are appended to the output of sunshine
* "null" -- The output of the commands are discarded
@ -52,6 +53,7 @@ struct ctx_t {
std::string name;
std::string cmd;
std::string starting_dir;
std::string output;
};