From ec63e694d8cea44c651a570f08380669eb1c2ee4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 7 Jun 2022 14:23:18 +0200 Subject: [PATCH] DeviceShell: Don't store a shell script on remote side Execute a script directly on remote side instead. Storing it always into /tmp/shell.sh may potentially break when 2 or more shells are being started for one device at the same time. Change-Id: I2b8c94ef531fa4916383355a312421a3a18bfcad Reviewed-by: hjk --- src/libs/utils/deviceshell.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libs/utils/deviceshell.cpp b/src/libs/utils/deviceshell.cpp index d46be147096..da8dc1a02d4 100644 --- a/src/libs/utils/deviceshell.cpp +++ b/src/libs/utils/deviceshell.cpp @@ -349,15 +349,12 @@ bool DeviceShell::start() bool DeviceShell::installShellScript() { - const QString installCmd - = QString("echo %1 | base64 -d > /tmp/shell.sh 2>/dev/null && " - "chmod +x /tmp/shell.sh && " - "/tmp/shell.sh || echo ERROR_INSTALL_SCRIPT >&2\n") - .arg(QString::fromLatin1( - QByteArray(r_execScript.begin(), r_execScript.size()).toBase64())); + const QByteArray runScriptCmd = "scriptData=$(echo " + + QByteArray(r_execScript.begin(), r_execScript.size()).toBase64() + + " | base64 -d) && /bin/sh -c \"$scriptData\" || echo ERROR_INSTALL_SCRIPT >&2\n"; - qCDebug(deviceShellLog) << "Install shell script command:" << installCmd; - m_shellProcess->write(installCmd); + qCDebug(deviceShellLog) << "Install shell script command:" << runScriptCmd; + m_shellProcess->writeRaw(runScriptCmd); while (m_shellScriptState == State::Unknown) { if (!m_shellProcess->waitForReadyRead()) {