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

Side by Side Diff: runtime/bin/process_win.cc

Issue 10127008: Support passing an environment variable map to child processes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 os_error_message[os_error_message_len - 1] = '\0'; 463 os_error_message[os_error_message_len - 1] = '\0';
464 return error_code; 464 return error_code;
465 } 465 }
466 466
467 467
468 int Process::Start(const char* path, 468 int Process::Start(const char* path,
469 char* arguments[], 469 char* arguments[],
470 intptr_t arguments_length, 470 intptr_t arguments_length,
471 const char* working_directory, 471 const char* working_directory,
472 char* environment[],
473 intptr_t environment_length,
472 intptr_t* in, 474 intptr_t* in,
473 intptr_t* out, 475 intptr_t* out,
474 intptr_t* err, 476 intptr_t* err,
475 intptr_t* id, 477 intptr_t* id,
476 intptr_t* exit_handler, 478 intptr_t* exit_handler,
477 char* os_error_message, 479 char* os_error_message,
478 int os_error_message_len) { 480 int os_error_message_len) {
479 // Ensure that the process exit handler thread has been started. 481 // Ensure that the process exit handler thread has been started.
480 bool initialized = ExitCodeHandler::EnsureInitialized(); 482 bool initialized = ExitCodeHandler::EnsureInitialized();
481 if (!initialized) { 483 if (!initialized) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 len += written; 580 len += written;
579 remaining -= written; 581 remaining -= written;
580 ASSERT(remaining >= 0); 582 ASSERT(remaining >= 0);
581 for (int i = 0; i < arguments_length; i++) { 583 for (int i = 0; i < arguments_length; i++) {
582 written = snprintf(command_line + len, remaining, " %s", arguments[i]); 584 written = snprintf(command_line + len, remaining, " %s", arguments[i]);
583 len += written; 585 len += written;
584 remaining -= written; 586 remaining -= written;
585 ASSERT(remaining >= 0); 587 ASSERT(remaining >= 0);
586 } 588 }
587 589
590 // Create environment block if an environment is supplied.
591 char* environment_block = NULL;
592 if (environment != NULL) {
593 // An environment block is a sequence of zero-terminated strings
594 // followed by a block-terminating zero char.
595 intptr_t block_size = 1;
596 for (intptr_t i = 0; i < environment_length; i++) {
597 block_size += strlen(environment[i]) + 1;
598 }
599 environment_block = new char[block_size];
600 intptr_t block_index = 0;
601 for (intptr_t i = 0; i < environment_length; i++) {
602 printf("%s\n", environment[i]);
Søren Gjesse 2012/04/19 12:45:55 Debugging print
Mads Ager (google) 2012/04/20 12:24:51 Removed.
603 intptr_t len = strlen(environment[i]);
604 intptr_t result = snprintf(environment_block + block_index,
605 len,
606 "%s",
607 environment[i]);
608 ASSERT(result == len);
609 block_index += len;
610 environment_block[block_index++] = '\0';
611 }
612 // Block-terminating zero char.
613 environment_block[block_index++] = '\0';
614 ASSERT(block_index == block_size);
615 }
616
588 // Create process. 617 // Create process.
589 BOOL result = CreateProcess(NULL, // ApplicationName 618 BOOL result = CreateProcess(NULL, // ApplicationName
590 command_line, 619 command_line,
591 NULL, // ProcessAttributes 620 NULL, // ProcessAttributes
592 NULL, // ThreadAttributes 621 NULL, // ThreadAttributes
593 TRUE, // InheritHandles 622 TRUE, // InheritHandles
594 0, // CreationFlags 623 0, // CreationFlags
595 NULL, // Environment 624 environment_block,
596 working_directory, 625 working_directory,
597 &startup_info, 626 &startup_info,
598 &process_info); 627 &process_info);
599 628
600 // Deallocate command-line string. 629 // Deallocate command-line and environment block strings.
601 delete[] command_line; 630 delete[] command_line;
631 delete[] environment_block;
602 632
603 if (result == 0) { 633 if (result == 0) {
604 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); 634 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
605 CloseProcessPipes( 635 CloseProcessPipes(
606 stdin_handles, stdout_handles, stderr_handles, exit_handles); 636 stdin_handles, stdout_handles, stderr_handles, exit_handles);
607 return error_code; 637 return error_code;
608 } 638 }
609 639
610 ProcessInfoList::AddProcess(process_info.dwProcessId, 640 ProcessInfoList::AddProcess(process_info.dwProcessId,
611 process_info.hProcess, 641 process_info.hProcess,
(...skipping 30 matching lines...) Expand all
642 if (!result) { 672 if (!result) {
643 return false; 673 return false;
644 } 674 }
645 return true; 675 return true;
646 } 676 }
647 677
648 678
649 void Process::TerminateExitCodeHandler() { 679 void Process::TerminateExitCodeHandler() {
650 ExitCodeHandler::TerminateExitCodeThread(); 680 ExitCodeHandler::TerminateExitCodeThread();
651 } 681 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698