Commit b494459a authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Updating failure checks in requestExec.

parent da03c8eb
...@@ -58,6 +58,8 @@ SessionWorker::~SessionWorker() ...@@ -58,6 +58,8 @@ SessionWorker::~SessionWorker()
if (p != nullptr) delete p; if (p != nullptr) delete p;
} }
QByteArray SessionWorker::readExecOutput() { return p->output_buffer; }
void SessionWorker::setHost(QString host) void SessionWorker::setHost(QString host)
{ {
assert_ssh_session(p->session, "setHost() -- Session is not allocated."); assert_ssh_session(p->session, "setHost() -- Session is not allocated.");
...@@ -270,21 +272,24 @@ void SessionWorker::requestExec(QString command) ...@@ -270,21 +272,24 @@ void SessionWorker::requestExec(QString command)
ssh_channel channel = ssh_channel_new(p->session); ssh_channel channel = ssh_channel_new(p->session);
if (channel == nullptr) if (channel == nullptr)
{ {
radix_tagged_line("TODO: Handle failed new channel"); radix_tagged_line("Failed to create new channel");
emit execFailed("Failed to allocate a channel on the open session.");
return; return;
} }
int rc = ssh_channel_open_session(channel); int rc = ssh_channel_open_session(channel);
if (rc < 0) if (rc < 0)
{ {
radix_tagged_line("TODO: Handle failed new channel"); radix_tagged_line("Failed to create new channel");
emit execFailed("Failed to open a channel on the session.");
return; return;
} }
rc = ssh_channel_request_exec(channel, command.toStdString().c_str()); rc = ssh_channel_request_exec(channel, command.toStdString().c_str());
if (rc < 0) if (rc < 0)
{ {
radix_tagged_line("TODO: Handle failed new channel"); radix_tagged_line("Failed to request exec.");
emit execFailed("Failed to execute remote command.");
ssh_channel_close(channel); ssh_channel_close(channel);
ssh_channel_free(channel); ssh_channel_free(channel);
return; return;
...@@ -303,9 +308,15 @@ void SessionWorker::requestExec(QString command) ...@@ -303,9 +308,15 @@ void SessionWorker::requestExec(QString command)
{ {
ssh_channel_send_eof(channel); ssh_channel_send_eof(channel);
} }
if (nbytes < 0)
{
emit execFailed("Failed to read response from remote command.");
}
ssh_channel_close(channel); ssh_channel_close(channel);
ssh_channel_free(channel); ssh_channel_free(channel);
radix_tagged_line("'" << command.toStdString() << "' finished.");
emit execFinished();
} }
} // namespace rsm } // namespace rsm
\ No newline at end of file
...@@ -34,6 +34,7 @@ class RSM_PUBLIC SessionWorker : public QObject ...@@ -34,6 +34,7 @@ class RSM_PUBLIC SessionWorker : public QObject
*/ */
SessionWorker(QString host, QObject* parent = nullptr); SessionWorker(QString host, QObject* parent = nullptr);
~SessionWorker(); ~SessionWorker();
QByteArray readExecOutput();
public slots: public slots:
...@@ -109,6 +110,8 @@ class RSM_PUBLIC SessionWorker : public QObject ...@@ -109,6 +110,8 @@ class RSM_PUBLIC SessionWorker : public QObject
void passwordRequested(); void passwordRequested();
void loginBannerIssued(QString message); void loginBannerIssued(QString message);
void execOutputReady(); void execOutputReady();
void execFailed(QString message);
void execFinished();
}; // class SessionWorker }; // class SessionWorker
} // namespace rsm } // namespace rsm
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
using namespace rsm; using namespace rsm;
TEST(RSM, Session) TEST(RSM, Session)
{ {
SessionWorker session("nfecc"); SessionWorker session("apollo");
session.setLogVerbosity(SessionWorker::Verbosity::None); session.setLogVerbosity(SessionWorker::Verbosity::None);
session.setPort(22); session.setPort(22);
session.setUser("jap"); session.setUser("jap");
...@@ -13,6 +13,18 @@ TEST(RSM, Session) ...@@ -13,6 +13,18 @@ TEST(RSM, Session)
session.verifyKnownHost(); // 2) verify host is known/acceptable session.verifyKnownHost(); // 2) verify host is known/acceptable
session.authenticate(); // 3) process authentication session.authenticate(); // 3) process authentication
session.requestExec("ls -la"); session.requestExec("ls -la");
QByteArray ls_la = session.readExecOutput();
session.requestExec("ls modulefiles"); session.requestExec("ls modulefiles");
QByteArray ls_mod = session.readExecOutput();
std::cout << "ls -la output" << std::endl;
std::cout << ls_la.data() << std::endl;
std::cout << "ls modulefiles output" << std::endl;
std::cout << ls_mod.data() << std::endl;
session.requestExec("showq");
std::cout << session.readExecOutput().data() << std::endl;
session.disconnect(); session.disconnect();
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment