Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/platform/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class path;
}
namespace process {
class child;
class group;
template<typename Char>
class basic_environment;
typedef basic_environment<char> environment;
Expand Down Expand Up @@ -311,7 +312,7 @@ std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &
// A list of names of displays accepted as display_name with the mem_type_e
std::vector<std::string> display_names(mem_type_e hwdevice_type);

boost::process::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, boost::process::environment &env, FILE *file, std::error_code &ec);
boost::process::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, boost::process::environment &env, FILE *file, std::error_code &ec, boost::process::group &group);

enum class thread_priority_e : int {
low,
Expand Down
6 changes: 3 additions & 3 deletions src/platform/linux/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ std::string get_mac_address(const std::string_view &address) {
return "00:00:00:00:00:00"s;
}

bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec) {
bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec, bp::group &group) {
BOOST_LOG(warning) << "run_unprivileged() is not yet implemented for this platform. The new process will run with Sunshine's permissions."sv;
if(!file) {
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec, group);
}
else {
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec);
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec, group);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/platform/macos/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ std::string get_mac_address(const std::string_view &address) {
return "00:00:00:00:00:00"s;
}

bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec) {
bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec, bp::group &group) {
BOOST_LOG(warning) << "run_unprivileged() is not yet implemented for this platform. The new process will run with Sunshine's permissions."sv;
if(!file) {
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec, group);
}
else {
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec);
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec, group);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/platform/windows/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void free_proc_thread_attr_list(LPPROC_THREAD_ATTRIBUTE_LIST list) {
HeapFree(GetProcessHeap(), 0, list);
}

bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec) {
bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &working_dir, bp::environment &env, FILE *file, std::error_code &ec, bp::group &group) {
HANDLE shell_token = duplicate_shell_token();
if(!shell_token) {
// This can happen if the shell has crashed. Fail the launch rather than risking launching with
Expand Down Expand Up @@ -459,7 +459,7 @@ bp::child run_unprivileged(const std::string &cmd, boost::filesystem::path &work
if(ret) {
// Since we are always spawning a process with a less privileged token than ourselves,
// bp::child() should have no problem opening it with any access rights it wants.
auto child = bp::child((bp::pid_t)process_info.dwProcessId);
auto child = bp::child((bp::pid_t)process_info.dwProcessId, group);

// Only close handles after bp::child() has opened the process. If the process terminates
// quickly, the PID could be reused if we close the process handle.
Expand Down
8 changes: 4 additions & 4 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ int proc_t::execute(int app_id) {
find_working_directory(cmd, _env) :
boost::filesystem::path(proc.working_dir);
BOOST_LOG(info) << "Spawning ["sv << cmd << "] in ["sv << working_dir << ']';
auto child = platf::run_unprivileged(cmd, working_dir, _env, _pipe.get(), ec);
bp::group child_group;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I don't really like this myself that there is a need to pass a temporary group, but I don't know how to do it optionally without creating 2 function versions. The boost::child constructor is just meh...

auto child = platf::run_unprivileged(cmd, working_dir, _env, _pipe.get(), ec, child_group);
if(ec) {
BOOST_LOG(warning) << "Couldn't spawn ["sv << cmd << "]: System: "sv << ec.message();
}
else {
child.detach();
child_group.detach();
}
}

Expand All @@ -168,13 +170,11 @@ int proc_t::execute(int app_id) {
find_working_directory(proc.cmd, _env) :
boost::filesystem::path(proc.working_dir);
BOOST_LOG(info) << "Executing: ["sv << proc.cmd << "] in ["sv << working_dir << ']';
_process = platf::run_unprivileged(proc.cmd, working_dir, _env, _pipe.get(), ec);
_process = platf::run_unprivileged(proc.cmd, working_dir, _env, _pipe.get(), ec, _process_handle);
if(ec) {
BOOST_LOG(warning) << "Couldn't run ["sv << proc.cmd << "]: System: "sv << ec.message();
return -1;
}

_process_handle.add(_process);
}

fg.disable();
Expand Down