This commit is contained in:
Atlante45 2017-11-14 17:14:49 -08:00
parent e68ce97697
commit d8b1cb10df
3 changed files with 9 additions and 8 deletions

View file

@ -29,7 +29,7 @@ const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor
const int WAIT_FOR_CHILD_MSECS = 1000;
#ifdef Q_OS_WIN
HANDLE JOB_OBJECT = createJobObject();
HANDLE PROCESS_GROUP = createProcessGroup();
#endif
AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmentClientForks,
@ -207,7 +207,7 @@ void AssignmentClientMonitor::spawnChildClient() {
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
#ifdef Q_OS_WIN
addProcessToJobObject(JOB_OBJECT, assignmentClient->processId());
addProcessToGroup(PROCESS_GROUP, assignmentClient->processId());
#endif
QString stdoutPath, stderrPath;

View file

@ -1124,7 +1124,7 @@ QString getLastErrorAsString() {
LPSTR messageBuffer = nullptr;
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);
nullptr, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, nullptr);
auto message = QString::fromLocal8Bit(messageBuffer, (int)size);
@ -1134,7 +1134,8 @@ QString getLastErrorAsString() {
return message;
}
void* createJobObject() {
// All processes in the group will shut down with the process creating the group
void* createProcessGroup() {
HANDLE jobObject = CreateJobObject(nullptr, nullptr);
if (jobObject == nullptr) {
qWarning() << "Could NOT create job object:" << getLastErrorAsString();
@ -1155,12 +1156,12 @@ void* createJobObject() {
return jobObject;
}
void addProcessToJobObject(void *jobObject, qint64 processId) {
void addProcessToGroup(void* processGroup, qint64 processId) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (hProcess == nullptr) {
qCritical() << "Could NOT open process" << getLastErrorAsString();
}
if (!AssignProcessToJobObject(jobObject, hProcess)) {
if (!AssignProcessToJobObject(processGroup, hProcess)) {
qCritical() << "Could NOT assign process to job object" << getLastErrorAsString();
}
}

View file

@ -240,8 +240,8 @@ void watchParentProcess(int parentPID);
#ifdef Q_OS_WIN
void* createJobObject();
void addProcessToJobObject(void* jobObject, qint64 processId);
void* createProcessGroup();
void addProcessToGroup(void* processGroup, qint64 processId);
#endif
#endif // hifi_SharedUtil_h