This commit is contained in:
parent
e85aa5c81b
commit
a6cac3a426
@ -121,7 +121,7 @@ sCommand server_env_manager::construct_standard_template_run_cmd(const std::stri
|
||||
argstr += " " + quote(dequote(trim(arg)));
|
||||
}
|
||||
|
||||
std::vector<std::string> cmd = {"bash", script_path};
|
||||
std::vector<std::string> cmd = {script_path};
|
||||
cmd.insert(cmd.end(), args.begin(), args.end());
|
||||
sCommand scommand(remote_service_template_path, cmd, env_vars);
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "contrib/base64.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include <termios.h>
|
||||
|
||||
bool EXITSTATUSCHECK(int ret) {
|
||||
return (ret != -1 && WIFEXITED(ret) && (WEXITSTATUS(ret) == 0)); // ret is -1 if the command failed to execute.
|
||||
@ -20,6 +21,17 @@ bool EXITSTATUSCHECK(int ret) {
|
||||
namespace dropshell {
|
||||
bool __execute_command(std::vector<std::string> command, std::string * output)
|
||||
{
|
||||
// Save TTY state if possible
|
||||
struct termios orig_termios;
|
||||
int tty_fd = isatty(STDIN_FILENO) ? STDIN_FILENO : -1;
|
||||
if (tty_fd != -1) {
|
||||
tcgetattr(tty_fd, &orig_termios);
|
||||
}
|
||||
|
||||
std::cout << "Executing command: ";
|
||||
for (auto & x : command) std::cout << "[" << x << "] ";
|
||||
std::cout << std::endl << std::flush;
|
||||
|
||||
int pipefd[2];
|
||||
bool capture = (output != nullptr);
|
||||
if (capture && pipe(pipefd) == -1) {
|
||||
@ -73,6 +85,11 @@ bool __execute_command(std::vector<std::string> command, std::string * output)
|
||||
// Wait for the child process to complete
|
||||
waitpid(pid, &ret, 0);
|
||||
|
||||
// Restore TTY state if possible
|
||||
if (tty_fd != -1) {
|
||||
tcsetattr(tty_fd, TCSANOW, &orig_termios);
|
||||
}
|
||||
|
||||
return EXITSTATUSCHECK(ret);
|
||||
}
|
||||
}
|
||||
@ -86,14 +103,19 @@ bool execute_command(const sSSHInfo * ssh_info, const sCommand command, cMode mo
|
||||
|
||||
if (ssh_info)
|
||||
{
|
||||
std::vector<std::string> ssh_command = {"/usr/bin/ssh", "-p", ssh_info->port, "-tt", ssh_info->user, "@", ssh_info->host};
|
||||
std::vector<std::string> ssh_command = {"/usr/bin/ssh", "-p", ssh_info->port, "-tt", ssh_info->user + "@" + ssh_info->host};
|
||||
commandvec.insert(commandvec.end(), ssh_command.begin(), ssh_command.end());
|
||||
}
|
||||
|
||||
commandvec.push_back("bash");
|
||||
commandvec.push_back("-c");
|
||||
|
||||
commandvec.insert(commandvec.end(), command.get_command_to_run().begin(), command.get_command_to_run().end());
|
||||
std::string shell_command = "";
|
||||
for (auto & x : command.get_command_to_run()) {
|
||||
shell_command += x + " ";
|
||||
}
|
||||
shell_command = shell_command.substr(0, shell_command.size() - 1);
|
||||
commandvec.push_back(shell_command);
|
||||
|
||||
|
||||
if (hasFlag(mode, cMode::CaptureOutput)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user