2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-05-31 12:47:53 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
#include "linuxdevice.h"
|
2011-05-31 12:47:53 +02:00
|
|
|
|
2012-04-06 18:28:16 +02:00
|
|
|
#include "genericlinuxdeviceconfigurationwidget.h"
|
2013-08-08 14:05:11 +02:00
|
|
|
#include "linuxdeviceprocess.h"
|
2013-06-27 17:12:08 +02:00
|
|
|
#include "linuxdevicetester.h"
|
2012-04-06 18:28:16 +02:00
|
|
|
#include "publickeydeploymentdialog.h"
|
2011-07-25 11:55:00 +02:00
|
|
|
#include "remotelinux_constants.h"
|
2013-09-16 15:30:30 +02:00
|
|
|
#include "remotelinuxsignaloperation.h"
|
2011-07-25 11:55:00 +02:00
|
|
|
|
2012-06-05 14:30:31 +02:00
|
|
|
#include <coreplugin/id.h>
|
2012-08-02 14:45:27 +02:00
|
|
|
#include <projectexplorer/devicesupport/sshdeviceprocesslist.h>
|
2013-09-16 15:30:30 +02:00
|
|
|
#include <ssh/sshremoteprocessrunner.h>
|
2012-02-15 14:47:45 -08:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2013-09-16 15:30:30 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
2012-07-26 16:23:20 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
namespace RemoteLinux {
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2012-07-26 17:41:52 +02:00
|
|
|
const char Delimiter0[] = "x--";
|
|
|
|
const char Delimiter1[] = "---";
|
|
|
|
|
|
|
|
static QString visualizeNull(QString s)
|
|
|
|
{
|
|
|
|
return s.replace(QLatin1Char('\0'), QLatin1String("<null>"));
|
|
|
|
}
|
|
|
|
|
2012-08-02 14:45:27 +02:00
|
|
|
class LinuxDeviceProcessList : public SshDeviceProcessList
|
2012-08-01 16:26:27 +02:00
|
|
|
{
|
2012-08-02 14:45:27 +02:00
|
|
|
public:
|
|
|
|
LinuxDeviceProcessList(const IDevice::ConstPtr &device, QObject *parent)
|
|
|
|
: SshDeviceProcessList(device, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString listProcessesCommandLine() const
|
|
|
|
{
|
|
|
|
return QString::fromLatin1(
|
2012-08-01 16:26:27 +02:00
|
|
|
"for dir in `ls -d /proc/[0123456789]*`; do "
|
|
|
|
"test -d $dir || continue;" // Decrease the likelihood of a race condition.
|
|
|
|
"echo $dir;"
|
|
|
|
"cat $dir/cmdline;echo;" // cmdline does not end in newline
|
|
|
|
"cat $dir/stat;"
|
|
|
|
"readlink $dir/exe;"
|
|
|
|
"printf '%1''%2';"
|
2012-11-26 14:41:39 +02:00
|
|
|
"done").arg(QLatin1String(Delimiter0)).arg(QLatin1String(Delimiter1));
|
2012-08-02 14:45:27 +02:00
|
|
|
}
|
2012-08-01 16:26:27 +02:00
|
|
|
|
2013-08-08 11:13:20 +02:00
|
|
|
QList<DeviceProcessItem> buildProcessList(const QString &listProcessesReply) const
|
2012-08-02 14:45:27 +02:00
|
|
|
{
|
2013-08-08 11:13:20 +02:00
|
|
|
QList<DeviceProcessItem> processes;
|
2012-08-02 14:45:27 +02:00
|
|
|
const QStringList lines = listProcessesReply.split(QString::fromLatin1(Delimiter0)
|
|
|
|
+ QString::fromLatin1(Delimiter1), QString::SkipEmptyParts);
|
|
|
|
foreach (const QString &line, lines) {
|
|
|
|
const QStringList elements = line.split(QLatin1Char('\n'));
|
|
|
|
if (elements.count() < 4) {
|
|
|
|
qDebug("%s: Expected four list elements, got %d. Line was '%s'.", Q_FUNC_INFO,
|
|
|
|
elements.count(), qPrintable(visualizeNull(line)));
|
2012-08-01 16:26:27 +02:00
|
|
|
continue;
|
2012-08-02 14:45:27 +02:00
|
|
|
}
|
|
|
|
bool ok;
|
|
|
|
const int pid = elements.first().mid(6).toInt(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
qDebug("%s: Expected number in %s. Line was '%s'.", Q_FUNC_INFO,
|
|
|
|
qPrintable(elements.first()), qPrintable(visualizeNull(line)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString command = elements.at(1);
|
|
|
|
command.replace(QLatin1Char('\0'), QLatin1Char(' '));
|
|
|
|
if (command.isEmpty()) {
|
|
|
|
const QString &statString = elements.at(2);
|
|
|
|
const int openParenPos = statString.indexOf(QLatin1Char('('));
|
|
|
|
const int closedParenPos = statString.indexOf(QLatin1Char(')'), openParenPos);
|
|
|
|
if (openParenPos == -1 || closedParenPos == -1)
|
|
|
|
continue;
|
|
|
|
command = QLatin1Char('[')
|
|
|
|
+ statString.mid(openParenPos + 1, closedParenPos - openParenPos - 1)
|
|
|
|
+ QLatin1Char(']');
|
|
|
|
}
|
|
|
|
|
2013-08-08 11:13:20 +02:00
|
|
|
DeviceProcessItem process;
|
2012-08-02 14:45:27 +02:00
|
|
|
process.pid = pid;
|
|
|
|
process.cmdLine = command;
|
|
|
|
process.exe = elements.at(3);
|
|
|
|
processes.append(process);
|
2012-08-01 16:26:27 +02:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:45:27 +02:00
|
|
|
qSort(processes);
|
|
|
|
return processes;
|
2012-08-01 16:26:27 +02:00
|
|
|
}
|
2012-08-02 14:45:27 +02:00
|
|
|
};
|
2012-08-01 16:26:27 +02:00
|
|
|
|
|
|
|
class LinuxPortsGatheringMethod : public ProjectExplorer::PortsGatheringMethod
|
|
|
|
{
|
|
|
|
QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const
|
|
|
|
{
|
|
|
|
QString procFilePath;
|
|
|
|
int addressLength;
|
|
|
|
if (protocol == QAbstractSocket::IPv4Protocol) {
|
|
|
|
procFilePath = QLatin1String("/proc/net/tcp");
|
|
|
|
addressLength = 8;
|
|
|
|
} else {
|
|
|
|
procFilePath = QLatin1String("/proc/net/tcp6");
|
|
|
|
addressLength = 32;
|
|
|
|
}
|
|
|
|
return QString::fromLatin1("sed "
|
|
|
|
"'s/.*: [[:xdigit:]]\\{%1\\}:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' %2")
|
|
|
|
.arg(addressLength).arg(procFilePath).toUtf8();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> usedPorts(const QByteArray &output) const
|
|
|
|
{
|
|
|
|
QList<int> ports;
|
|
|
|
QList<QByteArray> portStrings = output.split('\n');
|
|
|
|
portStrings.removeFirst();
|
|
|
|
foreach (const QByteArray &portString, portStrings) {
|
|
|
|
if (portString.isEmpty())
|
|
|
|
continue;
|
|
|
|
bool ok;
|
|
|
|
const int port = portString.toInt(&ok, 16);
|
|
|
|
if (ok) {
|
|
|
|
if (!ports.contains(port))
|
|
|
|
ports << port;
|
|
|
|
} else {
|
|
|
|
qWarning("%s: Unexpected string '%s' is not a port.",
|
|
|
|
Q_FUNC_INFO, portString.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ports;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
LinuxDevice::Ptr LinuxDevice::create(const QString &name,
|
2012-05-16 10:46:21 +02:00
|
|
|
Core::Id type, MachineType machineType, Origin origin, Core::Id id)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2012-07-27 13:31:13 +02:00
|
|
|
return Ptr(new LinuxDevice(name, type, machineType, origin, id));
|
2012-03-02 18:09:59 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
QString LinuxDevice::displayType() const
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
|
|
|
return tr("Generic Linux");
|
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
ProjectExplorer::IDeviceWidget *LinuxDevice::createWidget()
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
2012-07-26 17:41:52 +02:00
|
|
|
return new GenericLinuxDeviceConfigurationWidget(sharedFromThis());
|
2012-04-06 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
QList<Core::Id> LinuxDevice::actionIds() const
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
2013-06-27 17:12:08 +02:00
|
|
|
return QList<Core::Id>() << Core::Id(Constants::GenericDeployKeyToDeviceActionId);
|
2012-04-06 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
QString LinuxDevice::displayNameForActionId(Core::Id actionId) const
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
|
|
|
QTC_ASSERT(actionIds().contains(actionId), return QString());
|
|
|
|
|
2012-08-03 15:24:33 +02:00
|
|
|
if (actionId == Constants::GenericDeployKeyToDeviceActionId)
|
2012-04-06 18:28:16 +02:00
|
|
|
return tr("Deploy Public Key...");
|
|
|
|
return QString(); // Can't happen.
|
|
|
|
}
|
|
|
|
|
2013-09-16 11:12:31 +02:00
|
|
|
void LinuxDevice::executeAction(Core::Id actionId, QWidget *parent)
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
2012-05-02 16:03:26 +02:00
|
|
|
QTC_ASSERT(actionIds().contains(actionId), return);
|
2012-04-06 18:28:16 +02:00
|
|
|
|
2012-06-06 22:53:11 +02:00
|
|
|
QDialog *d = 0;
|
2012-07-27 13:31:13 +02:00
|
|
|
const LinuxDevice::ConstPtr device = sharedFromThis().staticCast<const LinuxDevice>();
|
2013-06-27 17:12:08 +02:00
|
|
|
if (actionId == Constants::GenericDeployKeyToDeviceActionId)
|
2012-05-02 16:03:26 +02:00
|
|
|
d = PublicKeyDeploymentDialog::createDialog(device, parent);
|
|
|
|
if (d)
|
|
|
|
d->exec();
|
2012-08-02 14:45:27 +02:00
|
|
|
delete d;
|
2012-04-06 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
LinuxDevice::LinuxDevice(const QString &name, Core::Id type, MachineType machineType,
|
2012-07-25 17:10:20 +02:00
|
|
|
Origin origin, Core::Id id)
|
|
|
|
: IDevice(type, origin, machineType, id)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2012-03-06 12:31:42 +01:00
|
|
|
setDisplayName(name);
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
LinuxDevice::LinuxDevice(const LinuxDevice &other)
|
2012-06-05 14:30:31 +02:00
|
|
|
: IDevice(other)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
LinuxDevice::Ptr LinuxDevice::create()
|
2012-03-02 18:09:59 +01:00
|
|
|
{
|
2012-07-27 13:31:13 +02:00
|
|
|
return Ptr(new LinuxDevice);
|
2012-03-02 18:09:59 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 13:31:13 +02:00
|
|
|
ProjectExplorer::IDevice::Ptr LinuxDevice::clone() const
|
2012-03-05 12:37:32 +01:00
|
|
|
{
|
2012-07-27 13:31:13 +02:00
|
|
|
return Ptr(new LinuxDevice(*this));
|
2012-03-05 12:37:32 +01:00
|
|
|
}
|
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
DeviceProcess *LinuxDevice::createProcess(QObject *parent) const
|
|
|
|
{
|
|
|
|
return new LinuxDeviceProcess(sharedFromThis(), parent);
|
|
|
|
}
|
|
|
|
|
2013-04-18 09:31:22 +02:00
|
|
|
bool LinuxDevice::canAutoDetectPorts() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-01 16:26:27 +02:00
|
|
|
PortsGatheringMethod::Ptr LinuxDevice::portsGatheringMethod() const
|
2012-07-26 17:41:52 +02:00
|
|
|
{
|
2012-08-01 16:26:27 +02:00
|
|
|
return LinuxPortsGatheringMethod::Ptr(new LinuxPortsGatheringMethod);
|
2012-07-26 17:41:52 +02:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:45:27 +02:00
|
|
|
DeviceProcessList *LinuxDevice::createProcessListModel(QObject *parent) const
|
|
|
|
{
|
|
|
|
return new LinuxDeviceProcessList(sharedFromThis(), parent);
|
|
|
|
}
|
|
|
|
|
2013-06-27 17:12:08 +02:00
|
|
|
DeviceTester *LinuxDevice::createDeviceTester() const
|
2013-05-30 13:53:28 +02:00
|
|
|
{
|
|
|
|
return new GenericLinuxDeviceTester;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:30:30 +02:00
|
|
|
DeviceProcessSignalOperation::Ptr LinuxDevice::signalOperation() const
|
|
|
|
{
|
|
|
|
return DeviceProcessSignalOperation::Ptr(new RemoteLinuxSignalOperation(sshParameters()));
|
|
|
|
}
|
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
} // namespace RemoteLinux
|