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

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

Issue 1076093004: Make all of stdout/stderr/stdin pipes close-on-exec when spawing child processes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | « no previous file | runtime/bin/process_linux.cc » ('j') | runtime/bin/process_linux.cc » ('J')
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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/process.h" 8 #include "bin/process.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 ASSERT(exec_control_[0] == -1); 372 ASSERT(exec_control_[0] == -1);
373 ASSERT(exec_control_[1] == -1); 373 ASSERT(exec_control_[1] == -1);
374 374
375 *id_ = pid; 375 *id_ = pid;
376 return 0; 376 return 0;
377 } 377 }
378 378
379 private: 379 private:
380 int CreatePipes() { 380 int CreatePipes() {
381 int result; 381 int result;
382 result = TEMP_FAILURE_RETRY(pipe(exec_control_)); 382 result = TEMP_FAILURE_RETRY(pipe2(exec_control_, O_CLOEXEC));
383 if (result < 0) { 383 if (result < 0) {
384 return CleanupAndReturnError(); 384 return CleanupAndReturnError();
385 } 385 }
386 FDUtils::SetCloseOnExec(exec_control_[0]);
387 FDUtils::SetCloseOnExec(exec_control_[1]);
388 386
389 // For a detached process the pipe to connect stdout is still used for 387 // For a detached process the pipe to connect stdout is still used for
390 // signaling when to do the first fork. 388 // signaling when to do the first fork.
391 result = TEMP_FAILURE_RETRY(pipe(read_in_)); 389 result = TEMP_FAILURE_RETRY(pipe2(read_in_, O_CLOEXEC));
392 if (result < 0) { 390 if (result < 0) {
393 return CleanupAndReturnError(); 391 return CleanupAndReturnError();
394 } 392 }
395 FDUtils::SetCloseOnExec(read_in_[0]);
396 393
397 // For detached processes the pipe to connect stderr and stdin are not used. 394 // For detached processes the pipe to connect stderr and stdin are not used.
398 if (mode_ != kDetached) { 395 if (mode_ != kDetached) {
399 result = TEMP_FAILURE_RETRY(pipe(read_err_)); 396 result = TEMP_FAILURE_RETRY(pipe2(read_err_, O_CLOEXEC));
400 if (result < 0) { 397 if (result < 0) {
401 return CleanupAndReturnError(); 398 return CleanupAndReturnError();
402 } 399 }
403 FDUtils::SetCloseOnExec(read_err_[0]);
404 400
405 result = TEMP_FAILURE_RETRY(pipe(write_out_)); 401 result = TEMP_FAILURE_RETRY(pipe2(write_out_, O_CLOEXEC));
406 if (result < 0) { 402 if (result < 0) {
407 return CleanupAndReturnError(); 403 return CleanupAndReturnError();
408 } 404 }
409 FDUtils::SetCloseOnExec(write_out_[1]);
410 } 405 }
411 406
412 return 0; 407 return 0;
413 } 408 }
414 409
415 410
416 void NewProcess() { 411 void NewProcess() {
417 // Wait for parent process before setting up the child process. 412 // Wait for parent process before setting up the child process.
418 char msg; 413 char msg;
419 int bytes_read = FDUtils::ReadFromBlocking(read_in_[0], &msg, sizeof(msg)); 414 int bytes_read = FDUtils::ReadFromBlocking(read_in_[0], &msg, sizeof(msg));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 } else { 515 } else {
521 // Exit the intermeiate process. 516 // Exit the intermeiate process.
522 exit(0); 517 exit(0);
523 } 518 }
524 } 519 }
525 520
526 521
527 int RegisterProcess(pid_t pid) { 522 int RegisterProcess(pid_t pid) {
528 int result; 523 int result;
529 int event_fds[2]; 524 int event_fds[2];
530 result = TEMP_FAILURE_RETRY(pipe(event_fds)); 525 result = TEMP_FAILURE_RETRY(pipe2(event_fds, O_CLOEXEC));
531 if (result < 0) { 526 if (result < 0) {
532 return CleanupAndReturnError(); 527 return CleanupAndReturnError();
533 } 528 }
534 FDUtils::SetCloseOnExec(event_fds[0]);
535 FDUtils::SetCloseOnExec(event_fds[1]);
536 529
537 ProcessInfoList::AddProcess(pid, event_fds[1]); 530 ProcessInfoList::AddProcess(pid, event_fds[1]);
538 *exit_event_ = event_fds[0]; 531 *exit_event_ = event_fds[0];
539 FDUtils::SetNonBlocking(event_fds[0]); 532 FDUtils::SetNonBlocking(event_fds[0]);
540 return 0; 533 return 0;
541 } 534 }
542 535
543 536
544 int ReadExecResult() { 537 int ReadExecResult() {
545 int child_errno; 538 int child_errno;
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 bzero(&act, sizeof(act)); 1006 bzero(&act, sizeof(act));
1014 act.sa_handler = SIG_DFL; 1007 act.sa_handler = SIG_DFL;
1015 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); 1008 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL));
1016 } 1009 }
1017 } 1010 }
1018 1011
1019 } // namespace bin 1012 } // namespace bin
1020 } // namespace dart 1013 } // namespace dart
1021 1014
1022 #endif // defined(TARGET_OS_ANDROID) 1015 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_linux.cc » ('j') | runtime/bin/process_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698