fix(flatpak): remove need to prefix commands (#5723)

This commit is contained in:
Dave Lane authored and GitHub committed 2026-09-15 08:34:12 -04:00
1 parent 63d35f702e
commit 1cca880503
5 files changed
+62 -24

No files matched your search

-6
View File
@@ -345,12 +345,6 @@ third-party tool, you can use *QRes* as an example.
### Additional Considerations
#### Linux (Flatpak)
> [!CAUTION]
> Because Flatpak packages run in a sandboxed environment and do not normally have access to the
> host, the Flatpak of Sunshine requires commands to be prefixed with `flatpak-spawn --host`.
#### Windows
**Elevating Commands (Windows)**
-1
View File
@@ -725,7 +725,6 @@ All shortcuts start with `Ctrl+Alt+Shift`, just like Moonlight.
* The "Desktop" app works the same as any other application except it has no commands. It does not start an application,
instead it simply starts a stream. If you removed it and would like to get it back, just add a new application with
the name "Desktop" and "desktop.png" as the image path.
* For the Linux flatpak you must prepend commands with `flatpak-spawn --host`.
* If inputs (mouse, keyboard, gamepads...) aren't working after connecting:
* On FreeBSD/Linux, add the user running sunshine to the `input` group.
+38 -17
View File
@@ -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();
+8
View File
@@ -180,6 +180,14 @@ namespace proc {
*/
std::tuple<std::string, std::string> calculate_app_id(const std::string &app_name, std::string app_image_path, int index);
/**
* @brief Prepare a configured command for execution.
*
* @param command Configured command line.
* @return Command line with any package-specific launcher prefix applied.
*/
std::string prepare_command(const std::string &command);
bool check_valid_png(const std::filesystem::path &path);
/**
* @brief Validate app image path.
+16
View File
@@ -14,6 +14,22 @@
namespace fs = std::filesystem;
TEST(ProcessTest, PrepareCommand) {
#ifdef SUNSHINE_BUILD_FLATPAK
EXPECT_EQ(proc::prepare_command("steam"), "flatpak-spawn --host steam");
EXPECT_EQ(proc::prepare_command("flatpak-spawn --host steam"), "flatpak-spawn --host steam");
EXPECT_EQ(proc::prepare_command(" flatpak-spawn --host steam "), "flatpak-spawn --host steam");
EXPECT_EQ(proc::prepare_command(" steam "), "flatpak-spawn --host steam");
EXPECT_EQ(proc::prepare_command(""), "");
EXPECT_EQ(proc::prepare_command(" \t"), "");
#else
EXPECT_EQ(proc::prepare_command("steam"), "steam");
EXPECT_EQ(proc::prepare_command(" steam "), " steam ");
EXPECT_EQ(proc::prepare_command("flatpak-spawn --host steam"), "flatpak-spawn --host steam");
EXPECT_EQ(proc::prepare_command(""), "");
#endif
}
class ProcessPNGTest: public BaseTest {
protected:
void SetUp() override {