| 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 "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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (initialized_) { | 117 if (initialized_) { |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Allocate a pipe that the signal handler can write a byte to and | 121 // Allocate a pipe that the signal handler can write a byte to and |
| 122 // that the exit handler thread can poll. | 122 // that the exit handler thread can poll. |
| 123 int result = TEMP_FAILURE_RETRY(pipe(sig_chld_fds_)); | 123 int result = TEMP_FAILURE_RETRY(pipe(sig_chld_fds_)); |
| 124 if (result < 0) { | 124 if (result < 0) { |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 FDUtils::SetCloseOnExec(sig_chld_fds_[0]); |
| 128 FDUtils::SetCloseOnExec(sig_chld_fds_[1]); |
| 127 | 129 |
| 128 // Start thread that polls the pipe and handles process exits when | 130 // Start thread that polls the pipe and handles process exits when |
| 129 // data is received on the pipe. | 131 // data is received on the pipe. |
| 130 result = dart::Thread::Start(ExitCodeHandlerEntry, sig_chld_fds_[0]); | 132 result = dart::Thread::Start(ExitCodeHandlerEntry, sig_chld_fds_[0]); |
| 131 if (result != 0) { | 133 if (result != 0) { |
| 132 FATAL1("Failed to start exit code handler worker thread %d", result); | 134 FATAL1("Failed to start exit code handler worker thread %d", result); |
| 133 } | 135 } |
| 134 | 136 |
| 135 // Mark write end non-blocking. | 137 // Mark write end non-blocking. |
| 136 FDUtils::SetNonBlocking(sig_chld_fds_[1]); | 138 FDUtils::SetNonBlocking(sig_chld_fds_[1]); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 SetChildOsErrorMessage(os_error_message); | 475 SetChildOsErrorMessage(os_error_message); |
| 474 TEMP_FAILURE_RETRY(close(read_in[0])); | 476 TEMP_FAILURE_RETRY(close(read_in[0])); |
| 475 TEMP_FAILURE_RETRY(close(read_in[1])); | 477 TEMP_FAILURE_RETRY(close(read_in[1])); |
| 476 TEMP_FAILURE_RETRY(close(read_err[0])); | 478 TEMP_FAILURE_RETRY(close(read_err[0])); |
| 477 TEMP_FAILURE_RETRY(close(read_err[1])); | 479 TEMP_FAILURE_RETRY(close(read_err[1])); |
| 478 TEMP_FAILURE_RETRY(close(write_out[0])); | 480 TEMP_FAILURE_RETRY(close(write_out[0])); |
| 479 TEMP_FAILURE_RETRY(close(write_out[1])); | 481 TEMP_FAILURE_RETRY(close(write_out[1])); |
| 480 Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message); | 482 Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message); |
| 481 return errno; | 483 return errno; |
| 482 } | 484 } |
| 485 FDUtils::SetCloseOnExec(event_fds[0]); |
| 486 FDUtils::SetCloseOnExec(event_fds[1]); |
| 483 | 487 |
| 484 ProcessInfoList::AddProcess(pid, event_fds[1]); | 488 ProcessInfoList::AddProcess(pid, event_fds[1]); |
| 485 *exit_event = event_fds[0]; | 489 *exit_event = event_fds[0]; |
| 486 FDUtils::SetNonBlocking(event_fds[0]); | 490 FDUtils::SetNonBlocking(event_fds[0]); |
| 487 | 491 |
| 488 // Notify child process to start. | 492 // Notify child process to start. |
| 489 char msg = '1'; | 493 char msg = '1'; |
| 490 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); | 494 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); |
| 491 if (result != sizeof(msg)) { | 495 if (result != sizeof(msg)) { |
| 492 perror("Failed sending notification message"); | 496 perror("Failed sending notification message"); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 553 |
| 550 | 554 |
| 551 void Process::TerminateExitCodeHandler() { | 555 void Process::TerminateExitCodeHandler() { |
| 552 ExitCodeHandler::TerminateExitCodeThread(); | 556 ExitCodeHandler::TerminateExitCodeThread(); |
| 553 } | 557 } |
| 554 | 558 |
| 555 | 559 |
| 556 intptr_t Process::CurrentProcessId() { | 560 intptr_t Process::CurrentProcessId() { |
| 557 return static_cast<intptr_t>(getpid()); | 561 return static_cast<intptr_t>(getpid()); |
| 558 } | 562 } |
| OLD | NEW |