fix cd bug in ds_run, and fix ds ssh so it doesnt hang process
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 48s
Build-Test-Publish / build (linux/arm64) (push) Successful in 3m10s

This commit is contained in:
j
2026-01-02 22:02:46 +13:00
parent b20bf7476c
commit 767692160d
4 changed files with 34 additions and 4 deletions

View File

@@ -86,5 +86,4 @@ fi
[[ -f "${COMMAND_TO_RUN}" ]] || _die "Command not found: ${DSCOMMAND} (looked for ${TEMPLATE_PATH}/${DSCOMMAND}[.sh])" [[ -f "${COMMAND_TO_RUN}" ]] || _die "Command not found: ${DSCOMMAND} (looked for ${TEMPLATE_PATH}/${DSCOMMAND}[.sh])"
# -- Execute the command with any remaining arguments -- # -- Execute the command with any remaining arguments --
cd "${TEMPLATE_PATH}" cd "${COMMAND_PATH}" && exec "${COMMAND_TO_RUN}" "$@"
exec bash cd "${COMMAND_PATH}" && "${COMMAND_TO_RUN}" "$@"

View File

@@ -54,7 +54,8 @@ namespace dropshell
info << "SSHing into " << server << ":" << remote_path << " as user " << user << std::endl; 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; return true;
} }

View File

@@ -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 // execute_local_command
// ---------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------
@@ -117,6 +134,18 @@ namespace dropshell
{ {
sCommand command(directory_to_run_in, command_to_run, env_vars); 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)) if (hasFlag(mode, cMode::Interactive))
{ {
ASSERT(output == nullptr, "Interactive mode and an output string cannot be used together"); ASSERT(output == nullptr, "Interactive mode and an output string cannot be used together");

View File

@@ -14,7 +14,8 @@ enum class cMode {
Defaults = 0, Defaults = 0,
Interactive = 1, Interactive = 1,
Silent = 2, 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));} inline cMode operator&(cMode lhs, cMode rhs) {return static_cast<cMode>(static_cast<int>(lhs) & static_cast<int>(rhs));}