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

Side by Side Diff: runtime/bin/process_macos.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 "bin/process.h" 5 #include "bin/process.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <signal.h> 10 #include <signal.h>
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 TEMP_FAILURE_RETRY(close(exec_control_fd)); 300 TEMP_FAILURE_RETRY(close(exec_control_fd));
301 exit(1); 301 exit(1);
302 } 302 }
303 303
304 304
305 int Process::Start(const char* path, 305 int Process::Start(const char* path,
306 char* arguments[], 306 char* arguments[],
307 intptr_t arguments_length, 307 intptr_t arguments_length,
308 const char* working_directory, 308 const char* working_directory,
309 char* environment[],
310 intptr_t environment_length,
309 intptr_t* in, 311 intptr_t* in,
310 intptr_t* out, 312 intptr_t* out,
311 intptr_t* err, 313 intptr_t* err,
312 intptr_t* id, 314 intptr_t* id,
313 intptr_t* exit_event, 315 intptr_t* exit_event,
314 char* os_error_message, 316 char* os_error_message,
315 int os_error_message_len) { 317 int os_error_message_len) {
316 pid_t pid; 318 pid_t pid;
317 int read_in[2]; // Pipe for stdout to child process. 319 int read_in[2]; // Pipe for stdout to child process.
318 int read_err[2]; // Pipe for stderr to child process. 320 int read_err[2]; // Pipe for stderr to child process.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 TEMP_FAILURE_RETRY(close(read_err[1])); 384 TEMP_FAILURE_RETRY(close(read_err[1]));
383 TEMP_FAILURE_RETRY(close(write_out[0])); 385 TEMP_FAILURE_RETRY(close(write_out[0]));
384 TEMP_FAILURE_RETRY(close(write_out[1])); 386 TEMP_FAILURE_RETRY(close(write_out[1]));
385 TEMP_FAILURE_RETRY(close(exec_control[0])); 387 TEMP_FAILURE_RETRY(close(exec_control[0]));
386 TEMP_FAILURE_RETRY(close(exec_control[1])); 388 TEMP_FAILURE_RETRY(close(exec_control[1]));
387 fprintf(stderr, "fcntl failed: %s\n", os_error_message); 389 fprintf(stderr, "fcntl failed: %s\n", os_error_message);
388 return errno; 390 return errno;
389 } 391 }
390 392
391 char** program_arguments = new char*[arguments_length + 2]; 393 char** program_arguments = new char*[arguments_length + 2];
392 program_arguments[0] = const_cast<char *>(path); 394 program_arguments[0] = const_cast<char*>(path);
393 for (int i = 0; i < arguments_length; i++) { 395 for (int i = 0; i < arguments_length; i++) {
394 program_arguments[i + 1] = arguments[i]; 396 program_arguments[i + 1] = arguments[i];
395 } 397 }
396 program_arguments[arguments_length + 1] = NULL; 398 program_arguments[arguments_length + 1] = NULL;
397 399
400 char** program_environment = NULL;
401 if (environment != NULL) {
402 program_environment = new char*[environment_length + 1];
403 for (int i = 0; i < environment_length; i++) {
404 program_environment[i] = environment[i];
405 }
406 program_arguments[environment_length] = NULL;
407 }
408
398 struct sigaction act; 409 struct sigaction act;
399 bzero(&act, sizeof(act)); 410 bzero(&act, sizeof(act));
400 act.sa_sigaction = SigChldHandler; 411 act.sa_sigaction = SigChldHandler;
401 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; 412 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
402 if (sigaction(SIGCHLD, &act, 0) != 0) { 413 if (sigaction(SIGCHLD, &act, 0) != 0) {
403 perror("Process start: setting signal handler failed"); 414 perror("Process start: setting signal handler failed");
404 } 415 }
405 pid = TEMP_FAILURE_RETRY(fork()); 416 pid = TEMP_FAILURE_RETRY(fork());
406 if (pid < 0) { 417 if (pid < 0) {
407 SetChildOsErrorMessage(os_error_message, os_error_message_len); 418 SetChildOsErrorMessage(os_error_message, os_error_message_len);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 if (TEMP_FAILURE_RETRY(dup2(read_err[1], STDERR_FILENO)) == -1) { 453 if (TEMP_FAILURE_RETRY(dup2(read_err[1], STDERR_FILENO)) == -1) {
443 ReportChildError(exec_control[1]); 454 ReportChildError(exec_control[1]);
444 } 455 }
445 TEMP_FAILURE_RETRY(close(read_err[1])); 456 TEMP_FAILURE_RETRY(close(read_err[1]));
446 457
447 if (working_directory != NULL && 458 if (working_directory != NULL &&
448 TEMP_FAILURE_RETRY(chdir(working_directory)) == -1) { 459 TEMP_FAILURE_RETRY(chdir(working_directory)) == -1) {
449 ReportChildError(exec_control[1]); 460 ReportChildError(exec_control[1]);
450 } 461 }
451 462
452 TEMP_FAILURE_RETRY( 463 if (environment != NULL) {
453 execvp(path, const_cast<char* const*>(program_arguments))); 464 TEMP_FAILURE_RETRY(
465 execve(path,
466 const_cast<char* const*>(program_arguments),
467 program_environment));
468 } else {
469 TEMP_FAILURE_RETRY(
470 execvp(path, const_cast<char* const*>(program_arguments)));
471 }
454 ReportChildError(exec_control[1]); 472 ReportChildError(exec_control[1]);
455 } 473 }
456 474
457 // The arguments for the spawned process are not needed any longer. 475 // The arguments and environment for the spawned process are not needed
476 // any longer.
458 delete[] program_arguments; 477 delete[] program_arguments;
478 delete[] program_environment;
459 479
460 int event_fds[2]; 480 int event_fds[2];
461 result = TEMP_FAILURE_RETRY(pipe(event_fds)); 481 result = TEMP_FAILURE_RETRY(pipe(event_fds));
462 if (result < 0) { 482 if (result < 0) {
463 SetChildOsErrorMessage(os_error_message, os_error_message_len); 483 SetChildOsErrorMessage(os_error_message, os_error_message_len);
464 TEMP_FAILURE_RETRY(close(read_in[0])); 484 TEMP_FAILURE_RETRY(close(read_in[0]));
465 TEMP_FAILURE_RETRY(close(read_in[1])); 485 TEMP_FAILURE_RETRY(close(read_in[1]));
466 TEMP_FAILURE_RETRY(close(read_err[0])); 486 TEMP_FAILURE_RETRY(close(read_err[0]));
467 TEMP_FAILURE_RETRY(close(read_err[1])); 487 TEMP_FAILURE_RETRY(close(read_err[1]));
468 TEMP_FAILURE_RETRY(close(write_out[0])); 488 TEMP_FAILURE_RETRY(close(write_out[0]));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (result == -1) { 555 if (result == -1) {
536 return false; 556 return false;
537 } 557 }
538 return true; 558 return true;
539 } 559 }
540 560
541 561
542 void Process::TerminateExitCodeHandler() { 562 void Process::TerminateExitCodeHandler() {
543 ExitCodeHandler::TerminateExitCodeThread(); 563 ExitCodeHandler::TerminateExitCodeThread();
544 } 564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698