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