From 1c282142607d90a0e5661b8afb764137a43689d9 Mon Sep 17 00:00:00 2001 From: loki Date: Thu, 23 Jan 2020 19:32:16 +0100 Subject: [PATCH] Fix stream not starting properly on Windows when option "cmd" omitted in apps.json --- assets/apps_windows.json | 3 +-- sunshine/process.cpp | 13 +++++++------ sunshine/process.h | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/assets/apps_windows.json b/assets/apps_windows.json index 1ee37f50..512fd497 100644 --- a/assets/apps_windows.json +++ b/assets/apps_windows.json @@ -7,9 +7,8 @@ "name":"Steam BigPicture", "output":"steam.txt", - "cmd":"steam -tenfoot", "prep-cmd":[ - { "do":"steam -shutdown" } + {"do":"steam \"steam://open/bigpicture\""} ] } ] diff --git a/sunshine/process.cpp b/sunshine/process.cpp index 2ae6f045..c4058614 100644 --- a/sunshine/process.cpp +++ b/sunshine/process.cpp @@ -41,7 +41,7 @@ int exe(const std::string &cmd, bp::environment &env, file_t &file, std::error_c } int proc_t::execute(int app_id) { - if(!_process.running() && _app_id != -1) { + if(!running() && _app_id != -1) { // previous process exited on it's own, reset _process_handle _process_handle = bp::group(); @@ -91,7 +91,10 @@ int proc_t::execute(int app_id) { } BOOST_LOG(debug) << "Starting ["sv << proc.cmd << ']'; - if(proc.output.empty() || proc.output == "null"sv) { + if(proc.cmd.empty()) { + placebo = true; + } + else if(proc.output.empty() || proc.output == "null"sv) { _process = bp::child(_process_handle, proc.cmd, _env, bp::std_out > bp::null, bp::std_err > bp::null, ec); } else { @@ -109,7 +112,7 @@ int proc_t::execute(int app_id) { } int proc_t::running() { - if(_process.running()) { + if(placebo || _process.running()) { return _app_id; } @@ -120,6 +123,7 @@ void proc_t::terminate() { std::error_code ec; // Ensure child process is terminated + placebo = false; process_end(_process, _process_handle); _app_id = -1; @@ -265,9 +269,6 @@ std::optional parse(const std::string& file_name) { if(cmd) { ctx.cmd = parse_env_val(this_env, *cmd); } - else { - ctx.cmd = "sh -c \"while true; do sleep 10000; done;\""; - } ctx.name = std::move(name); ctx.prep_cmds = std::move(prep_cmds); diff --git a/sunshine/process.h b/sunshine/process.h index 0ee9cbe5..ad42ce2f 100644 --- a/sunshine/process.h +++ b/sunshine/process.h @@ -75,6 +75,9 @@ private: boost::process::environment _env; std::vector _apps; + // If no command associated with _app_id, yet it's still running + bool placebo {}; + boost::process::child _process; boost::process::group _process_handle;