Skip to content

Commit

Permalink
Add noexit argument (MisterTea#566)
Browse files Browse the repository at this point in the history
When used in conjunction with --command it doesn't exit after
running the command.
  • Loading branch information
ml-1 authored Feb 23, 2023
1 parent fde8a7c commit 97b5956
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/terminal/TerminalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TerminalClient::~TerminalClient() {
connection.reset();
}

void TerminalClient::run(const string& command) {
void TerminalClient::run(const string& command, const bool noexit) {
if (console) {
console->setup();
}
Expand All @@ -157,7 +157,10 @@ void TerminalClient::run(const string& command) {
if (command.length()) {
LOG(INFO) << "Got command: " << command;
et::TerminalBuffer tb;
tb.set_buffer(command + "; exit\n");
if (noexit)
tb.set_buffer(command + "\n");
else
tb.set_buffer(command + "; exit\n");

connection->writePacket(
Packet(TerminalPacketType::TERMINAL_BUFFER, protoToString(tb)));
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/TerminalClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TerminalClient {
const string& reverseTunnels, bool forwardSshAgent,
const string& identityAgent, int _keepaliveDuration);
virtual ~TerminalClient();
void run(const string& command);
void run(const string& command, const bool noexit);
void shutdown() {
lock_guard<recursive_mutex> guard(shutdownMutex);
shuttingDown = true;
Expand Down
9 changes: 6 additions & 3 deletions src/terminal/TerminalClientMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ int main(int argc, char** argv) {
cxxopts::value<std::string>()) //
("p,port", "Remote machine etserver port",
cxxopts::value<int>()->default_value("2022")) //
("c,command", "Run command on connect",
("c,command", "Run command on connect and exit after command is run",
cxxopts::value<std::string>()) //
("e,noexit",
"Used together with -c to not exit after command is run") //
("terminal-path",
"Path to etterminal on server side. "
"Use if etterminal is not on the system path.",
Expand Down Expand Up @@ -351,8 +353,9 @@ int main(int argc, char** argv) {
socketEndpoint, id, passkey, console,
is_jumphost, tunnel_arg, r_tunnel_arg,
forwardAgent, sshSocket, keepaliveDuration);
terminalClient.run(result.count("command") ? result["command"].as<string>()
: "");
terminalClient.run(
result.count("command") ? result["command"].as<string>() : "",
result.count("noexit"));
} catch (TunnelParseException& tpe) {
handleParseException(tpe, options);
} catch (cxxopts::OptionException& oe) {
Expand Down
3 changes: 2 additions & 1 deletion test/JumphostTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void readWriteTest(const string& clientId,
clientSocketHandler, clientPipeSocketHandler, jumphostEndpoint, clientId,
CRYPTO_KEY, fakeConsole, true, "", "", false, "",
MAX_CLIENT_KEEP_ALIVE_DURATION));
thread terminalClientThread([terminalClient]() { terminalClient->run(""); });
thread terminalClientThread(
[terminalClient]() { terminalClient->run("", false); });
sleep(3);

string s(1024, '\0');
Expand Down
6 changes: 4 additions & 2 deletions test/TerminalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ void readWriteTest(const string& clientId,
clientSocketHandler, clientPipeSocketHandler, serverEndpoint, clientId,
CRYPTO_KEY, fakeConsole, false, "", "", false, "",
MAX_CLIENT_KEEP_ALIVE_DURATION));
thread terminalClientThread([terminalClient]() { terminalClient->run(""); });
thread terminalClientThread(
[terminalClient]() { terminalClient->run("", false); });
sleep(3);

string s(1024, '\0');
Expand Down Expand Up @@ -379,7 +380,8 @@ void simultaneousTerminalConnectionTest(
clientSocketHandler, clientPipeSocketHandler, serverEndpoint, clientId,
CRYPTO_KEY, fakeConsole, false, "", "", false, "",
MAX_CLIENT_KEEP_ALIVE_DURATION));
thread terminalClientThread([terminalClient]() { terminalClient->run(""); });
thread terminalClientThread(
[terminalClient]() { terminalClient->run("", false); });
sleep(3);

const string s("test");
Expand Down

0 comments on commit 97b5956

Please sign in to comment.