diff --git a/src/plugins/qnx/qnxdeviceconfiguration.cpp b/src/plugins/qnx/qnxdeviceconfiguration.cpp index 3305959bcd5a2eb724274bdd815847c250045f3a..2224a44e75231606b7e3acfe8aa86100e22debf0 100644 --- a/src/plugins/qnx/qnxdeviceconfiguration.cpp +++ b/src/plugins/qnx/qnxdeviceconfiguration.cpp @@ -39,20 +39,62 @@ #include <projectexplorer/devicesupport/sshdeviceprocess.h> #include <ssh/sshconnection.h> #include <utils/qtcassert.h> +#include <utils/qtcprocess.h> #include <QApplication> #include <QRegExp> #include <QStringList> #include <QThread> -using namespace Qnx; -using namespace Qnx::Internal; +using namespace ProjectExplorer; +using namespace Utils; + +namespace Qnx { +namespace Internal { -namespace { const char QnxVersionKey[] = "QnxVersion"; const char DeployQtLibrariesActionId [] = "Qnx.Qnx.DeployQtLibrariesAction"; + +static int pidFileCounter = 0; + +QnxDeviceProcess::QnxDeviceProcess(const QSharedPointer<const IDevice> &device, QObject *parent) + : SshDeviceProcess(device, parent) +{ + setEnvironment(Environment(OsTypeLinux)); + m_pidFile = QString::fromLatin1("/var/run/qtc.%1.pid").arg(++pidFileCounter); +} + +QString QnxDeviceProcess::fullCommandLine() const +{ + QStringList args = arguments(); + args.prepend(executable()); + QString cmd = QtcProcess::Arguments::createUnixArgs(args).toString(); + + QString fullCommandLine = QLatin1String( + "test -f /etc/profile && . /etc/profile ; " + "test -f $HOME/profile && . $HOME/profile ; " + ); + + if (!m_workingDir.isEmpty()) + fullCommandLine += QString::fromLatin1("cd %1 ; ").arg(QtcProcess::quoteArg(m_workingDir)); + + for (auto it = environment().constBegin(); it != environment().constEnd(); ++it) + fullCommandLine += QString::fromLatin1("%1='%2' ").arg(it.key()).arg(it.value()); + + fullCommandLine += QString::fromLatin1("%1 & echo $! > %2").arg(cmd).arg(m_pidFile); + + return fullCommandLine; +} + +void QnxDeviceProcess::doSignal(int sig) +{ + auto signaler = new SshDeviceProcess(device(), this); + QString cmd = QString::fromLatin1("kill -%2 `cat %1`").arg(m_pidFile).arg(sig); + connect(signaler, &SshDeviceProcess::finished, signaler, &QObject::deleteLater); + signaler->start(cmd, QStringList()); } + class QnxPortsGatheringMethod : public ProjectExplorer::PortsGatheringMethod { // TODO: The command is probably needlessly complicated because the parsing method @@ -196,6 +238,11 @@ ProjectExplorer::DeviceTester *QnxDeviceConfiguration::createDeviceTester() cons return new QnxDeviceTester; } +ProjectExplorer::DeviceProcess *QnxDeviceConfiguration::createProcess(QObject *parent) const +{ + return new QnxDeviceProcess(sharedFromThis(), parent); +} + QList<Core::Id> QnxDeviceConfiguration::actionIds() const { QList<Core::Id> actions = RemoteLinux::LinuxDevice::actionIds(); @@ -228,3 +275,6 @@ ProjectExplorer::DeviceProcessSignalOperation::Ptr QnxDeviceConfiguration::signa return ProjectExplorer::DeviceProcessSignalOperation::Ptr( new QnxDeviceProcessSignalOperation(sshParameters())); } + +} // namespace Internal +} // namespace Qnx diff --git a/src/plugins/qnx/qnxdeviceconfiguration.h b/src/plugins/qnx/qnxdeviceconfiguration.h index 9f95be2d84dd5c7cbc80da1be21aa6100b7bcade..1fe3aedb53ae6b5f15d76ddf8e07dcbcf174bb43 100644 --- a/src/plugins/qnx/qnxdeviceconfiguration.h +++ b/src/plugins/qnx/qnxdeviceconfiguration.h @@ -34,10 +34,29 @@ #define QNX_INTERNAL_QNXDEVICECONFIGURATION_H #include <remotelinux/linuxdevice.h> +#include <projectexplorer/devicesupport/sshdeviceprocess.h> namespace Qnx { namespace Internal { +class QnxDeviceProcess : public ProjectExplorer::SshDeviceProcess +{ +public: + QnxDeviceProcess(const QSharedPointer<const ProjectExplorer::IDevice> &device, QObject *parent); + + void setWorkingDirectory(const QString &directory) { m_workingDir = directory; } + + void interrupt() { doSignal(2); } + void terminate() { doSignal(15); } + void kill() { doSignal(9); } + QString fullCommandLine() const; + +private: + void doSignal(int sig); + QString m_pidFile; + QString m_workingDir; +}; + class QnxDeviceConfiguration : public RemoteLinux::LinuxDevice { Q_DECLARE_TR_FUNCTIONS(Qnx::Internal::QnxDeviceConfiguration) @@ -56,6 +75,7 @@ public: ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const; ProjectExplorer::DeviceTester *createDeviceTester() const; + ProjectExplorer::DeviceProcess *createProcess(QObject *parent) const; QList<Core::Id> actionIds() const; QString displayNameForActionId(Core::Id actionId) const; diff --git a/src/plugins/qnx/slog2inforunner.cpp b/src/plugins/qnx/slog2inforunner.cpp index 5a33a4677545d50dfb5fd690afe1075d3e743b3d..e24a5ee66a184f591802a5184fed7ded70198737 100644 --- a/src/plugins/qnx/slog2inforunner.cpp +++ b/src/plugins/qnx/slog2inforunner.cpp @@ -32,7 +32,8 @@ #include "slog2inforunner.h" -#include <projectexplorer/devicesupport/sshdeviceprocess.h> +#include "qnxdeviceconfiguration.h" + #include <utils/qtcassert.h> using namespace Qnx; @@ -48,13 +49,13 @@ Slog2InfoRunner::Slog2InfoRunner(const QString &applicationId, const RemoteLinux // We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info. m_applicationId.truncate(63); - m_testProcess = new ProjectExplorer::SshDeviceProcess(device, this); + m_testProcess = new QnxDeviceProcess(device, this); connect(m_testProcess, SIGNAL(finished()), this, SLOT(handleTestProcessCompleted())); m_launchDateTimeProcess = new ProjectExplorer::SshDeviceProcess(device, this); connect(m_launchDateTimeProcess, SIGNAL(finished()), this, SLOT(launchSlog2Info())); - m_logProcess = new ProjectExplorer::SshDeviceProcess(device, this); + m_logProcess = new QnxDeviceProcess(device, this); connect(m_logProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readLogStandardOutput())); connect(m_logProcess, SIGNAL(readyReadStandardError()), this, SLOT(readLogStandardError())); connect(m_logProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(handleLogError()));