diff options
| author | Tannin <devnull@localhost> | 2014-07-15 20:45:29 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-07-15 20:45:29 +0200 |
| commit | 0a152ceadfc90650359b15dc448751f702e1070c (patch) | |
| tree | 02e468fb58330d25fd765974e48ab681bf360cab /src/spawn.cpp | |
| parent | d412060d59b1597ae1d11d793662610e90863fc9 (diff) | |
| parent | 5718af351034c1936a91a3782651733dfecdc4e5 (diff) | |
Merge
Diffstat (limited to 'src/spawn.cpp')
| -rw-r--r-- | src/spawn.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp index 6adafba0..d314a326 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -88,7 +88,7 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus commandLine, NULL, NULL, // no special process or thread attributes inheritHandles, // inherit handles if we plan to use stdout or stderr reroute - suspended ? CREATE_SUSPENDED : 0, // create suspended so I have time to inject the DLL + CREATE_BREAKAWAY_FROM_JOB | (suspended ? CREATE_SUSPENDED : 0), // create suspended so I have time to inject the DLL NULL, // same environment as parent currentDirectory, // current directory &si, &pi // startup and process information @@ -117,12 +117,18 @@ HANDLE startBinary(const QFileInfo &binary, HANDLE stdOut, HANDLE stdErr) { + HANDLE jobObject = ::CreateJobObject(NULL, NULL); + + if (jobObject == NULL) { + qWarning("failed to create job object: %lu", ::GetLastError()); + } + HANDLE processHandle, threadHandle; std::wstring binaryName = ToWString(QDir::toNativeSeparators(binary.absoluteFilePath())); std::wstring currentDirectoryName = ToWString(QDir::toNativeSeparators(currentDirectory.absolutePath())); try { - if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), hooked, + if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), true, stdOut, stdErr, processHandle, threadHandle)) { reportError(QObject::tr("failed to spawn \"%1\"").arg(binary.fileName())); return INVALID_HANDLE_VALUE; @@ -170,12 +176,22 @@ HANDLE startBinary(const QFileInfo &binary, #ifdef _DEBUG reportError("ready?"); #endif // DEBUG - if (::ResumeThread(threadHandle) == (DWORD)-1) { - reportError(QObject::tr("failed to run \"%1\"").arg(binary.fileName())); - return INVALID_HANDLE_VALUE; - } } - return processHandle; + + if (::AssignProcessToJobObject(jobObject, processHandle) == 0) { + qWarning("failed to assign to job object: %lu", ::GetLastError()); + ::CloseHandle(jobObject); + jobObject = processHandle; + } else { + ::CloseHandle(processHandle); + } + + if (::ResumeThread(threadHandle) == (DWORD)-1) { + reportError(QObject::tr("failed to run \"%1\"").arg(binary.fileName())); + return INVALID_HANDLE_VALUE; + } + ::CloseHandle(threadHandle); + return jobObject; } /* |
