From a6cac3a4261e18f0e1bf5fed022221156d57b5a8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 10 May 2025 11:02:56 +1200 Subject: [PATCH] . --- src/server_env_manager.cpp | 2 +- src/utils/execute.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/server_env_manager.cpp b/src/server_env_manager.cpp index 5df415d..89902f7 100644 --- a/src/server_env_manager.cpp +++ b/src/server_env_manager.cpp @@ -121,7 +121,7 @@ sCommand server_env_manager::construct_standard_template_run_cmd(const std::stri argstr += " " + quote(dequote(trim(arg))); } - std::vector cmd = {"bash", script_path}; + std::vector cmd = {script_path}; cmd.insert(cmd.end(), args.begin(), args.end()); sCommand scommand(remote_service_template_path, cmd, env_vars); diff --git a/src/utils/execute.cpp b/src/utils/execute.cpp index ddd109e..0154269 100644 --- a/src/utils/execute.cpp +++ b/src/utils/execute.cpp @@ -12,6 +12,7 @@ #include "contrib/base64.hpp" #include "utils/utils.hpp" #include "utils/directories.hpp" +#include 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 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 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 ssh_command = {"/usr/bin/ssh", "-p", ssh_info->port, "-tt", ssh_info->user, "@", ssh_info->host}; + std::vector 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)) {