155 lines
4.2 KiB
Diff
155 lines
4.2 KiB
Diff
From 29bc721fee1e6a56fede0274ad5c94db70c6e33e Mon Sep 17 00:00:00 2001
|
|
From: Ray Donnelly <mingw.android@gmail.com>
|
|
Date: Sat, 27 Sep 2014 14:57:41 +0100
|
|
Subject: [PATCH 01/14] Use Q_PID instead of int, reducing QProcess repitition
|
|
|
|
Process ids are not ints on all systems
|
|
---
|
|
src/utils.cpp | 70 +++++++++++++++++++++++++++++++++++------------------------
|
|
src/utils.h | 6 ++---
|
|
2 files changed, 45 insertions(+), 31 deletions(-)
|
|
|
|
diff --git a/src/utils.cpp b/src/utils.cpp
|
|
index 6d56ea7..80abf6c 100644
|
|
--- a/src/utils.cpp
|
|
+++ b/src/utils.cpp
|
|
@@ -89,6 +89,38 @@ void utils::ProcessWrapper::onProcessStarted()
|
|
emit startedTerminal();
|
|
}
|
|
|
|
+QString Ps_To_Q_PIDs(QString ps_args)
|
|
+{
|
|
+ QString out;
|
|
+ QProcess proc;
|
|
+ proc.start(ps_args);
|
|
+ proc.waitForFinished(-1);
|
|
+ out = proc.readAll();
|
|
+ proc.close();
|
|
+ return out;
|
|
+}
|
|
+
|
|
+QStringList Ps_To_Q_PIDs_SL(QString ps_args)
|
|
+{
|
|
+ QString out = Ps_To_Q_PIDs(ps_args);
|
|
+ QStringList list = out.split("\n", QString::SkipEmptyParts);
|
|
+ return list;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * Returns the _PROCESS_INFORMATION* on Windows, does nothing on
|
|
+ * others.
|
|
+ */
|
|
+Q_PID int_to_Q_PID(int in_pid)
|
|
+{
|
|
+ return in_pid;
|
|
+}
|
|
+
|
|
+int Q_PID_to_int(Q_PID in_pid)
|
|
+{
|
|
+ return in_pid;
|
|
+}
|
|
+
|
|
/*
|
|
* We need this to search for the SH process pid (which spaws AUR tool)
|
|
*/
|
|
@@ -98,21 +130,11 @@ void utils::ProcessWrapper::onSingleShot()
|
|
QProcess pAux;
|
|
QString saux;
|
|
|
|
- proc.start("ps -o pid -C sh");
|
|
- proc.waitForFinished(-1);
|
|
- QString out = proc.readAll();
|
|
- proc.close();
|
|
-
|
|
- QStringList list = out.split("\n", QString::SkipEmptyParts);
|
|
+ QStringList list = Ps_To_Q_PIDs_SL(QLatin1String("ps -o pid -C sh"));
|
|
|
|
if (list.count() == 1)
|
|
{
|
|
- proc.start("ps -o pid -C " + UnixCommand::getShell());
|
|
- proc.waitForFinished(-1);
|
|
- out = proc.readAll();
|
|
- proc.close();
|
|
-
|
|
- list = out.split("\n", QString::SkipEmptyParts);
|
|
+ list = Ps_To_Q_PIDs_SL(QLatin1String("ps -o pid -C ") + UnixCommand::getShell());
|
|
}
|
|
|
|
QStringList slist;
|
|
@@ -121,12 +143,10 @@ void utils::ProcessWrapper::onSingleShot()
|
|
{
|
|
int candidatePid = list.at(c).trimmed().toInt();
|
|
|
|
- if (candidatePid < m_pidTerminal) continue;
|
|
+ // Determine if candidatePid is a child of m_pidTerminal
|
|
+ if (candidatePid < Q_PID_to_int(m_pidTerminal)) continue;
|
|
|
|
- QString cmd = QString("ps -O cmd --ppid %1").arg(candidatePid);
|
|
- proc.start(cmd);
|
|
- proc.waitForFinished(-1);
|
|
- QString out = proc.readAll();
|
|
+ QString out = Ps_To_Q_PIDs(QString("ps -O cmd --ppid %1").arg(candidatePid));
|
|
|
|
if (UnixCommand::getLinuxDistro() == ectn_KAOS)
|
|
{
|
|
@@ -143,8 +163,8 @@ void utils::ProcessWrapper::onSingleShot()
|
|
|
|
if (candidatePid < candidatePid2)
|
|
{
|
|
- m_pidSH = candidatePid;
|
|
- m_pidAUR = candidatePid2;
|
|
+ m_pidSH = int_to_Q_PID(candidatePid);
|
|
+ m_pidAUR = int_to_Q_PID(candidatePid2);
|
|
m_timer->start();
|
|
|
|
return;
|
|
@@ -167,8 +187,8 @@ void utils::ProcessWrapper::onSingleShot()
|
|
|
|
if (candidatePid < candidatePid2)
|
|
{
|
|
- m_pidSH = candidatePid;
|
|
- m_pidAUR = candidatePid2;
|
|
+ m_pidSH = int_to_Q_PID(candidatePid);
|
|
+ m_pidAUR = int_to_Q_PID(candidatePid2);
|
|
m_timer->start();
|
|
|
|
return;
|
|
@@ -187,16 +207,10 @@ void utils::ProcessWrapper::onSingleShot()
|
|
void utils::ProcessWrapper::onTimer()
|
|
{
|
|
QProcess proc;
|
|
- QString cmd = QString("ps -p %1 %2").arg(m_pidSH).arg(m_pidAUR);
|
|
+ QString out = Ps_To_Q_PIDs(QString("ps -p %1 %2").arg(Q_PID_to_int(m_pidSH)).arg(Q_PID_to_int(m_pidAUR)));
|
|
|
|
//std::cout << "PIDS: " << cmd.toLatin1().data() << "\n" << std::endl;
|
|
|
|
- proc.start(cmd);
|
|
- proc.waitForFinished(-1);
|
|
-
|
|
- //If any of the processes have finished...
|
|
- QString out = proc.readAll();
|
|
-
|
|
//std::cout << "Output: " << out.toLatin1().data() << "\n" << std::endl;
|
|
|
|
if (!out.contains(".qt_temp_", Qt::CaseInsensitive))
|
|
diff --git a/src/utils.h b/src/utils.h
|
|
index b5e4d33..bf206f3 100644
|
|
--- a/src/utils.h
|
|
+++ b/src/utils.h
|
|
@@ -40,9 +40,9 @@ class ProcessWrapper : public QObject
|
|
Q_OBJECT
|
|
|
|
private:
|
|
- int m_pidTerminal;
|
|
- int m_pidSH;
|
|
- int m_pidAUR;
|
|
+ Q_PID m_pidTerminal;
|
|
+ Q_PID m_pidSH;
|
|
+ Q_PID m_pidAUR;
|
|
QProcess *m_process;
|
|
QTimer *m_timer;
|
|
QTimer *m_timerSingleShot;
|
|
--
|
|
2.8.2
|
|
|