mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
Implement shutdown with parent for Mac and Linux
This commit is contained in:
parent
366ce69e66
commit
2d246d2563
1 changed files with 22 additions and 6 deletions
|
@ -47,6 +47,7 @@ extern "C" FILE * __cdecl __iob_func(void) {
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QTimer>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
@ -1077,14 +1078,20 @@ void setMaxCores(uint8_t maxCores) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
void quitWithParentProcess() {
|
||||||
VOID CALLBACK parentDiedCallback(PVOID lpParameter, BOOLEAN timerOrWaitFired) {
|
if (qApp) {
|
||||||
if (!timerOrWaitFired && qApp) {
|
|
||||||
qDebug() << "Parent process died, quitting";
|
qDebug() << "Parent process died, quitting";
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
VOID CALLBACK parentDiedCallback(PVOID lpParameter, BOOLEAN timerOrWaitFired) {
|
||||||
|
if (!timerOrWaitFired) {
|
||||||
|
quitWithParentProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void watchParentProcess(int parentPID) {
|
void watchParentProcess(int parentPID) {
|
||||||
DWORD processID = parentPID;
|
DWORD processID = parentPID;
|
||||||
HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
|
HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
|
||||||
|
@ -1092,8 +1099,17 @@ void watchParentProcess(int parentPID) {
|
||||||
HANDLE newHandle;
|
HANDLE newHandle;
|
||||||
RegisterWaitForSingleObject(&newHandle, procHandle, parentDiedCallback, NULL, INFINITE, WT_EXECUTEONLYONCE);
|
RegisterWaitForSingleObject(&newHandle, procHandle, parentDiedCallback, NULL, INFINITE, WT_EXECUTEONLYONCE);
|
||||||
}
|
}
|
||||||
#else
|
#elif defined(Q_OS_MAC) || defined(Q_OS_LINUX)
|
||||||
void watchParentProcess(int parentPID) {
|
void watchParentProcess(int parentPID) {
|
||||||
qWarning() << "Parent PID option not implemented on this plateform";
|
auto timer = new QTimer(qApp);
|
||||||
|
timer->setInterval(MSECS_PER_SECOND);
|
||||||
|
QObject::connect(timer, &QTimer::timeout, qApp, [parentPID]() {
|
||||||
|
auto ppid = getppid();
|
||||||
|
if (parentPID != ppid) {
|
||||||
|
// If the PPID changed, then that means our parent process died.
|
||||||
|
quitWithParentProcess();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer->start();
|
||||||
}
|
}
|
||||||
#endif // Q_OS_WIN
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue