mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-02 18:13:51 +00:00
fix(flatpak): remove need to prefix commands (#5723)
This commit is contained in:
1 parent
63d35f702e
commit
1cca880503
5 files changed
+62
-24
No files matched your search
+38
-17
@@ -149,6 +149,23 @@ namespace proc {
|
||||
return cmd_path.parent_path();
|
||||
}
|
||||
|
||||
std::string prepare_command(const std::string &command) {
|
||||
#ifdef SUNSHINE_BUILD_FLATPAK
|
||||
constexpr auto host_command_prefix = "flatpak-spawn --host "sv;
|
||||
const auto stripped_command = boost::trim_copy(command);
|
||||
if (stripped_command.empty() || stripped_command.starts_with(host_command_prefix)) {
|
||||
if (!stripped_command.empty()) {
|
||||
BOOST_LOG(warning) << "Command ["sv << stripped_command << "] already includes [flatpak-spawn --host], which is no longer required for Flatpak builds."sv;
|
||||
}
|
||||
return stripped_command;
|
||||
}
|
||||
|
||||
return std::string {host_command_prefix} + stripped_command;
|
||||
#else
|
||||
return command;
|
||||
#endif
|
||||
}
|
||||
|
||||
int proc_t::execute(int app_id, std::shared_ptr<rtsp_stream::launch_session_t> launch_session) {
|
||||
// Ensure starting from a clean slate
|
||||
terminate();
|
||||
@@ -221,14 +238,15 @@ namespace proc {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto command = prepare_command(cmd.do_cmd);
|
||||
boost::filesystem::path working_dir = _app.working_dir.empty() ?
|
||||
find_working_directory(cmd.do_cmd, _env) :
|
||||
find_working_directory(command, _env) :
|
||||
boost::filesystem::path(_app.working_dir);
|
||||
BOOST_LOG(info) << "Executing Do Cmd: ["sv << cmd.do_cmd << ']';
|
||||
auto child = platf::run_command(cmd.elevated, true, cmd.do_cmd, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
BOOST_LOG(info) << "Executing Do Cmd: ["sv << command << ']';
|
||||
auto child = platf::run_command(cmd.elevated, true, command, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
|
||||
if (ec) {
|
||||
BOOST_LOG(error) << "Couldn't run ["sv << cmd.do_cmd << "]: System: "sv << ec.message();
|
||||
BOOST_LOG(error) << "Couldn't run ["sv << command << "]: System: "sv << ec.message();
|
||||
// We don't want any prep commands failing launch of the desktop.
|
||||
// This is to prevent the issue where users reboot their PC and need to log in with Sunshine.
|
||||
// permission_denied is typically returned when the user impersonation fails, which can happen when user is not signed in yet.
|
||||
@@ -239,24 +257,25 @@ namespace proc {
|
||||
|
||||
child.wait(ec);
|
||||
if (ec) {
|
||||
BOOST_LOG(error) << '[' << cmd.do_cmd << "] wait failed with error code ["sv << ec << ']';
|
||||
BOOST_LOG(error) << '[' << command << "] wait failed with error code ["sv << ec << ']';
|
||||
return -1;
|
||||
}
|
||||
auto ret = child.exit_code();
|
||||
if (ret != 0) {
|
||||
BOOST_LOG(error) << '[' << cmd.do_cmd << "] exited with code ["sv << ret << ']';
|
||||
BOOST_LOG(error) << '[' << command << "] exited with code ["sv << ret << ']';
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &cmd : _app.detached) {
|
||||
const auto command = prepare_command(cmd);
|
||||
boost::filesystem::path working_dir = _app.working_dir.empty() ?
|
||||
find_working_directory(cmd, _env) :
|
||||
find_working_directory(command, _env) :
|
||||
boost::filesystem::path(_app.working_dir);
|
||||
BOOST_LOG(info) << "Spawning ["sv << cmd << "] in ["sv << working_dir << ']';
|
||||
auto child = platf::run_command(_app.elevated, true, cmd, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
BOOST_LOG(info) << "Spawning ["sv << command << "] in ["sv << working_dir << ']';
|
||||
auto child = platf::run_command(_app.elevated, true, command, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
if (ec) {
|
||||
BOOST_LOG(warning) << "Couldn't spawn ["sv << cmd << "]: System: "sv << ec.message();
|
||||
BOOST_LOG(warning) << "Couldn't spawn ["sv << command << "]: System: "sv << ec.message();
|
||||
} else {
|
||||
child.detach();
|
||||
}
|
||||
@@ -266,13 +285,14 @@ namespace proc {
|
||||
BOOST_LOG(info) << "Executing [Desktop]"sv;
|
||||
placebo = true;
|
||||
} else {
|
||||
const auto command = prepare_command(_app.cmd);
|
||||
boost::filesystem::path working_dir = _app.working_dir.empty() ?
|
||||
find_working_directory(_app.cmd, _env) :
|
||||
find_working_directory(command, _env) :
|
||||
boost::filesystem::path(_app.working_dir);
|
||||
BOOST_LOG(info) << "Executing: ["sv << _app.cmd << "] in ["sv << working_dir << ']';
|
||||
_process = platf::run_command(_app.elevated, true, _app.cmd, working_dir, _env, _pipe.get(), ec, &_process_group);
|
||||
BOOST_LOG(info) << "Executing: ["sv << command << "] in ["sv << working_dir << ']';
|
||||
_process = platf::run_command(_app.elevated, true, command, working_dir, _env, _pipe.get(), ec, &_process_group);
|
||||
if (ec) {
|
||||
BOOST_LOG(warning) << "Couldn't run ["sv << _app.cmd << "]: System: "sv << ec.message();
|
||||
BOOST_LOG(warning) << "Couldn't run ["sv << command << "]: System: "sv << ec.message();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -334,11 +354,12 @@ namespace proc {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto command = prepare_command(cmd.undo_cmd);
|
||||
boost::filesystem::path working_dir = _app.working_dir.empty() ?
|
||||
find_working_directory(cmd.undo_cmd, _env) :
|
||||
find_working_directory(command, _env) :
|
||||
boost::filesystem::path(_app.working_dir);
|
||||
BOOST_LOG(info) << "Executing Undo Cmd: ["sv << cmd.undo_cmd << ']';
|
||||
auto child = platf::run_command(cmd.elevated, true, cmd.undo_cmd, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
BOOST_LOG(info) << "Executing Undo Cmd: ["sv << command << ']';
|
||||
auto child = platf::run_command(cmd.elevated, true, command, working_dir, _env, _pipe.get(), ec, nullptr);
|
||||
|
||||
if (ec) {
|
||||
BOOST_LOG(warning) << "System: "sv << ec.message();
|
||||
|
||||
Reference in new issue
Block a user