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

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

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

Powered by Google App Engine
This is Rietveld 408576698