1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
4 ** Contact: BlackBerry (qt@blackberry.com), KDAB (info@kdab.com)
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "qnxdeviceprocesssignaloperation.h"
27 
28 #include <utils/fileutils.h>
29 
30 using namespace Qnx;
31 using namespace Qnx::Internal;
32 
QnxDeviceProcessSignalOperation(const QSsh::SshConnectionParameters & sshParameters)33 QnxDeviceProcessSignalOperation::QnxDeviceProcessSignalOperation(
34         const QSsh::SshConnectionParameters &sshParameters)
35     : RemoteLinux::RemoteLinuxSignalOperation(sshParameters)
36 {
37 }
38 
signalProcessByNameQnxCommandLine(const QString & filePath,int sig)39 static QString signalProcessByNameQnxCommandLine(const QString &filePath, int sig)
40 {
41     QString executable = filePath;
42     return QString::fromLatin1("for PID in $(ps -f -o pid,comm | grep %1 | awk '/%1/ {print $1}'); "
43         "do "
44             "kill -%2 $PID; "
45         "done").arg(executable.replace(QLatin1String("/"), QLatin1String("\\/"))).arg(sig);
46 }
47 
killProcessByNameCommandLine(const QString & filePath) const48 QString QnxDeviceProcessSignalOperation::killProcessByNameCommandLine(
49         const QString &filePath) const
50 {
51     return QString::fromLatin1("%1; %2").arg(signalProcessByNameQnxCommandLine(filePath, 15),
52                                            signalProcessByNameQnxCommandLine(filePath, 9));
53 }
54 
interruptProcessByNameCommandLine(const QString & filePath) const55 QString QnxDeviceProcessSignalOperation::interruptProcessByNameCommandLine(
56         const QString &filePath) const
57 {
58     return signalProcessByNameQnxCommandLine(filePath, 2);
59 }
60