diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /NonInheritingProcess.cpp | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'NonInheritingProcess.cpp')
| -rw-r--r-- | NonInheritingProcess.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/NonInheritingProcess.cpp b/NonInheritingProcess.cpp index 7f5644d5..5501f5a2 100644 --- a/NonInheritingProcess.cpp +++ b/NonInheritingProcess.cpp @@ -43,6 +43,44 @@ class NonInheritingProcess::impl { public: #ifdef Q_OS_WIN + impl () + : job_ {nullptr} + { + job_ = ::CreateJobObjectW (nullptr, nullptr); + if (job_) + { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits {}; + limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if (!::SetInformationJobObject (job_, JobObjectExtendedLimitInformation, + &limits, sizeof limits)) + { + ::CloseHandle (job_); + job_ = nullptr; + } + } + } + + ~impl () + { + if (job_) + { + ::CloseHandle (job_); + } + } + + void assign_to_job (qint64 process_id) + { + if (!job_ || process_id <= 0) return; + + HANDLE process = ::OpenProcess (PROCESS_SET_QUOTA | PROCESS_TERMINATE, + FALSE, static_cast<DWORD> (process_id)); + if (process) + { + ::AssignProcessToJobObject (job_, process); + ::CloseHandle (process); + } + } + void extend_CreateProcessArguments (QProcess::CreateProcessArguments * args) { // @@ -95,6 +133,7 @@ public: using start_info_type = std::unique_ptr<STARTUPINFOEXW, start_info_deleter>; start_info_type start_info_; + HANDLE job_; #endif }; @@ -105,7 +144,10 @@ NonInheritingProcess::NonInheritingProcess (QObject * parent) using namespace std::placeholders; // enable cleanup after process starts or fails to start - connect (this, &QProcess::started, [this] {m_->start_info_.reset ();}); + connect (this, &QProcess::started, [this] { + m_->start_info_.reset (); + m_->assign_to_job (processId ()); + }); connect (this, &QProcess::errorOccurred, [this] (QProcess::ProcessError) {m_->start_info_.reset ();}); setCreateProcessArgumentsModifier (std::bind (&NonInheritingProcess::impl::extend_CreateProcessArguments, &*m_, _1)); #endif |
