Skip to content
Snippets Groups Projects
Commit 661f6eb9 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #2669: Fixes ever-expanding input buffer for SSHconnection

parent fb0c0965
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,8 @@
#include <string.h>
#include <errno.h>
#include <vector>
#include <string>
#include <sstream>
#ifdef HAVE_LIBSSH2
#include <Scheduling.h>
......@@ -217,7 +219,6 @@ void SSHconnection::commThread()
LOG_DEBUG_STR( itsLogPrefix << "Connected" );
stringstream buffer;
int rc;
int exitcode;
char *exitsignal=(char *)"none";
......@@ -247,16 +248,24 @@ void SSHconnection::commThread()
LOG_DEBUG_STR( itsLogPrefix << "Remote command started, waiting for output" );
// raw input buffer
char data[0x1000];
// the current line (or line remnant)
string line("");
/* Session I/O */
for( ;; )
{
/* loop until we block */
do {
char data[0x4000];
rc = libssh2_channel_read( channel, data, sizeof data );
if( rc > 0 )
{
// create a buffer for line + data
stringstream buffer;
buffer << line;
buffer.write( data, rc );
/* extract and log lines */
......@@ -264,16 +273,15 @@ void SSHconnection::commThread()
{
Cancellation::point();
buffer.getline( data, sizeof data );
std::getline( buffer, line );
if (buffer.fail()) {
// no line found
buffer.clear();
if (!buffer.good()) {
// 'line' now holds the remnant
break;
}
// TODO: Use logger somehow (we'd duplicate the prefix if we just use LOG_* macros..)
cout << data << endl;
cout << line << endl;
}
} else {
if( rc < 0 && rc != LIBSSH2_ERROR_EAGAIN ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment