fix cd bug in ds_run, and fix ds ssh so it doesnt hang process
This commit is contained in:
@@ -86,5 +86,4 @@ fi
|
||||
[[ -f "${COMMAND_TO_RUN}" ]] || _die "Command not found: ${DSCOMMAND} (looked for ${TEMPLATE_PATH}/${DSCOMMAND}[.sh])"
|
||||
|
||||
# -- Execute the command with any remaining arguments --
|
||||
cd "${TEMPLATE_PATH}"
|
||||
exec bash cd "${COMMAND_PATH}" && "${COMMAND_TO_RUN}" "$@"
|
||||
cd "${COMMAND_PATH}" && exec "${COMMAND_TO_RUN}" "$@"
|
||||
|
||||
@@ -54,7 +54,8 @@ namespace dropshell
|
||||
|
||||
info << "SSHing into " << server << ":" << remote_path << " as user " << user << std::endl;
|
||||
|
||||
execute_ssh_command(server_env.get_SSH_INFO(user), sCommand(remote_path, bash_cmd, env_vars), cMode::Interactive);
|
||||
// Use ReplaceProcess so dropshell exits and ssh takes over completely
|
||||
execute_ssh_command(server_env.get_SSH_INFO(user), sCommand(remote_path, bash_cmd, env_vars), cMode::Interactive | cMode::ReplaceProcess);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,23 @@ namespace dropshell
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_local_command_replace - replaces current process with the command (never returns on success)
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
bool execute_local_command_replace(const std::string &full_command)
|
||||
{
|
||||
if (full_command.empty())
|
||||
return false;
|
||||
|
||||
// Use exec to replace the current process with a shell running the command
|
||||
// This means dropshell exits immediately and ssh (or whatever) takes over
|
||||
execlp("/bin/bash", "bash", "-c", full_command.c_str(), nullptr);
|
||||
|
||||
// If we get here, exec failed
|
||||
perror("exec failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_local_command
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
@@ -117,6 +134,18 @@ namespace dropshell
|
||||
{
|
||||
sCommand command(directory_to_run_in, command_to_run, env_vars);
|
||||
|
||||
if (hasFlag(mode, cMode::ReplaceProcess))
|
||||
{
|
||||
ASSERT(output == nullptr, "ReplaceProcess mode and an output string cannot be used together");
|
||||
// For ReplaceProcess, run the command directly without bb64 wrapping
|
||||
// (the caller is responsible for constructing the full command)
|
||||
std::string full_cmd = command_to_run;
|
||||
if (!directory_to_run_in.empty())
|
||||
full_cmd = "cd " + quote(directory_to_run_in) + " && " + full_cmd;
|
||||
return execute_local_command_replace(full_cmd);
|
||||
// Note: execute_local_command_replace never returns on success
|
||||
}
|
||||
|
||||
if (hasFlag(mode, cMode::Interactive))
|
||||
{
|
||||
ASSERT(output == nullptr, "Interactive mode and an output string cannot be used together");
|
||||
|
||||
@@ -14,7 +14,8 @@ enum class cMode {
|
||||
Defaults = 0,
|
||||
Interactive = 1,
|
||||
Silent = 2,
|
||||
NoBB64 = 4
|
||||
NoBB64 = 4,
|
||||
ReplaceProcess = 8 // Use exec to replace current process (dropshell exits immediately)
|
||||
};
|
||||
|
||||
inline cMode operator&(cMode lhs, cMode rhs) {return static_cast<cMode>(static_cast<int>(lhs) & static_cast<int>(rhs));}
|
||||
|
||||
Reference in New Issue
Block a user