Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
rsm
Commits
b494459a
Commit
b494459a
authored
Jan 17, 2020
by
LEFEBVREJP email
Browse files
Updating failure checks in requestExec.
parent
da03c8eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
rsmcore/sessionworker.cc
View file @
b494459a
...
...
@@ -58,6 +58,8 @@ SessionWorker::~SessionWorker()
if
(
p
!=
nullptr
)
delete
p
;
}
QByteArray
SessionWorker
::
readExecOutput
()
{
return
p
->
output_buffer
;
}
void
SessionWorker
::
setHost
(
QString
host
)
{
assert_ssh_session
(
p
->
session
,
"setHost() -- Session is not allocated."
);
...
...
@@ -270,21 +272,24 @@ void SessionWorker::requestExec(QString command)
ssh_channel
channel
=
ssh_channel_new
(
p
->
session
);
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
;
}
int
rc
=
ssh_channel_open_session
(
channel
);
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
;
}
rc
=
ssh_channel_request_exec
(
channel
,
command
.
toStdString
().
c_str
());
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_free
(
channel
);
return
;
...
...
@@ -303,9 +308,15 @@ void SessionWorker::requestExec(QString command)
{
ssh_channel_send_eof
(
channel
);
}
if
(
nbytes
<
0
)
{
emit
execFailed
(
"Failed to read response from remote command."
);
}
ssh_channel_close
(
channel
);
ssh_channel_free
(
channel
);
radix_tagged_line
(
"'"
<<
command
.
toStdString
()
<<
"' finished."
);
emit
execFinished
();
}
}
// namespace rsm
\ No newline at end of file
rsmcore/sessionworker.hh
View file @
b494459a
...
...
@@ -34,6 +34,7 @@ class RSM_PUBLIC SessionWorker : public QObject
*/
SessionWorker
(
QString
host
,
QObject
*
parent
=
nullptr
);
~
SessionWorker
();
QByteArray
readExecOutput
();
public
slots
:
...
...
@@ -109,6 +110,8 @@ class RSM_PUBLIC SessionWorker : public QObject
void
passwordRequested
();
void
loginBannerIssued
(
QString
message
);
void
execOutputReady
();
void
execFailed
(
QString
message
);
void
execFinished
();
};
// class SessionWorker
}
// namespace rsm
...
...
rsmcore/tests/tstSession.cc
View file @
b494459a
...
...
@@ -5,7 +5,7 @@
using
namespace
rsm
;
TEST
(
RSM
,
Session
)
{
SessionWorker
session
(
"
nfecc
"
);
SessionWorker
session
(
"
apollo
"
);
session
.
setLogVerbosity
(
SessionWorker
::
Verbosity
::
None
);
session
.
setPort
(
22
);
session
.
setUser
(
"jap"
);
...
...
@@ -13,6 +13,18 @@ TEST(RSM, Session)
session
.
verifyKnownHost
();
// 2) verify host is known/acceptable
session
.
authenticate
();
// 3) process authentication
session
.
requestExec
(
"ls -la"
);
QByteArray
ls_la
=
session
.
readExecOutput
();
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
();
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment