Commit efb19505 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Bug #44775 MTR fails to bootstrap mysqld on Windows in Pushbuild 2.

Suspected reason for the failure is that safe_process.exe already runs in a job that does not allow breakaways. 
The fix is to use a fallback -  make newly created process the root of the new process group. This allows to kill process together with descendants via GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid)
parent 3e6f1f27
......@@ -259,22 +259,37 @@ int main(int argc, const char** argv )
the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag, making sure it will be
terminated when the last handle to it is closed(which is owned by
this process).
If breakaway from job fails on some reason, fallback is to create a
new process group. Process groups also allow to kill process and its
descedants, subject to some restrictions (processes have to run within
the same console,and must not ignore CTRL_BREAK)
*/
if (CreateProcess(NULL, (LPSTR)child_args,
DWORD create_flags[]= {CREATE_BREAKAWAY_FROM_JOB, CREATE_NEW_PROCESS_GROUP, 0};
BOOL process_created= FALSE;
BOOL jobobject_assigned= FALSE;
for (int i=0; i < sizeof(create_flags)/sizeof(create_flags[0]); i++)
{
process_created= CreateProcess(NULL, (LPSTR)child_args,
NULL,
NULL,
TRUE, /* inherit handles */
CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB,
CREATE_SUSPENDED | create_flags[i],
NULL,
NULL,
&si,
&process_info) == 0)
die("CreateProcess failed");
&process_info);
if (process_created)
{
jobobject_assigned= AssignProcessToJobObject(job_handle, process_info.hProcess);
break;
}
}
if (AssignProcessToJobObject(job_handle, process_info.hProcess) == 0)
if (!process_created)
{
TerminateProcess(process_info.hProcess, 200);
die("AssignProcessToJobObject failed");
die("CreateProcess failed");
}
ResumeThread(process_info.hThread);
CloseHandle(process_info.hThread);
......@@ -312,6 +327,13 @@ int main(int argc, const char** argv )
message("TerminateJobObject failed");
CloseHandle(job_handle);
message("Job terminated and closed");
if (!jobobject_assigned)
{
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process_info.dwProcessId);
TerminateProcess(process_info.hProcess, 202);
}
if (wait_res != WAIT_OBJECT_0 + CHILD)
{
/* The child has not yet returned, wait for it */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment