145 lines
3.6 KiB
Diff
145 lines
3.6 KiB
Diff
From 49a60231f41bcbfe02bb7181935943e799d0e5be Mon Sep 17 00:00:00 2001
|
|
From: Ray Donnelly <mingw.android@gmail.com>
|
|
Date: Sat, 27 Sep 2014 15:44:22 +0100
|
|
Subject: [PATCH 12/14] MSYS2: Process id changes (WIP)
|
|
|
|
---
|
|
notifier/octopi-notifier/octopi-notifier.pro | 2 +
|
|
src/utils.cpp | 77 ++++++++++++++++++++++++++++
|
|
2 files changed, 79 insertions(+)
|
|
|
|
diff --git a/notifier/octopi-notifier/octopi-notifier.pro b/notifier/octopi-notifier/octopi-notifier.pro
|
|
index 5dfb2a6..48372e4 100644
|
|
--- a/notifier/octopi-notifier/octopi-notifier.pro
|
|
+++ b/notifier/octopi-notifier/octopi-notifier.pro
|
|
@@ -60,6 +60,8 @@ HEADERS += \
|
|
../../src/searchlineedit.h \
|
|
../../src/searchbar.h
|
|
|
|
+win32: LIBS += -lwtsapi32
|
|
+
|
|
FORMS += ../../ui/transactiondialog.ui \
|
|
ui/setupdialog.ui
|
|
|
|
diff --git a/src/utils.cpp b/src/utils.cpp
|
|
index 23680fd..ae48504 100644
|
|
--- a/src/utils.cpp
|
|
+++ b/src/utils.cpp
|
|
@@ -38,6 +38,12 @@
|
|
#include <QProcess>
|
|
#include <QTimer>
|
|
#include <QTextBrowser>
|
|
+#include <QDebug>
|
|
+
|
|
+#if defined(Q_OS_WIN)
|
|
+#include <windows.h>
|
|
+#include <wtsapi32.h>
|
|
+#endif
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
#include <QScreen>
|
|
@@ -89,8 +95,63 @@ void utils::ProcessWrapper::onProcessStarted()
|
|
emit startedTerminal();
|
|
}
|
|
|
|
+#if defined(Q_OS_WIN)
|
|
+QString Ps_To_Q_PIDs(QString ps_args)
|
|
+{
|
|
+ QString ps_name;
|
|
+ QString out;
|
|
+ QStringList in_pids;
|
|
+ if (ps_args.startsWith(QLatin1String("ps -o pid -C")))
|
|
+ {
|
|
+ ps_name = ps_args.remove(QLatin1String("ps -o pid -C")).trimmed();
|
|
+ }
|
|
+ else if (ps_args.startsWith(QLatin1String("ps -O cmd --ppid")))
|
|
+ {
|
|
+ in_pids.append(ps_args.remove("ps -O cmd --ppid").trimmed());
|
|
+ }
|
|
+ else if (ps_args.startsWith(QLatin1String("ps -p")))
|
|
+ {
|
|
+ QString temp = ps_args.remove("ps -p").trimmed();
|
|
+ QTextStream pid_args(&temp);
|
|
+ while (!pid_args.atEnd())
|
|
+ {
|
|
+ QString a_pid;
|
|
+ pid_args >> a_pid;
|
|
+ in_pids.append(a_pid);
|
|
+ }
|
|
+ }
|
|
+ WTS_PROCESS_INFO* pProcessInfo = 0;
|
|
+ DWORD Count;
|
|
+ if(WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pProcessInfo, &Count))
|
|
+ {
|
|
+ for(DWORD i = 0; i < Count; i++)
|
|
+ {
|
|
+ qDebug() << pProcessInfo[i].pProcessName << "\tPID="
|
|
+ << pProcessInfo[i].ProcessId << "\tSess="
|
|
+ << pProcessInfo[i].SessionId;
|
|
+ QString process_name = QString::fromWCharArray(pProcessInfo[i].pProcessName);
|
|
+ if (!ps_name.isEmpty())
|
|
+ {
|
|
+ out += QLatin1String("PID\n");
|
|
+ if (ps_name == process_name)
|
|
+ {
|
|
+ out += QString::number(pProcessInfo[i].ProcessId) + QLatin1String("\n");
|
|
+ return out;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+// BOOL WINAPI EnumProcesses(
|
|
+// _Out_ DWORD *pProcessIds,
|
|
+// _In_ DWORD cb,
|
|
+// _Out_ DWORD *pBytesReturned
|
|
+// );
|
|
+ }
|
|
+ return out;
|
|
+}
|
|
+#else /* !defined(Q_OS_WIN) */
|
|
QString Ps_To_Q_PIDs(QString ps_args)
|
|
{
|
|
+ QStringList list;
|
|
QString out;
|
|
QProcess proc;
|
|
proc.start(ps_args);
|
|
@@ -99,6 +160,7 @@ QString Ps_To_Q_PIDs(QString ps_args)
|
|
proc.close();
|
|
return out;
|
|
}
|
|
+#endif /* defined(Q_OS_WIN) */
|
|
|
|
QStringList Ps_To_Q_PIDs_SL(QString ps_args)
|
|
{
|
|
@@ -107,6 +169,20 @@ QStringList Ps_To_Q_PIDs_SL(QString ps_args)
|
|
return list;
|
|
}
|
|
|
|
+#if defined(Q_OS_WIN)
|
|
+Q_PID int_to_Q_PID(int in_pid)
|
|
+{
|
|
+ Q_UNUSED(in_pid);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int Q_PID_to_int(Q_PID in_pid)
|
|
+{
|
|
+ Q_UNUSED(in_pid);
|
|
+ return 1;
|
|
+}
|
|
+
|
|
+#else
|
|
/*
|
|
* Returns the _PROCESS_INFORMATION* on Windows, does nothing on
|
|
* others.
|
|
@@ -120,6 +196,7 @@ int Q_PID_to_int(Q_PID in_pid)
|
|
{
|
|
return in_pid;
|
|
}
|
|
+#endif
|
|
|
|
/*
|
|
* We need this to search for the SH process pid (which spaws AUR tool)
|
|
--
|
|
2.8.2
|
|
|