Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: base/process_util_win.cc

Issue 7789018: Move launching in a job object logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.h ('k') | net/test/test_server_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_win.cc
===================================================================
--- base/process_util_win.cc (revision 99780)
+++ base/process_util_win.cc (working copy)
@@ -237,8 +237,19 @@
startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
PROCESS_INFORMATION process_info;
+ DWORD flags = 0;
+
+ if (options.job_handle) {
+ flags |= CREATE_SUSPENDED;
+
+ // If this code is run under a debugger, the launched process is
+ // automatically associated with a job object created by the debugger.
+ // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this.
+ flags |= CREATE_BREAKAWAY_FROM_JOB;
+ }
+
if (options.as_user) {
- DWORD flags = CREATE_UNICODE_ENVIRONMENT;
+ flags |= CREATE_UNICODE_ENVIRONMENT;
void* enviroment_block = NULL;
if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE))
@@ -256,12 +267,23 @@
} else {
if (!CreateProcess(NULL,
const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
- options.inherit_handles, 0, NULL, NULL,
+ options.inherit_handles, flags, NULL, NULL,
&startup_info, &process_info)) {
return false;
}
}
+ if (options.job_handle) {
+ if (0 == AssignProcessToJobObject(options.job_handle,
+ process_info.hProcess)) {
+ LOG(ERROR) << "Could not AssignProcessToObject.";
+ KillProcess(process_info.hProcess, kProcessKilledExitCode, true);
+ return false;
+ }
+
+ ResumeThread(process_info.hThread);
+ }
+
// Handles must be closed or they will leak.
CloseHandle(process_info.hThread);
« no previous file with comments | « base/process_util.h ('k') | net/test/test_server_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698