summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-11-27 17:46:45 +0100
committerhjk <hjk121@nokiamail.com>2014-12-01 12:56:14 +0100
commit762a3e6e4cd8843d5c72e4c6d5acb820d991b3eb (patch)
treef1bf0324e4adfd4a33b86a7128f6c2a2cc25b9e4
parentb28d1525ebc8491c839412ce946fca5d6f22d38f (diff)
downloadqt-creator-762a3e6e4cd8843d5c72e4c6d5acb820d991b3eb.tar.gz
Qnx: Introduce QnxDeviceProcess
This is helpful for more selective and direct process killing. Previously, all processes with a given name were killed, and in some cases stale awk and grep processes were left over. Change-Id: I4fb3999818062b8c1fdf7dca8a337ef9c158be9b Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r--src/plugins/qnx/qnxdeviceconfiguration.cpp56
-rw-r--r--src/plugins/qnx/qnxdeviceconfiguration.h20
-rw-r--r--src/plugins/qnx/slog2inforunner.cpp7
3 files changed, 77 insertions, 6 deletions
diff --git a/src/plugins/qnx/qnxdeviceconfiguration.cpp b/src/plugins/qnx/qnxdeviceconfiguration.cpp
index 3305959bcd..2224a44e75 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 9f95be2d84..1fe3aedb53 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 5a33a46775..e24a5ee66a 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()));