-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Allow processes to be started on start/stop of a session. #2138
base: master
Are you sure you want to change the base?
Conversation
I have some points I'd like to discuss here:
|
#include <boost/process.hpp> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed
boost::process::environment env; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unused, remove?
std::error_code ec; | ||
std::vector<cmd_t>::const_iterator prep_it = std::end(config::sunshine.prep_cmds); | ||
for (; prep_it != std::begin(config::sunshine.prep_cmds); --prep_it) { | ||
auto &cmd = *(prep_it - 1); | ||
|
||
// Skip empty and non session commands | ||
if (cmd.undo_cmd.empty() || !cmd.on_session) { | ||
continue; | ||
} | ||
|
||
boost::filesystem::path working_dir = find_working_directory(cmd.do_cmd); | ||
BOOST_LOG(info) << "Executing Undo Cmd: ["sv << cmd.undo_cmd << ']'; | ||
auto child = platf::run_command(cmd.elevated, true, cmd.undo_cmd, working_dir, session.env, nullptr, ec, nullptr); | ||
|
||
if (ec) { | ||
BOOST_LOG(warning) << "Couldn't run ["sv << cmd.undo_cmd << "]: "sv << ec.message(); | ||
} | ||
|
||
child.wait(); | ||
auto ret = child.exit_code(); | ||
|
||
if (ret != 0) { | ||
BOOST_LOG(warning) << '[' << cmd.undo_cmd << "] failed with code ["sv << ret << ']'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This files looks awfully big already and this feels out of place, can we move this to another file, maybe reuse some of it in process too?
I'd suggest moving this to something like: user_commands::run_session_stop()
and call it here
std::error_code ec; | ||
std::vector<cmd_t>::const_iterator prep_it = std::begin(config::sunshine.prep_cmds); | ||
for (; prep_it != std::end(config::sunshine.prep_cmds); ++prep_it) { | ||
auto &cmd = *prep_it; | ||
|
||
// Skip empty and non session commands | ||
if (cmd.do_cmd.empty() || !cmd.on_session) { | ||
continue; | ||
} | ||
|
||
boost::filesystem::path working_dir = find_working_directory(cmd.do_cmd); | ||
BOOST_LOG(info) << "Executing Do Cmd: ["sv << cmd.do_cmd << ']'; | ||
auto child = platf::run_command(cmd.elevated, true, cmd.do_cmd, working_dir, session.env, nullptr, ec, nullptr); | ||
|
||
if (ec) { | ||
BOOST_LOG(error) << "Couldn't run ["sv << cmd.do_cmd << "]: System: "sv << ec.message(); | ||
return -1; | ||
} | ||
|
||
child.wait(); | ||
auto ret = child.exit_code(); | ||
if (ret != 0) { | ||
BOOST_LOG(error) << '[' << cmd.do_cmd << "] failed with code ["sv << ret << ']'; | ||
return -1; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest moving this to something like: user_commands::run_session_start()
and call it here
boost::filesystem::path | ||
find_working_directory(const std::string &cmd) { | ||
// Parse the raw command string into parts to get the actual command portion | ||
#ifdef _WIN32 | ||
auto parts = boost::program_options::split_winmain(cmd); | ||
#else | ||
auto parts = boost::program_options::split_unix(cmd); | ||
#endif | ||
if (parts.empty()) { | ||
BOOST_LOG(error) << "Unable to parse command: "sv << cmd; | ||
return boost::filesystem::path(); | ||
} | ||
|
||
BOOST_LOG(debug) << "Parsed executable ["sv << parts.at(0) << "] from command ["sv << cmd << ']'; | ||
|
||
// If the cmd path is not an absolute path, resolve it using our PATH variable | ||
boost::filesystem::path cmd_path(parts.at(0)); | ||
if (!cmd_path.is_absolute()) { | ||
cmd_path = boost::process::search_path(parts.at(0)); | ||
if (cmd_path.empty()) { | ||
BOOST_LOG(error) << "Unable to find executable ["sv << parts.at(0) << "]. Is it in your PATH?"sv; | ||
return boost::filesystem::path(); | ||
} | ||
} | ||
|
||
BOOST_LOG(debug) << "Resolved executable ["sv << parts.at(0) << "] to path ["sv << cmd_path << ']'; | ||
|
||
// Now that we have a complete path, we can just use parent_path() | ||
return cmd_path.parent_path(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest moving this to user_commands
@@ -109,7 +109,7 @@ namespace proc { | |||
} | |||
|
|||
boost::filesystem::path | |||
find_working_directory(const std::string &cmd, bp::environment &env) { | |||
find_working_directory(const std::string &cmd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be merged with the other method with the same name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to the same user_commands
if something like this gets created?
Description
Allows for processes to be started when a client connects, resumes an app or disconnects from an app.
Added new session envs.
SUNSHINE_CLIENT_ID - Not sure how useful this one is with how it's used right now.
SUNSHINE_CLIENT_UNIQUE_ID
SUNSHINE_CLIENT_SLOT - Can only be used when set to session.
I'm open to suggests for the header text for the config as I don't know if users will know what it means by Session.
Issues:
SUNSHINE_APP_ID
andSUNSHINE_APP_NAME
can't be used when the process is set to session.Screenshot
Issues Fixed or Closed
Type of Change
.github/...
)Checklist
Branch Updates
LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.