Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ using namespace std::literals;

namespace nvhttp {

static constexpr std::string_view EMPTY_PROPERTY_TREE_ERROR_MSG = "Property tree is empty. Probably, control flow got interrupted by an unexpected C++ exception. This is a bug in Sunshine. Moonlight-qt will report Malformed XML (missing root element)."sv;

namespace fs = std::filesystem;
namespace pt = boost::property_tree;

Expand Down Expand Up @@ -816,6 +818,10 @@ namespace nvhttp {
auto g = util::fail_guard([&]() {
std::ostringstream data;

if (tree.empty()) {
BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG;
}

pt::write_xml(data, tree);
response->write(data.str());
response->close_connection_after_response = true;
Expand Down Expand Up @@ -922,6 +928,10 @@ namespace nvhttp {
auto g = util::fail_guard([&]() {
std::ostringstream data;

if (tree.empty()) {
BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG;
}

pt::write_xml(data, tree);
response->write(data.str());
response->close_connection_after_response = true;
Expand Down
21 changes: 16 additions & 5 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <boost/program_options/parsers.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/token_functions.hpp>
#include <openssl/evp.h>
#include <openssl/sha.h>

Expand Down Expand Up @@ -97,11 +98,17 @@ namespace proc {

boost::filesystem::path find_working_directory(const std::string &cmd, boost::process::v1::environment &env) {
// Parse the raw command string into parts to get the actual command portion
std::vector<std::string> parts;
try {
#ifdef _WIN32
auto parts = boost::program_options::split_winmain(cmd);
parts = boost::program_options::split_winmain(cmd);
#else
auto parts = boost::program_options::split_unix(cmd);
parts = boost::program_options::split_unix(cmd);
#endif
} catch (boost::escaped_list_error &err) {
BOOST_LOG(error) << "Boost failed to parse command ["sv << cmd << "] because " << err.what();
return boost::filesystem::path();
}
if (parts.empty()) {
BOOST_LOG(error) << "Unable to parse command: "sv << cmd;
return boost::filesystem::path();
Expand Down Expand Up @@ -217,10 +224,14 @@ namespace proc {
}
}

child.wait();
child.wait(ec);
if (ec) {
BOOST_LOG(error) << '[' << cmd.do_cmd << "] wait failed with error code ["sv << ec << ']';
return -1;
}
auto ret = child.exit_code();
if (ret != 0 && ec != std::errc::permission_denied) {
BOOST_LOG(error) << '[' << cmd.do_cmd << "] failed with code ["sv << ret << ']';
if (ret != 0) {
BOOST_LOG(error) << '[' << cmd.do_cmd << "] exited with code ["sv << ret << ']';
return -1;
}
}
Expand Down
Loading