| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <process.h> | 5 #include <process.h> |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
| 10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 startup_info.dwFlags |= STARTF_USESTDHANDLES; | 553 startup_info.dwFlags |= STARTF_USESTDHANDLES; |
| 554 | 554 |
| 555 PROCESS_INFORMATION process_info; | 555 PROCESS_INFORMATION process_info; |
| 556 ZeroMemory(&process_info, sizeof(process_info)); | 556 ZeroMemory(&process_info, sizeof(process_info)); |
| 557 | 557 |
| 558 // Compute command-line length. | 558 // Compute command-line length. |
| 559 int command_line_length = strlen(path); | 559 int command_line_length = strlen(path); |
| 560 for (int i = 0; i < arguments_length; i++) { | 560 for (int i = 0; i < arguments_length; i++) { |
| 561 command_line_length += strlen(arguments[i]); | 561 command_line_length += strlen(arguments[i]); |
| 562 } | 562 } |
| 563 // Account for two occurrences of '"' around the command, one space | 563 // Account for null termination and one space per argument. |
| 564 // and two occurrences of '"' per argument and a terminating '\0'. | 564 command_line_length += arguments_length + 1; |
| 565 command_line_length += 2 + (3 * arguments_length) + 1; | |
| 566 static const int kMaxCommandLineLength = 32768; | 565 static const int kMaxCommandLineLength = 32768; |
| 567 if (command_line_length > kMaxCommandLineLength) { | 566 if (command_line_length > kMaxCommandLineLength) { |
| 568 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); | 567 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); |
| 569 CloseProcessPipes( | 568 CloseProcessPipes( |
| 570 stdin_handles, stdout_handles, stderr_handles, exit_handles); | 569 stdin_handles, stdout_handles, stderr_handles, exit_handles); |
| 571 return error_code; | 570 return error_code; |
| 572 } | 571 } |
| 573 | 572 |
| 574 // Put together command-line string. | 573 // Put together command-line string. |
| 575 char* command_line = new char[command_line_length]; | 574 char* command_line = new char[command_line_length]; |
| 576 int len = 0; | 575 int len = 0; |
| 577 int remaining = command_line_length; | 576 int remaining = command_line_length; |
| 578 int written = snprintf(command_line + len, remaining, "\"%s\"", path); | 577 int written = snprintf(command_line + len, remaining, "%s", path); |
| 579 len += written; | 578 len += written; |
| 580 remaining -= written; | 579 remaining -= written; |
| 581 ASSERT(remaining >= 0); | 580 ASSERT(remaining >= 0); |
| 582 for (int i = 0; i < arguments_length; i++) { | 581 for (int i = 0; i < arguments_length; i++) { |
| 583 written = snprintf(command_line + len, remaining, " \"%s\"", arguments[i]); | 582 written = snprintf(command_line + len, remaining, " %s", arguments[i]); |
| 584 len += written; | 583 len += written; |
| 585 remaining -= written; | 584 remaining -= written; |
| 586 ASSERT(remaining >= 0); | 585 ASSERT(remaining >= 0); |
| 587 } | 586 } |
| 588 | 587 |
| 589 // Create process. | 588 // Create process. |
| 590 BOOL result = CreateProcess(NULL, // ApplicationName | 589 BOOL result = CreateProcess(NULL, // ApplicationName |
| 591 command_line, | 590 command_line, |
| 592 NULL, // ProcessAttributes | 591 NULL, // ProcessAttributes |
| 593 NULL, // ThreadAttributes | 592 NULL, // ThreadAttributes |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 if (!result) { | 642 if (!result) { |
| 644 return false; | 643 return false; |
| 645 } | 644 } |
| 646 return true; | 645 return true; |
| 647 } | 646 } |
| 648 | 647 |
| 649 | 648 |
| 650 void Process::TerminateExitCodeHandler() { | 649 void Process::TerminateExitCodeHandler() { |
| 651 ExitCodeHandler::TerminateExitCodeThread(); | 650 ExitCodeHandler::TerminateExitCodeThread(); |
| 652 } | 651 } |
| OLD | NEW |