Allow applications started by sunshine to be detached
This commit is contained in:
@@ -117,15 +117,20 @@ sunshine needs access to uinput to create mouse and gamepad events:
|
|||||||
"cmd":"command to open app",
|
"cmd":"command to open app",
|
||||||
"prep-cmd":[
|
"prep-cmd":[
|
||||||
{
|
{
|
||||||
"do":"somecommand",
|
"do":"some-command",
|
||||||
"undo":"undothatcommand"
|
"undo":"undo-that-command"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"detached":[
|
||||||
|
"some-command",
|
||||||
|
"another-command"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- name: Self explanatory
|
- name: Self explanatory
|
||||||
- output <optional>: The file where the output of the command is stored
|
- output <optional>: The file where the output of the command is stored
|
||||||
- If it is not specified, the output is ignored
|
- If it is not specified, the output is ignored
|
||||||
|
- detached: A list of commands to be run and forgotten about
|
||||||
- prep-cmd: A list of commands to be run before/after the application
|
- prep-cmd: A list of commands to be run before/after the application
|
||||||
- If any of the prep-commands fail, starting the application is aborted
|
- If any of the prep-commands fail, starting the application is aborted
|
||||||
- do: Run before the application
|
- do: Run before the application
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"name":"Steam BigPicture",
|
"name":"Steam BigPicture",
|
||||||
|
|
||||||
"output":"steam.txt",
|
"output":"steam.txt",
|
||||||
"cmd":"steam -bigpicture"
|
"detached":["setsid steam steam://open/bigpicture"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
"name":"Steam BigPicture",
|
"name":"Steam BigPicture",
|
||||||
|
|
||||||
"output":"steam.txt",
|
"output":"steam.txt",
|
||||||
"prep-cmd":[
|
"detached":["steam steam://open/bigpicture"]
|
||||||
{"do":"steam \"steam://open/bigpicture\""}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-5
@@ -80,17 +80,31 @@ int proc_t::execute(int app_id) {
|
|||||||
auto ret = exe(cmd, _env, _pipe, ec);
|
auto ret = exe(cmd, _env, _pipe, ec);
|
||||||
|
|
||||||
if(ec) {
|
if(ec) {
|
||||||
BOOST_LOG(error) << "System: "sv << ec.message();
|
BOOST_LOG(error) << "Couldn't run ["sv << cmd << "]: System: "sv << ec.message();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
BOOST_LOG(error) << "Return code ["sv << ret << ']';
|
BOOST_LOG(error) << '[' << cmd << "] failed with code ["sv << ret << ']';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG(debug) << "Starting ["sv << proc.cmd << ']';
|
for(auto &cmd : proc.detached) {
|
||||||
|
BOOST_LOG(info) << "Spawning ["sv << cmd << ']';
|
||||||
|
if(proc.output.empty()) {
|
||||||
|
bp::spawn(cmd, _env, bp::std_out > bp::null, bp::std_err > bp::null, ec);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bp::spawn(cmd, _env, bp::std_out > _pipe.get(), bp::std_err > _pipe.get(), ec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ec) {
|
||||||
|
BOOST_LOG(warning) << "Couldn't spawn ["sv << cmd << "]: System: "sv << ec.message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << ']';
|
||||||
if(proc.cmd.empty()) {
|
if(proc.cmd.empty()) {
|
||||||
placebo = true;
|
placebo = true;
|
||||||
}
|
}
|
||||||
@@ -102,7 +116,7 @@ int proc_t::execute(int app_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ec) {
|
if(ec) {
|
||||||
BOOST_LOG(info) << "System: "sv << ec.message();
|
BOOST_LOG(warning) << "Couldn't run ["sv << proc.cmd << "]: System: "sv << ec.message();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,12 +265,12 @@ std::optional<proc::proc_t> parse(const std::string& file_name) {
|
|||||||
proc::ctx_t ctx;
|
proc::ctx_t ctx;
|
||||||
|
|
||||||
auto prep_nodes_opt = app_node.get_child_optional("prep-cmd"s);
|
auto prep_nodes_opt = app_node.get_child_optional("prep-cmd"s);
|
||||||
|
auto detached_nodes_opt = app_node.get_child_optional("detached"s);
|
||||||
auto output = app_node.get_optional<std::string>("output"s);
|
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 name = parse_env_val(this_env, app_node.get<std::string>("name"s));
|
||||||
auto cmd = app_node.get_optional<std::string>("cmd"s);
|
auto cmd = app_node.get_optional<std::string>("cmd"s);
|
||||||
|
|
||||||
std::vector<proc::cmd_t> prep_cmds;
|
std::vector<proc::cmd_t> prep_cmds;
|
||||||
|
|
||||||
if(prep_nodes_opt) {
|
if(prep_nodes_opt) {
|
||||||
auto &prep_nodes = *prep_nodes_opt;
|
auto &prep_nodes = *prep_nodes_opt;
|
||||||
|
|
||||||
@@ -274,6 +288,16 @@ std::optional<proc::proc_t> parse(const std::string& file_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> detached;
|
||||||
|
if(detached_nodes_opt) {
|
||||||
|
auto &detached_nodes = *detached_nodes_opt;
|
||||||
|
|
||||||
|
detached.reserve(detached_nodes.size());
|
||||||
|
for(auto &[_, detached_val] : detached_nodes) {
|
||||||
|
detached.emplace_back(parse_env_val(this_env, detached_val.get_value<std::string>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(output) {
|
if(output) {
|
||||||
ctx.output = parse_env_val(this_env, *output);
|
ctx.output = parse_env_val(this_env, *output);
|
||||||
}
|
}
|
||||||
@@ -284,6 +308,7 @@ std::optional<proc::proc_t> parse(const std::string& file_name) {
|
|||||||
|
|
||||||
ctx.name = std::move(name);
|
ctx.name = std::move(name);
|
||||||
ctx.prep_cmds = std::move(prep_cmds);
|
ctx.prep_cmds = std::move(prep_cmds);
|
||||||
|
ctx.detached = std::move(detached);
|
||||||
|
|
||||||
apps.emplace_back(std::move(ctx));
|
apps.emplace_back(std::move(ctx));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ struct cmd_t {
|
|||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* pre_cmds -- guaranteed to be executed unless any of the commands fail.
|
* pre_cmds -- guaranteed to be executed unless any of the commands fail.
|
||||||
|
* detached -- commands detached from Sunshine
|
||||||
* cmd -- Runs indefinitely until:
|
* cmd -- Runs indefinitely until:
|
||||||
* No session is running and a different set of commands it to be executed
|
* No session is running and a different set of commands it to be executed
|
||||||
* Command exits
|
* Command exits
|
||||||
@@ -41,6 +42,14 @@ struct cmd_t {
|
|||||||
struct ctx_t {
|
struct ctx_t {
|
||||||
std::vector<cmd_t> prep_cmds;
|
std::vector<cmd_t> prep_cmds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some applications, such as Steam,
|
||||||
|
* either exit quickly, or keep running indefinitely.
|
||||||
|
* Steam.exe is one such application.
|
||||||
|
* That is why some applications need be run and forgotten about
|
||||||
|
*/
|
||||||
|
std::vector<std::string> detached;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string cmd;
|
std::string cmd;
|
||||||
std::string output;
|
std::string output;
|
||||||
|
|||||||
Reference in New Issue
Block a user