| 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 631 } |
| 632 | 632 |
| 633 int alive = 3; | 633 int alive = 3; |
| 634 while (alive > 0) { | 634 while (alive > 0) { |
| 635 // Blocking call waiting for events from the child process. | 635 // Blocking call waiting for events from the child process. |
| 636 if (TEMP_FAILURE_RETRY(poll(fds, alive, -1)) <= 0) { | 636 if (TEMP_FAILURE_RETRY(poll(fds, alive, -1)) <= 0) { |
| 637 return CloseProcessBuffers(fds); | 637 return CloseProcessBuffers(fds); |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Process incoming data. | 640 // Process incoming data. |
| 641 for (int i = 0; i < alive; i++) { | 641 int current_alive = alive; |
| 642 for (int i = 0; i < current_alive; i++) { |
| 642 if (fds[i].revents & POLLIN) { | 643 if (fds[i].revents & POLLIN) { |
| 643 intptr_t avail = FDUtils::AvailableBytes(fds[i].fd); | 644 intptr_t avail = FDUtils::AvailableBytes(fds[i].fd); |
| 644 if (fds[i].fd == out) { | 645 if (fds[i].fd == out) { |
| 645 if (!out_data.Read(out, avail)) { | 646 if (!out_data.Read(out, avail)) { |
| 646 return CloseProcessBuffers(fds); | 647 return CloseProcessBuffers(fds); |
| 647 } | 648 } |
| 648 } else if (fds[i].fd == err) { | 649 } else if (fds[i].fd == err) { |
| 649 if (!err_data.Read(err, avail)) { | 650 if (!err_data.Read(err, avail)) { |
| 650 return CloseProcessBuffers(fds); | 651 return CloseProcessBuffers(fds); |
| 651 } | 652 } |
| 652 } else if (fds[i].fd == exit_event) { | 653 } else if (fds[i].fd == exit_event) { |
| 653 if (avail == 8) { | 654 if (avail == 8) { |
| 654 intptr_t b = TEMP_FAILURE_RETRY(read(exit_event, | 655 intptr_t b = TEMP_FAILURE_RETRY(read(exit_event, |
| 655 exit_code_data.bytes, 8)); | 656 exit_code_data.bytes, 8)); |
| 656 if (b != 8) { | 657 if (b != 8) { |
| 657 return CloseProcessBuffers(fds); | 658 return CloseProcessBuffers(fds); |
| 658 } | 659 } |
| 659 } | 660 } |
| 660 } else { | 661 } else { |
| 661 UNREACHABLE(); | 662 UNREACHABLE(); |
| 662 } | 663 } |
| 663 } | 664 } |
| 664 } | |
| 665 | |
| 666 // Process closed. | |
| 667 for (int i = 0; i < alive; i++) { | |
| 668 if (fds[i].revents & POLLHUP) { | 665 if (fds[i].revents & POLLHUP) { |
| 669 VOID_TEMP_FAILURE_RETRY(close(fds[i].fd)); | 666 VOID_TEMP_FAILURE_RETRY(close(fds[i].fd)); |
| 670 alive--; | 667 alive--; |
| 671 if (i < alive) { | 668 if (i < alive) { |
| 672 fds[i] = fds[alive]; | 669 fds[i] = fds[alive]; |
| 673 } | 670 } |
| 674 } | 671 } |
| 675 } | 672 } |
| 676 } | 673 } |
| 677 | 674 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 700 | 697 |
| 701 | 698 |
| 702 intptr_t Process::CurrentProcessId() { | 699 intptr_t Process::CurrentProcessId() { |
| 703 return static_cast<intptr_t>(getpid()); | 700 return static_cast<intptr_t>(getpid()); |
| 704 } | 701 } |
| 705 | 702 |
| 706 } // namespace bin | 703 } // namespace bin |
| 707 } // namespace dart | 704 } // namespace dart |
| 708 | 705 |
| 709 #endif // defined(TARGET_OS_LINUX) | 706 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |