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

Side by Side Diff: net/socket/ssl_test_util.cc

Issue 2344001: Restricting lifetime of python sync server on Windows via a JobObject. (Closed)
Patch Set: Cleaning up more ^Ms I found in the file. Created 10 years, 6 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 unified diff | Download patch
« no previous file with comments | « net/socket/ssl_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/ssl_test_util.h" 5 #include "net/socket/ssl_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 command_line.append(L"\""); 177 command_line.append(L"\"");
178 } 178 }
179 if (!file_root_url.empty()) { 179 if (!file_root_url.empty()) {
180 command_line.append(L" --file-root-url=\""); 180 command_line.append(L" --file-root-url=\"");
181 command_line.append(file_root_url); 181 command_line.append(file_root_url);
182 command_line.append(L"\""); 182 command_line.append(L"\"");
183 } 183 }
184 // Deliberately do not pass the --forking flag. It breaks the tests 184 // Deliberately do not pass the --forking flag. It breaks the tests
185 // on Windows. 185 // on Windows.
186 186
187 if (!base::LaunchApp(command_line, false, true, &process_handle_)) { 187 if (!LaunchTestServerAsJob(command_line,
188 true,
189 &process_handle_,
190 &job_handle_)) {
188 LOG(ERROR) << "Failed to launch " << command_line; 191 LOG(ERROR) << "Failed to launch " << command_line;
189 return false; 192 return false;
190 } 193 }
191 #elif defined(OS_POSIX) 194 #elif defined(OS_POSIX)
192 std::vector<std::string> command_line; 195 std::vector<std::string> command_line;
193 command_line.push_back("python"); 196 command_line.push_back("python");
194 command_line.push_back(testserver_path.value()); 197 command_line.push_back(testserver_path.value());
195 command_line.push_back("--port=" + port_str); 198 command_line.push_back("--port=" + port_str);
196 command_line.push_back("--data-dir=" + document_root_dir_.value()); 199 command_line.push_back("--data-dir=" + document_root_dir_.value());
197 if (protocol == ProtoFTP) 200 if (protocol == ProtoFTP)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca " 349 LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca "
347 "certificate to your trusted roots for this test to work. " 350 "certificate to your trusted roots for this test to work. "
348 "For more info visit:\n" 351 "For more info visit:\n"
349 "http://dev.chromium.org/developers/testing\n"; 352 "http://dev.chromium.org/developers/testing\n";
350 return false; 353 return false;
351 } 354 }
352 #endif 355 #endif
353 return true; 356 return true;
354 } 357 }
355 358
359 #if defined(OS_WIN)
360 bool LaunchTestServerAsJob(const std::wstring& cmdline,
361 bool start_hidden,
362 base::ProcessHandle* process_handle,
363 ScopedHandle* job_handle) {
364 // Launch test server process.
365 STARTUPINFO startup_info = {0};
366 startup_info.cb = sizeof(startup_info);
367 startup_info.dwFlags = STARTF_USESHOWWINDOW;
368 startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW;
369 PROCESS_INFORMATION process_info;
370
371 // If this code is run under a debugger, the test server process is
372 // automatically associated with a job object created by the debugger.
373 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this.
374 if (!CreateProcess(NULL,
375 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
376 FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL,
377 &startup_info, &process_info)) {
378 LOG(ERROR) << "Could not create process.";
379 return false;
380 }
381 CloseHandle(process_info.hThread);
382
383 // If the caller wants the process handle, we won't close it.
384 if (process_handle) {
385 *process_handle = process_info.hProcess;
386 } else {
387 CloseHandle(process_info.hProcess);
388 }
389
390 // Create a JobObject and associate the test server process with it.
391 job_handle->Set(CreateJobObject(NULL, NULL));
392 if (!job_handle->IsValid()) {
393 LOG(ERROR) << "Could not create JobObject.";
394 return false;
395 } else {
396 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
397 limit_info.BasicLimitInformation.LimitFlags =
398 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
399 if (0 == SetInformationJobObject(job_handle->Get(),
400 JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) {
401 LOG(ERROR) << "Could not SetInformationJobObject.";
402 return false;
403 }
404 if (0 == AssignProcessToJobObject(job_handle->Get(),
405 process_info.hProcess)) {
406 LOG(ERROR) << "Could not AssignProcessToObject.";
407 return false;
408 }
409 }
410 return true;
411 }
412 #endif
413
356 } // namespace net 414 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698