Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(process): refactor away the bugs and race conditions in proc_t #3604

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ namespace confighttp {
});

file_handler::write_file(config::stream.file_apps.c_str(), file_tree.dump(4));
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

output_tree["status"] = true;
send_response(response, output_tree);
Expand Down Expand Up @@ -656,7 +656,7 @@ namespace confighttp {
file_tree["apps"] = new_apps;

file_handler::write_file(config::stream.file_apps.c_str(), file_tree.dump(4));
proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

output_tree["status"] = true;
output_tree["result"] = "application " + std::to_string(index) + " deleted";
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) {
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
#endif

proc::refresh(config::stream.file_apps);
proc::proc.refresh(config::stream.file_apps);

// If any of the following fail, we log an error and continue event though sunshine will not function correctly.
// This allows access to the UI to fix configuration problems or view the logs.
Expand Down
22 changes: 8 additions & 14 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,10 @@ namespace nvhttp {
}
tree.put("root.ServerCodecModeSupport", codec_mode_flags);

auto current_appid = proc::proc.running();
auto current_appid = proc::proc.get_running_app_id();
tree.put("root.PairStatus", pair_status);
tree.put("root.currentgame", current_appid);
tree.put("root.state", current_appid > 0 ? "SUNSHINE_SERVER_BUSY" : "SUNSHINE_SERVER_FREE");
tree.put("root.currentgame", current_appid.value_or(0));
tree.put("root.state", current_appid ? "SUNSHINE_SERVER_BUSY" : "SUNSHINE_SERVER_FREE");

std::ostringstream data;

Expand Down Expand Up @@ -837,10 +837,7 @@ namespace nvhttp {
return;
}

auto appid = util::from_view(get_arg(args, "appid"));

auto current_appid = proc::proc.running();
if (current_appid > 0) {
if (proc::proc.get_running_app_id()) {
tree.put("root.resume", 0);
tree.put("root.<xmlattr>.status_code", 400);
tree.put("root.<xmlattr>.status_message", "An app is already running on this host");
Expand Down Expand Up @@ -884,6 +881,7 @@ namespace nvhttp {
return;
}

auto appid = util::from_view(get_arg(args, "appid"));
if (appid > 0) {
auto err = proc::proc.execute(appid, launch_session);
if (err) {
Expand Down Expand Up @@ -917,8 +915,7 @@ namespace nvhttp {
response->close_connection_after_response = true;
});

auto current_appid = proc::proc.running();
if (current_appid == 0) {
if (!proc::proc.get_running_app_id()) {
tree.put("root.resume", 0);
tree.put("root.<xmlattr>.status_code", 503);
tree.put("root.<xmlattr>.status_message", "No running app to resume");
Expand Down Expand Up @@ -1000,12 +997,9 @@ namespace nvhttp {
tree.put("root.<xmlattr>.status_code", 200);

rtsp_stream::terminate_sessions();
proc::proc.terminate();

if (proc::proc.running() > 0) {
proc::proc.terminate();
}

// The config needs to be reverted regardless of whether "proc::proc.terminate()" was called or not.
// The config needs to be reverted regardless of whether "proc::proc.terminate()" actually terminated app or not.
display_device::revert_configuration();
}

Expand Down
Loading
Loading