From 7c91900cfb53d42ea427458f2627bbb5d9f90d72 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 13 Jan 2022 12:56:24 +0100 Subject: [PATCH] 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 --- src/plugins/remotelinux/linuxdevice.cpp | 29 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 874ae4386ff..aec9af303da 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -197,19 +197,34 @@ public: delete m_shell; } + bool startFailed(const SshConnectionParameters ¶meters) + { + delete m_shell; + m_shell = nullptr; + DEBUG("Failed to connect to " << parameters.host()); + return false; + } + bool start(const SshConnectionParameters ¶meters) { m_shell = new SshRemoteProcess("/bin/sh", parameters.connectionOptions(SshSettings::sshFilePath()) << parameters.host(), ProcessMode::Writer); m_shell->start(); - const bool ret = m_shell->waitForStarted(); - if (!ret) { - delete m_shell; - m_shell = nullptr; - DEBUG("Failed to connect to " << parameters.host()); - } - return ret; + const bool startOK = m_shell->waitForStarted(); + if (!startOK) + return startFailed(parameters); + + m_shell->write("echo\n"); + const bool readOK = m_shell->waitForReadyRead(); + 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 = {})