summaryrefslogtreecommitdiff
path: root/mysql-test/lib/My/SafeProcess
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2009-05-14 21:56:53 +0200
committerVladislav Vaintroub <vvaintroub@mysql.com>2009-05-14 21:56:53 +0200
commitefb195051a3d26ee68162001759e992255df90d9 (patch)
treeb353a404778c5905d4568836b612b5f5d1437057 /mysql-test/lib/My/SafeProcess
parent3e6f1f27638fed9f842b910c7bd5e1062738b828 (diff)
downloadmariadb-git-efb195051a3d26ee68162001759e992255df90d9.tar.gz
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)
Diffstat (limited to 'mysql-test/lib/My/SafeProcess')
-rwxr-xr-xmysql-test/lib/My/SafeProcess/safe_process_win.cc36
1 files changed, 29 insertions, 7 deletions
diff --git a/mysql-test/lib/My/SafeProcess/safe_process_win.cc b/mysql-test/lib/My/SafeProcess/safe_process_win.cc
index 4fb89f098ed..80c1b7a97f2 100755
--- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc
+++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc
@@ -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 */