Chromium Code Reviews| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 ASSERT(read_err_[1] == -1); | 369 ASSERT(read_err_[1] == -1); |
| 370 } | 370 } |
| 371 ASSERT(exec_control_[0] == -1); | 371 ASSERT(exec_control_[0] == -1); |
| 372 ASSERT(exec_control_[1] == -1); | 372 ASSERT(exec_control_[1] == -1); |
| 373 | 373 |
| 374 *id_ = pid; | 374 *id_ = pid; |
| 375 return 0; | 375 return 0; |
| 376 } | 376 } |
| 377 | 377 |
| 378 private: | 378 private: |
| 379 int CreatePipes() { | 379 int CreatePipes() { |
|
Søren Gjesse
2015/04/23 06:58:51
Can't we then get rid of the explicit closing in t
Anders Johnsen
2015/04/23 07:05:34
You are right, it should be safe to remove those.
| |
| 380 int result; | 380 int result; |
| 381 result = TEMP_FAILURE_RETRY(pipe(exec_control_)); | 381 result = TEMP_FAILURE_RETRY(pipe2(exec_control_, O_CLOEXEC)); |
| 382 if (result < 0) { | 382 if (result < 0) { |
| 383 return CleanupAndReturnError(); | 383 return CleanupAndReturnError(); |
| 384 } | 384 } |
| 385 FDUtils::SetCloseOnExec(exec_control_[0]); | |
| 386 FDUtils::SetCloseOnExec(exec_control_[1]); | |
| 387 | 385 |
| 388 // For a detached process the pipe to connect stdout is still used for | 386 // For a detached process the pipe to connect stdout is still used for |
| 389 // signaling when to do the first fork. | 387 // signaling when to do the first fork. |
| 390 result = TEMP_FAILURE_RETRY(pipe(read_in_)); | 388 result = TEMP_FAILURE_RETRY(pipe2(read_in_, O_CLOEXEC)); |
| 391 if (result < 0) { | 389 if (result < 0) { |
| 392 return CleanupAndReturnError(); | 390 return CleanupAndReturnError(); |
| 393 } | 391 } |
| 394 FDUtils::SetCloseOnExec(read_in_[0]); | |
| 395 | 392 |
| 396 // For detached processes the pipe to connect stderr and stdin are not used. | 393 // For detached processes the pipe to connect stderr and stdin are not used. |
| 397 if (mode_ != kDetached) { | 394 if (mode_ != kDetached) { |
| 398 result = TEMP_FAILURE_RETRY(pipe(read_err_)); | 395 result = TEMP_FAILURE_RETRY(pipe2(read_err_, O_CLOEXEC)); |
| 399 if (result < 0) { | 396 if (result < 0) { |
| 400 return CleanupAndReturnError(); | 397 return CleanupAndReturnError(); |
| 401 } | 398 } |
| 402 FDUtils::SetCloseOnExec(read_err_[0]); | |
| 403 | 399 |
| 404 result = TEMP_FAILURE_RETRY(pipe(write_out_)); | 400 result = TEMP_FAILURE_RETRY(pipe2(write_out_, O_CLOEXEC)); |
| 405 if (result < 0) { | 401 if (result < 0) { |
| 406 return CleanupAndReturnError(); | 402 return CleanupAndReturnError(); |
| 407 } | 403 } |
| 408 FDUtils::SetCloseOnExec(write_out_[1]); | |
| 409 } | 404 } |
| 410 | 405 |
| 411 return 0; | 406 return 0; |
| 412 } | 407 } |
| 413 | 408 |
| 414 | 409 |
| 415 void NewProcess() { | 410 void NewProcess() { |
| 416 // Wait for parent process before setting up the child process. | 411 // Wait for parent process before setting up the child process. |
| 417 char msg; | 412 char msg; |
| 418 int bytes_read = FDUtils::ReadFromBlocking(read_in_[0], &msg, sizeof(msg)); | 413 int bytes_read = FDUtils::ReadFromBlocking(read_in_[0], &msg, sizeof(msg)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 } else { | 514 } else { |
| 520 // Exit the intermeiate process. | 515 // Exit the intermeiate process. |
| 521 exit(0); | 516 exit(0); |
| 522 } | 517 } |
| 523 } | 518 } |
| 524 | 519 |
| 525 | 520 |
| 526 int RegisterProcess(pid_t pid) { | 521 int RegisterProcess(pid_t pid) { |
| 527 int result; | 522 int result; |
| 528 int event_fds[2]; | 523 int event_fds[2]; |
| 529 result = TEMP_FAILURE_RETRY(pipe(event_fds)); | 524 result = TEMP_FAILURE_RETRY(pipe2(event_fds, O_CLOEXEC)); |
| 530 if (result < 0) { | 525 if (result < 0) { |
| 531 return CleanupAndReturnError(); | 526 return CleanupAndReturnError(); |
| 532 } | 527 } |
| 533 FDUtils::SetCloseOnExec(event_fds[0]); | |
| 534 FDUtils::SetCloseOnExec(event_fds[1]); | |
| 535 | 528 |
| 536 ProcessInfoList::AddProcess(pid, event_fds[1]); | 529 ProcessInfoList::AddProcess(pid, event_fds[1]); |
| 537 *exit_event_ = event_fds[0]; | 530 *exit_event_ = event_fds[0]; |
| 538 FDUtils::SetNonBlocking(event_fds[0]); | 531 FDUtils::SetNonBlocking(event_fds[0]); |
| 539 return 0; | 532 return 0; |
| 540 } | 533 } |
| 541 | 534 |
| 542 | 535 |
| 543 int ReadExecResult() { | 536 int ReadExecResult() { |
| 544 int child_errno; | 537 int child_errno; |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 bzero(&act, sizeof(act)); | 1001 bzero(&act, sizeof(act)); |
| 1009 act.sa_handler = SIG_DFL; | 1002 act.sa_handler = SIG_DFL; |
| 1010 sigaction(signal, &act, NULL); | 1003 sigaction(signal, &act, NULL); |
| 1011 } | 1004 } |
| 1012 } | 1005 } |
| 1013 | 1006 |
| 1014 } // namespace bin | 1007 } // namespace bin |
| 1015 } // namespace dart | 1008 } // namespace dart |
| 1016 | 1009 |
| 1017 #endif // defined(TARGET_OS_LINUX) | 1010 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |