Broken
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 20s

This commit is contained in:
Your Name 2025-05-10 14:27:24 +12:00
parent 5973d63d3e
commit 34f2763ef4
2 changed files with 9 additions and 4 deletions

View File

@ -122,7 +122,12 @@ int ssh_interactive_shell_session(ssh_session session, ssh_channel channel, cons
return 0; return 0;
} }
int ssh_exec_command(ssh_session session, ssh_channel channel, const std::string& remote_cmd_str, bool silent, std::string* output) { int ssh_exec_command(ssh_session session, ssh_channel channel, const std::string& remote_cmd_str, bool silent, std::string* output, const std::map<std::string, std::string>& env) {
// Set environment variables using ssh_channel_request_env
for (const auto& kv : env) {
if (kv.first == "SSHPASS") continue;
ssh_channel_request_env(channel, kv.first.c_str(), kv.second.c_str());
}
int rc = ssh_channel_request_exec(channel, remote_cmd_str.c_str()); int rc = ssh_channel_request_exec(channel, remote_cmd_str.c_str());
if (rc != SSH_OK) { if (rc != SSH_OK) {
if (output) *output = std::string("Failed to exec remote command: ") + ssh_get_error(session); if (output) *output = std::string("Failed to exec remote command: ") + ssh_get_error(session);
@ -255,12 +260,12 @@ int execute_cmd(
ssh_free(session); ssh_free(session);
return -1; return -1;
} }
std::string remote_cmd_str = ssh_build_remote_command(command, args, working_dir, env); std::string remote_cmd_str = ssh_build_remote_command(command, args, working_dir, {}); // Don't prefix env
int ret = 0; int ret = 0;
if (interactive) { if (interactive) {
ret = ssh_interactive_shell_session(session, channel, remote_cmd_str, command, output); ret = ssh_interactive_shell_session(session, channel, remote_cmd_str, command, output);
} else { } else {
ret = ssh_exec_command(session, channel, remote_cmd_str, silent, output); ret = ssh_exec_command(session, channel, remote_cmd_str, silent, output, env);
} }
ssh_channel_send_eof(channel); ssh_channel_send_eof(channel);
ssh_channel_close(channel); ssh_channel_close(channel);

View File

@ -79,7 +79,7 @@ void test_docker() {
void test_ssh() { void test_ssh() {
std::string command = "bash"; std::string command = "bash";
std::vector<std::string> args = {"-c", "ls -l && echo $WHATSUP"}; std::vector<std::string> args = {"-c", "ls -l && echo \"$WHATSUP\""};
std::string working_dir = "/home"; std::string working_dir = "/home";
std::map<std::string, std::string> env = {{"WHATSUP", "Waaaaattttsssuuuppppp!"}}; std::map<std::string, std::string> env = {{"WHATSUP", "Waaaaattttsssuuuppppp!"}};
bool silent = false; bool silent = false;