mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
CR
This commit is contained in:
parent
6b5b905b2a
commit
b31118fe00
2 changed files with 15 additions and 15 deletions
|
@ -1116,39 +1116,39 @@ void watchParentProcess(int parentPID) {
|
||||||
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString GetLastErrorAsString() {
|
QString getLastErrorAsString() {
|
||||||
//Get the error message, if any.
|
|
||||||
DWORD errorMessageID = ::GetLastError();
|
DWORD errorMessageID = ::GetLastError();
|
||||||
if (errorMessageID == 0)
|
if (errorMessageID == 0) {
|
||||||
return QString(); //No error message has been recorded
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
LPSTR messageBuffer = nullptr;
|
LPSTR messageBuffer = nullptr;
|
||||||
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
|
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
|
||||||
|
|
||||||
std::string message(messageBuffer, size);
|
auto message = QString::fromLocal8Bit(messageBuffer, (int)size);
|
||||||
|
|
||||||
//Free the buffer.
|
//Free the buffer.
|
||||||
LocalFree(messageBuffer);
|
LocalFree(messageBuffer);
|
||||||
|
|
||||||
return QString::fromStdString(message);
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *createJobObject() {
|
void* createJobObject() {
|
||||||
HANDLE jobObject = CreateJobObject(nullptr, nullptr);
|
HANDLE jobObject = CreateJobObject(nullptr, nullptr);
|
||||||
if (jobObject == nullptr) {
|
if (jobObject == nullptr) {
|
||||||
qWarning() << "Could NOT create job object:" << GetLastErrorAsString();
|
qWarning() << "Could NOT create job object:" << getLastErrorAsString();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION JELI;
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION JELI;
|
||||||
if (!QueryInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI), nullptr)) {
|
if (!QueryInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI), nullptr)) {
|
||||||
qWarning() << "Could NOT query job object information" << GetLastErrorAsString();
|
qWarning() << "Could NOT query job object information" << getLastErrorAsString();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
JELI.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
JELI.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
||||||
if (!SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI))) {
|
if (!SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI))) {
|
||||||
qWarning() << "Could NOT set job object information" << GetLastErrorAsString();
|
qWarning() << "Could NOT set job object information" << getLastErrorAsString();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,10 +1158,10 @@ void *createJobObject() {
|
||||||
void addProcessToJobObject(void *jobObject, qint64 processId) {
|
void addProcessToJobObject(void *jobObject, qint64 processId) {
|
||||||
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
|
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
|
||||||
if (hProcess == nullptr) {
|
if (hProcess == nullptr) {
|
||||||
qCritical() << "Could NOT open process" << GetLastErrorAsString();
|
qCritical() << "Could NOT open process" << getLastErrorAsString();
|
||||||
}
|
}
|
||||||
if (!AssignProcessToJobObject(jobObject, hProcess)) {
|
if (!AssignProcessToJobObject(jobObject, hProcess)) {
|
||||||
qCritical() << "Could NOT assign process to job object" << GetLastErrorAsString();
|
qCritical() << "Could NOT assign process to job object" << getLastErrorAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,9 +239,9 @@ const QString PARENT_PID_OPTION = "parent-pid";
|
||||||
void watchParentProcess(int parentPID);
|
void watchParentProcess(int parentPID);
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef Q_OS_WIN
|
||||||
void *createJobObject();
|
void* createJobObject();
|
||||||
void addProcessToJobObject(void *jobObject, qint64 processId);
|
void addProcessToJobObject(void* jobObject, qint64 processId);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // hifi_SharedUtil_h
|
#endif // hifi_SharedUtil_h
|
||||||
|
|
Loading…
Reference in a new issue