mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-19 14:36:38 -05:00
Avoid creating a redundant Windows Job Object when already running inside an existing job
This commit is contained in:
parent
ccf095a6f8
commit
029c3940fe
1 changed files with 26 additions and 14 deletions
40
os/mingw.c
40
os/mingw.c
|
|
@ -4661,21 +4661,33 @@ void os_init(unsigned opt)
|
|||
os_exit();
|
||||
}
|
||||
|
||||
/* initialize job object to terminate child processes if daemon dies */
|
||||
os_job_handle = CreateJobObjectW(0, 0);
|
||||
if (os_job_handle != 0) {
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
|
||||
ZeroMemory(&info, sizeof(info));
|
||||
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
||||
if (!SetInformationJobObject(os_job_handle, JobObjectExtendedLimitInformation, &info, sizeof(info))) {
|
||||
windows_errno(GetLastError());
|
||||
os_syslog(OS_LVL_WARNING, "failed to configure job object, errno=%s(%d)", strerror(errno), errno);
|
||||
CloseHandle(os_job_handle);
|
||||
os_job_handle = 0;
|
||||
}
|
||||
/*
|
||||
* Skip creating a separate job object if already running inside one
|
||||
* (e.g. spawned by snapraid-daemon, a service, or Task Scheduler).
|
||||
* Child processes automatically inherit the parent's job object, and
|
||||
* attempting to assign them to a second independent job object would
|
||||
* fail with ERROR_ACCESS_DENIED.
|
||||
*/
|
||||
BOOL in_job = 0;
|
||||
if (IsProcessInJob(GetCurrentProcess(), 0, &in_job) && in_job) {
|
||||
os_job_handle = 0;
|
||||
} else {
|
||||
windows_errno(GetLastError());
|
||||
os_syslog(OS_LVL_WARNING, "failed to create job object, errno=%s(%d)", strerror(errno), errno);
|
||||
/* initialize job object to terminate child processes if daemon dies */
|
||||
os_job_handle = CreateJobObjectW(0, 0);
|
||||
if (os_job_handle != 0) {
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
|
||||
ZeroMemory(&info, sizeof(info));
|
||||
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
||||
if (!SetInformationJobObject(os_job_handle, JobObjectExtendedLimitInformation, &info, sizeof(info))) {
|
||||
windows_errno(GetLastError());
|
||||
os_syslog(OS_LVL_WARNING, "failed to configure job object, errno=%s(%d)", strerror(errno), errno);
|
||||
CloseHandle(os_job_handle);
|
||||
os_job_handle = 0;
|
||||
}
|
||||
} else {
|
||||
windows_errno(GetLastError());
|
||||
os_syslog(OS_LVL_WARNING, "failed to create job object, errno=%s(%d)", strerror(errno), errno);
|
||||
}
|
||||
}
|
||||
|
||||
/* check for Wine presence */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue