LinuxDevice: Run test echo command after successful start

After we have started the shell it can happen that
it will finish silently soon due to e.g. ssh server not running.
Before we try to execute any command in the shell we
schedule a test echo command just after successful start
in order to confirm that the shell is running fine.
If waiting for ready read returned false (i.e. the shell
process finished) or if we don't receive the expected
newline character we report a start failure.

Fixes: QTCREATORBUG-26861
Change-Id: I7387b3a366f8e6f4a58745582bb803f5060cfc36
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-01-13 12:56:24 +01:00
parent e7d125ffec
commit 7c91900cfb

View File

@@ -197,19 +197,34 @@ public:
delete m_shell; delete m_shell;
} }
bool startFailed(const SshConnectionParameters &parameters)
{
delete m_shell;
m_shell = nullptr;
DEBUG("Failed to connect to " << parameters.host());
return false;
}
bool start(const SshConnectionParameters &parameters) bool start(const SshConnectionParameters &parameters)
{ {
m_shell = new SshRemoteProcess("/bin/sh", m_shell = new SshRemoteProcess("/bin/sh",
parameters.connectionOptions(SshSettings::sshFilePath()) << parameters.host(), parameters.connectionOptions(SshSettings::sshFilePath()) << parameters.host(),
ProcessMode::Writer); ProcessMode::Writer);
m_shell->start(); m_shell->start();
const bool ret = m_shell->waitForStarted(); const bool startOK = m_shell->waitForStarted();
if (!ret) { if (!startOK)
delete m_shell; return startFailed(parameters);
m_shell = nullptr;
DEBUG("Failed to connect to " << parameters.host()); m_shell->write("echo\n");
} const bool readOK = m_shell->waitForReadyRead();
return ret; if (!readOK)
return startFailed(parameters);
const QByteArray output = m_shell->readAllStandardOutput();
if (output != "\n")
return startFailed(parameters);
return true;
} }
bool runInShell(const CommandLine &cmd, const QByteArray &data = {}) bool runInShell(const CommandLine &cmd, const QByteArray &data = {})