From 78d8dd8997717f55ff13b826d0c2aab717264d78 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 25 May 2022 15:25:22 +0200 Subject: [PATCH] LinuxDevice: Fix starting a shell with SSH_ASKPASS Change-Id: I11a8a477a1f9796ceb021037b781da2ca8d87f43 Reviewed-by: Qt CI Bot Reviewed-by: Christian Kandeler --- src/plugins/remotelinux/linuxdevice.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index b0881625023..f75f94c9991 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -804,11 +804,30 @@ public: m_shell->setWriteData("echo\n"); m_shell->start(); - if (!m_shell->waitForStarted() || !m_shell->waitForReadyRead() - || m_shell->readAllStandardOutput() != "\n") { + auto failed = [this] { closeShell(); qCDebug(linuxDeviceLog) << "Failed to connect to" << m_displaylessSshParameters.host(); return false; + }; + + QDeadlineTimer timer(30000); + if (!m_shell->waitForStarted(timer.remainingTime())) + return failed(); + + while (true) { + if (!m_shell->waitForReadyRead(timer.remainingTime())) + return failed(); + + const QByteArray output = m_shell->readAllStandardOutput(); + if (output == "\n") + break; // expected output from echo + if (output.size() > 0) + return failed(); // other unidentified output + + // In case of trying to run a shell using SSH_ASKPASS, it may happen + // that we receive ready read signal but for error channel, while output + // channel still is empty. In this case we wait in loop until the user + // provides the right password, otherwise we timeout after 30 seconds. } return true; }